WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
Preferences Class Reference

The preferences class provides a relatively simple way to save important values to the RoboRIO to access the next time the RoboRIO is booted. More...

#include <Preferences.h>

Inheritance diagram for Preferences:
ErrorBase

Public Member Functions

std::vector< std::string > GetKeys ()
 Returns a vector of all the keys. More...
 
std::string GetString (llvm::StringRef key, llvm::StringRef defaultValue="")
 Returns the string at the given key. More...
 
int GetInt (llvm::StringRef key, int defaultValue=0)
 Returns the int at the given key. More...
 
double GetDouble (llvm::StringRef key, double defaultValue=0.0)
 Returns the double at the given key. More...
 
float GetFloat (llvm::StringRef key, float defaultValue=0.0)
 Returns the float at the given key. More...
 
bool GetBoolean (llvm::StringRef key, bool defaultValue=false)
 Returns the boolean at the given key. More...
 
int64_t GetLong (llvm::StringRef key, int64_t defaultValue=0)
 Returns the long (int64_t) at the given key. More...
 
void PutString (llvm::StringRef key, llvm::StringRef value)
 Puts the given string into the preferences table. More...
 
void PutInt (llvm::StringRef key, int value)
 Puts the given int into the preferences table. More...
 
void PutDouble (llvm::StringRef key, double value)
 Puts the given double into the preferences table. More...
 
void PutFloat (llvm::StringRef key, float value)
 Puts the given float into the preferences table. More...
 
void PutBoolean (llvm::StringRef key, bool value)
 Puts the given boolean into the preferences table. More...
 
void PutLong (llvm::StringRef key, int64_t value)
 Puts the given long (int64_t) into the preferences table. More...
 
 DEPRECATED ("Saving is now automatically performed by the NetworkTables server.") void Save()
 
bool ContainsKey (llvm::StringRef key)
 Returns whether or not there is a key with the given name. More...
 
void Remove (llvm::StringRef key)
 Remove a preference. More...
 
- Public Member Functions inherited from ErrorBase
 ErrorBase (const ErrorBase &)=delete
 
ErrorBaseoperator= (const ErrorBase &)=delete
 
virtual ErrorGetError ()
 Retrieve the current error. More...
 
virtual const ErrorGetError () const
 
virtual void SetErrnoError (llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef 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, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) const
 Set the current error information associated from the nivision Imaq API. More...
 
virtual void SetError (Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetWPIError (llvm::StringRef errorMessage, Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void CloneError (const 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 ()
 Get the one and only Preferences object. More...
 
- Static Public Member Functions inherited from ErrorBase
static void SetGlobalError (Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber)
 
static void SetGlobalWPIError (llvm::StringRef errorMessage, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber)
 
static ErrorGetGlobalError ()
 Retrieve the current global error.
 

Additional Inherited Members

- Protected Attributes inherited from ErrorBase
Error m_error
 
- Static Protected Attributes inherited from ErrorBase
static priority_mutex _globalErrorMutex
 
static Error _globalError
 

Detailed Description

The preferences class provides a relatively simple way to save important values to the RoboRIO to access the next time the RoboRIO is booted.

This class loads and saves from a file inside the RoboRIO. The user can not access the file directly, but may modify values at specific fields which will then be automatically periodically saved to the file by the NetworkTable server.

This class is thread safe.

This will also interact with NetworkTable by creating a table called "Preferences" with all the key-value pairs.

Member Function Documentation

bool Preferences::ContainsKey ( llvm::StringRef  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 ( llvm::StringRef  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 ( llvm::StringRef  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 ( llvm::StringRef  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 ( llvm::StringRef  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_t Preferences::GetLong ( llvm::StringRef  key,
int64_t  defaultValue = 0 
)

Returns the long (int64_t) 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 ( llvm::StringRef  key,
llvm::StringRef  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
void Preferences::PutBoolean ( llvm::StringRef  key,
bool  value 
)

Puts the given boolean into the preferences table.

The key may not have any whitespace nor an equals sign

Parameters
keythe key
valuethe value
void Preferences::PutDouble ( llvm::StringRef  key,
double  value 
)

Puts the given double into the preferences table.

The key may not have any whitespace nor an equals sign

Parameters
keythe key
valuethe value
void Preferences::PutFloat ( llvm::StringRef  key,
float  value 
)

Puts the given float into the preferences table.

The key may not have any whitespace nor an equals sign

Parameters
keythe key
valuethe value
void Preferences::PutInt ( llvm::StringRef  key,
int  value 
)

Puts the given int into the preferences table.

The key may not have any whitespace nor an equals sign

Parameters
keythe key
valuethe value
void Preferences::PutLong ( llvm::StringRef  key,
int64_t  value 
)

Puts the given long (int64_t) into the preferences table.

The key may not have any whitespace nor an equals sign

Parameters
keythe key
valuethe value
void Preferences::PutString ( llvm::StringRef  key,
llvm::StringRef  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

Parameters
keythe key
valuethe value
void Preferences::Remove ( llvm::StringRef  key)

Remove a preference.

Parameters
keythe key

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