Now you can download a copy of these docs so you can use them offline! Download now

#include <Preferences.h>

Inheritance diagram for Preferences:
Collaboration diagram for Preferences:

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 ErrorGetError ()
 Retrieve the current error. Get the current error information associated with this sensor.
 
virtual const ErrorGetError () 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 PreferencesGetInstance ()
 
- 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 ErrorGetGlobalError ()
 

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
 

Detailed Description

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.

Member Function Documentation

bool Preferences::ContainsKey ( const char *  key)

Returns whether or not there is a key with the given name.

Parameters
keythe key
Returns
if there is a value at the given 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.

Parameters
keythe key
defaultValuethe value to return if none exists in the table
Returns
either the value in the table, or the defaultValue

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.

Parameters
keythe key
defaultValuethe value to return if none exists in the table
Returns
either the value in the table, or the defaultValue

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.

Parameters
keythe key
defaultValuethe value to return if none exists in the table
Returns
either the value in the table, or the defaultValue

Definition at line 147 of file Preferences.cpp.

Preferences * Preferences::GetInstance ( )
static

Get the one and only Preferences object

Returns
pointer to the Preferences

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.

Parameters
keythe key
defaultValuethe value to return if none exists in the table
Returns
either the value in the table, or the defaultValue

Definition at line 115 of file Preferences.cpp.

std::vector< std::string > Preferences::GetKeys ( )

Returns a vector of all the keys

Returns
a vector of 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.

Parameters
keythe key
defaultValuethe value to return if none exists in the table
Returns
either the value in the table, or the defaultValue

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.

Parameters
keythe key
defaultValuethe value to return if none exists in the table
Returns
either the value in the table, or the defaultValue

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.

Parameters
keythe key
valuethe buffer to copy the value into
valueSizethe size of value
defaultValuethe value to return if none exists in the table
Returns
The size of the returned string

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.

Parameters
keythe key
valuethe 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.

Parameters
keythe key
valuethe 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.

Parameters
keythe key
valuethe 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.

Parameters
keythe key
valuethe 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.

Parameters
keythe key
valuethe 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.

Parameters
keythe key
valuethe value

Definition at line 210 of file Preferences.cpp.

void Preferences::Remove ( const char *  key)

Remove a preference

Parameters
keythe key

Definition at line 345 of file Preferences.cpp.

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.

void Preferences::ValueChanged ( ITable source,
const std::string &  key,
EntryValue  value,
bool  isNew 
)
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

Parameters
sourcethe table the key-value pair exists in
keythe key associated with the value that changed
valuethe new value
isNewtrue if the key did not previously exist in the table, otherwise it is false

Implements ITableListener.

Definition at line 583 of file Preferences.cpp.


The documentation for this class was generated from the following files:

Generated on Sat Apr 26 2014 12:26:46 for WPILibC++ by doxygen 1.8.6