#include <Preferences.h>
Public Member Functions | |
std::vector< std::string > | GetKeys () |
std::string | GetString (const char *key, const char *defaultValue="") |
int | GetString (const char *key, char *value, int valueSize, const char *defaultValue="") |
int | GetInt (const char *key, int defaultValue=0) |
double | GetDouble (const char *key, double defaultValue=0.0) |
float | GetFloat (const char *key, float defaultValue=0.0) |
bool | GetBoolean (const char *key, bool defaultValue=false) |
INT64 | GetLong (const char *key, INT64 defaultValue=0) |
void | PutString (const char *key, const char *value) |
void | PutInt (const char *key, int value) |
void | PutDouble (const char *key, double value) |
void | PutFloat (const char *key, float value) |
void | PutBoolean (const char *key, bool value) |
void | PutLong (const char *key, INT64 value) |
void | Save () |
bool | ContainsKey (const char *key) |
void | Remove (const char *key) |
void | ValueChanged (ITable *source, const std::string &key, EntryValue value, bool isNew) |
Public Member Functions inherited from ErrorBase | |
virtual Error & | GetError () |
Retrieve the current error. Get the current error information associated with this sensor. | |
virtual const Error & | GetError () const |
virtual void | SetErrnoError (const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const |
Set error information associated with a C library call that set an error to the "errno" global variable. More... | |
virtual void | SetImaqError (int success, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const |
Set the current error information associated from the nivision Imaq API. More... | |
virtual void | SetError (Error::Code code, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const |
Set the current error information associated with this sensor. More... | |
virtual void | SetWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const |
Set the current error information associated with this sensor. More... | |
virtual void | CloneError (ErrorBase *rhs) const |
virtual void | ClearError () const |
Clear the current error information associated with this sensor. | |
virtual bool | StatusIsFatal () const |
Check if the current error code represents a fatal error. More... | |
Static Public Member Functions | |
static Preferences * | GetInstance () |
Static Public Member Functions inherited from ErrorBase | |
static void | SetGlobalError (Error::Code code, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) |
static void | SetGlobalWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) |
static Error & | GetGlobalError () |
Additional Inherited Members | |
Protected Member Functions inherited from ErrorBase | |
ErrorBase () | |
Initialize the instance status to 0 for now. | |
Protected Attributes inherited from ErrorBase | |
Error | m_error |
Static Protected Attributes inherited from ErrorBase | |
static SEM_ID | _globalErrorMutex = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE) |
static Error | _globalError |
The preferences class provides a relatively simple way to save important values to the cRIO to access the next time the cRIO is booted.
This class loads and saves from a file inside the cRIO. The user can not access the file directly, but may modify values at specific fields which will then be saved to the file when Save() is called.
This class is thread safe.
This will also interact with NetworkTable by creating a table called "Preferences" with all the key-value pairs. To save using NetworkTable, simply set the boolean at position "~S A V E~" to true. Also, if the value of any variable is " in the NetworkTable, then that represents non-existence in the Preferences table
Definition at line 34 of file Preferences.h.
bool Preferences::ContainsKey | ( | const char * | key | ) |
Returns whether or not there is a key with the given name.
key | the key |
Definition at line 336 of file Preferences.cpp.
bool Preferences::GetBoolean | ( | const char * | key, |
bool | defaultValue = false |
||
) |
Returns the boolean at the given key. If this table does not have a value for that position, then the given defaultValue value will be returned.
key | the key |
defaultValue | the value to return if none exists in the table |
Definition at line 163 of file Preferences.cpp.
double Preferences::GetDouble | ( | const char * | key, |
double | defaultValue = 0.0 |
||
) |
Returns the double at the given key. If this table does not have a value for that position, then the given defaultValue value will be returned.
key | the key |
defaultValue | the value to return if none exists in the table |
Definition at line 131 of file Preferences.cpp.
float Preferences::GetFloat | ( | const char * | key, |
float | defaultValue = 0.0 |
||
) |
Returns the float at the given key. If this table does not have a value for that position, then the given defaultValue value will be returned.
key | the key |
defaultValue | the value to return if none exists in the table |
Definition at line 147 of file Preferences.cpp.
|
static |
Get the one and only Preferences object
Definition at line 63 of file Preferences.cpp.
int Preferences::GetInt | ( | const char * | key, |
int | defaultValue = 0 |
||
) |
Returns the int at the given key. If this table does not have a value for that position, then the given defaultValue value will be returned.
key | the key |
defaultValue | the value to return if none exists in the table |
Definition at line 115 of file Preferences.cpp.
std::vector< std::string > Preferences::GetKeys | ( | ) |
Returns a vector of all the keys
Definition at line 74 of file Preferences.cpp.
INT64 Preferences::GetLong | ( | const char * | key, |
INT64 | defaultValue = 0 |
||
) |
Returns the long (INT64) at the given key. If this table does not have a value for that position, then the given defaultValue value will be returned.
key | the key |
defaultValue | the value to return if none exists in the table |
Definition at line 185 of file Preferences.cpp.
std::string Preferences::GetString | ( | const char * | key, |
const char * | defaultValue = "" |
||
) |
Returns the string at the given key. If this table does not have a value for that position, then the given defaultValue will be returned.
key | the key |
defaultValue | the value to return if none exists in the table |
Definition at line 86 of file Preferences.cpp.
int Preferences::GetString | ( | const char * | key, |
char * | value, | ||
int | valueSize, | ||
const char * | defaultValue = "" |
||
) |
Returns the string at the given key. If this table does not have a value for that position, then the given defaultValue will be returned.
key | the key |
value | the buffer to copy the value into |
valueSize | the size of value |
defaultValue | the value to return if none exists in the table |
Definition at line 101 of file Preferences.cpp.
void Preferences::PutBoolean | ( | const char * | key, |
bool | value | ||
) |
Puts the given boolean into the preferences table.
The key may not have any whitespace nor an equals sign
This will NOT save the value to memory between power cycles, to do that you must call Save() (which must be used with care) at some point after calling this.
key | the key |
value | the value |
Definition at line 290 of file Preferences.cpp.
void Preferences::PutDouble | ( | const char * | key, |
double | value | ||
) |
Puts the given double into the preferences table.
The key may not have any whitespace nor an equals sign
This will NOT save the value to memory between power cycles, to do that you must call Save() (which must be used with care) at some point after calling this.
key | the key |
value | the value |
Definition at line 254 of file Preferences.cpp.
void Preferences::PutFloat | ( | const char * | key, |
float | value | ||
) |
Puts the given float into the preferences table.
The key may not have any whitespace nor an equals sign
This will NOT save the value to memory between power cycles, to do that you must call Save() (which must be used with care) at some point after calling this.
key | the key |
value | the value |
Definition at line 272 of file Preferences.cpp.
void Preferences::PutInt | ( | const char * | key, |
int | value | ||
) |
Puts the given int into the preferences table.
The key may not have any whitespace nor an equals sign
This will NOT save the value to memory between power cycles, to do that you must call Save() (which must be used with care) at some point after calling this.
key | the key |
value | the value |
Definition at line 236 of file Preferences.cpp.
void Preferences::PutLong | ( | const char * | key, |
INT64 | value | ||
) |
Puts the given long (INT64) into the preferences table.
The key may not have any whitespace nor an equals sign
This will NOT save the value to memory between power cycles, to do that you must call Save() (which must be used with care) at some point after calling this.
key | the key |
value | the value |
Definition at line 306 of file Preferences.cpp.
void Preferences::PutString | ( | const char * | key, |
const char * | value | ||
) |
Puts the given string into the preferences table.
The value may not have quotation marks, nor may the key have any whitespace nor an equals sign
This will NOT save the value to memory between power cycles, to do that you must call Save() (which must be used with care). at some point after calling this.
key | the key |
value | the value |
Definition at line 210 of file Preferences.cpp.
void Preferences::Remove | ( | const char * | key | ) |
void Preferences::Save | ( | ) |
Saves the preferences to a file on the cRIO.
This should NOT be called often. Too many writes can damage the cRIO's flash memory. While it is ok to save once or twice a match, this should never be called every run of IterativeRobot#TeleopPeriodic(), etc.
The actual writing of the file is done in a separate thread. However, any call to a get or put method will wait until the table is fully saved before continuing.
Definition at line 324 of file Preferences.cpp.
|
virtual |
Called when a key-value pair is changed in a ITable WARNING: If a new key-value is put in this method value changed will immediatly be called which could lead to recursive code
source | the table the key-value pair exists in |
key | the key associated with the value that changed |
value | the new value |
isNew | true if the key did not previously exist in the table, otherwise it is false |
Implements ITableListener.
Definition at line 583 of file Preferences.cpp.