WPILib  2014.0
WPIRoboticsLibraryforFRC
 All Classes Functions Variables Pages
Public Member Functions | Static Public Member Functions | List of all members
Preferences Class Reference

#include <Preferences.h>

Inheritance diagram for Preferences:
ErrorBase

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

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
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
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
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
Preferences * Preferences::GetInstance ( )
static

Get the one and only Preferences object

Returns
pointer to the Preferences
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
std::vector< std::string > Preferences::GetKeys ( )

Returns a vector of all the keys

Returns
a vector of the keys
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
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
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
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
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
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
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
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
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
void Preferences::Remove ( const char *  key)

Remove a preference

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


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