WPILibC++
2019.1.1-beta-2-44-g608d824
|
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>
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. | |
![]() | |
ErrorBase (ErrorBase &&)=default | |
ErrorBase & | operator= (ErrorBase &&)=default |
virtual Error & | GetError () |
Retrieve the current error. More... | |
virtual const Error & | GetError () 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 Preferences * | GetInstance () |
Get the one and only Preferences object. More... | |
![]() | |
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 Error & | GetGlobalError () |
Retrieve the current global error. | |
Protected Member Functions | |
Preferences (Preferences &&)=default | |
Preferences & | operator= (Preferences &&)=default |
Additional Inherited Members | |
![]() | |
Error | m_error |
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.
bool frc::Preferences::ContainsKey | ( | wpi::StringRef | key | ) |
Returns whether or not there is a key with the given name.
key | the 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.
key | the key |
defaultValue | the value to return if none exists in the table |
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.
key | the key |
defaultValue | the value to return if none exists in the table |
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.
key | the key |
defaultValue | the value to return if none exists in the table |
|
static |
Get the one and only Preferences object.
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.
key | the key |
defaultValue | the value to return if none exists in the table |
std::vector<std::string> frc::Preferences::GetKeys | ( | ) |
Returns a vector of all 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.
key | the key |
defaultValue | the value to return if none exists in the table |
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.
key | the key |
defaultValue | the value to return if none exists in the table |
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.
key | the key |
value | the 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.
key | the key |
value | the 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.
key | the key |
value | the 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.
key | the key |
value | the 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.
key | the key |
value | the 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.
key | the key |
value | the value |
void frc::Preferences::Remove | ( | wpi::StringRef | key | ) |
Remove a preference.
key | the key |