WPILibC++  2019.3.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
frc::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 frc::Preferences:
frc::ErrorBase

Public Member Functions

std::vector< std::string > GetKeys ()
 Returns a vector of all the keys. More...
 
std::string GetString (wpi::StringRef key, wpi::StringRef defaultValue="")
 Returns the string at the given key. More...
 
int GetInt (wpi::StringRef key, int defaultValue=0)
 Returns the int at the given key. More...
 
double GetDouble (wpi::StringRef key, double defaultValue=0.0)
 Returns the double at the given key. More...
 
float GetFloat (wpi::StringRef key, float defaultValue=0.0)
 Returns the float at the given key. More...
 
bool GetBoolean (wpi::StringRef key, bool defaultValue=false)
 Returns the boolean at the given key. More...
 
int64_t GetLong (wpi::StringRef key, int64_t defaultValue=0)
 Returns the long (int64_t) at the given key. More...
 
void PutString (wpi::StringRef key, wpi::StringRef value)
 Puts the given string into the preferences table. More...
 
void PutInt (wpi::StringRef key, int value)
 Puts the given int into the preferences table. More...
 
void PutDouble (wpi::StringRef key, double value)
 Puts the given double into the preferences table. More...
 
void PutFloat (wpi::StringRef key, float value)
 Puts the given float into the preferences table. More...
 
void PutBoolean (wpi::StringRef key, bool value)
 Puts the given boolean into the preferences table. More...
 
void PutLong (wpi::StringRef key, int64_t value)
 Puts the given long (int64_t) into the preferences table. More...
 
bool ContainsKey (wpi::StringRef key)
 Returns whether or not there is a key with the given name. More...
 
void Remove (wpi::StringRef key)
 Remove a preference. More...
 
void RemoveAll ()
 Remove all preferences.
 
- Public Member Functions inherited from frc::ErrorBase
 ErrorBase (ErrorBase &&)=default
 
ErrorBaseoperator= (ErrorBase &&)=default
 
virtual ErrorGetError ()
 Retrieve the current error. More...
 
virtual const ErrorGetError () const
 Retrieve the current error. More...
 
virtual void ClearError () const
 Clear the current error information associated with this sensor.
 
virtual void SetErrnoError (const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int 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 wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated from the nivision Imaq API. More...
 
virtual void SetError (Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetErrorRange (Error::Code code, int32_t minRange, int32_t maxRange, int32_t requestedValue, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetWPIError (const wpi::Twine &errorMessage, Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void CloneError (const ErrorBase &rhs) const
 
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 frc::ErrorBase
static void SetGlobalError (Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber)
 
static void SetGlobalWPIError (const wpi::Twine &errorMessage, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber)
 
static const ErrorGetGlobalError ()
 Retrieve the current global error.
 

Protected Member Functions

 Preferences (Preferences &&)=default
 
Preferencesoperator= (Preferences &&)=default
 

Additional Inherited Members

- Protected Attributes inherited from frc::ErrorBase
Error m_error
 

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 cannot 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 frc::Preferences::ContainsKey ( wpi::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 frc::Preferences::GetBoolean ( wpi::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 frc::Preferences::GetDouble ( wpi::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 frc::Preferences::GetFloat ( wpi::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
static Preferences* frc::Preferences::GetInstance ( )
static

Get the one and only Preferences object.

Returns
pointer to the Preferences
int frc::Preferences::GetInt ( wpi::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> frc::Preferences::GetKeys ( )

Returns a vector of all the keys.

Returns
a vector of the keys
int64_t frc::Preferences::GetLong ( wpi::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 frc::Preferences::GetString ( wpi::StringRef  key,
wpi::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 frc::Preferences::PutBoolean ( wpi::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 frc::Preferences::PutDouble ( wpi::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 frc::Preferences::PutFloat ( wpi::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 frc::Preferences::PutInt ( wpi::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 frc::Preferences::PutLong ( wpi::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 frc::Preferences::PutString ( wpi::StringRef  key,
wpi::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 frc::Preferences::Remove ( wpi::StringRef  key)

Remove a preference.

Parameters
keythe key

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