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:

List of all members.

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)

Static Public Member Functions

static PreferencesGetInstance ()

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 33 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:
key the 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:
key the key
defaultValue the 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:
key the key
defaultValue the 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:
key the key
defaultValue the 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:
key the key
defaultValue the 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:
key the key
defaultValue the 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.

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:
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
Returns:
The size of the returned string

Definition at line 101 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:
key the key
defaultValue the 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.

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:
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.

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

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

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

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

Parameters:
key the key
value the value

Definition at line 210 of file Preferences.cpp.

void Preferences::Remove ( const char *  key  ) 

Remove a preference

Parameters:
key the 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.


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

Generated on Thu Jan 12 2012 22:35:34 for WPILibC++ by doxygen 1.7.1