WPILibC++ 2023.4.3-108-ge5452e3
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 <frc/Preferences.h>

Static Public Member Functions

static std::vector< std::string > GetKeys ()
 Returns a vector of all the keys. More...
 
static std::string GetString (std::string_view key, std::string_view defaultValue="")
 Returns the string at the given key. More...
 
static int GetInt (std::string_view key, int defaultValue=0)
 Returns the int at the given key. More...
 
static double GetDouble (std::string_view key, double defaultValue=0.0)
 Returns the double at the given key. More...
 
static float GetFloat (std::string_view key, float defaultValue=0.0)
 Returns the float at the given key. More...
 
static bool GetBoolean (std::string_view key, bool defaultValue=false)
 Returns the boolean at the given key. More...
 
static int64_t GetLong (std::string_view key, int64_t defaultValue=0)
 Returns the long (int64_t) at the given key. More...
 
static void SetString (std::string_view key, std::string_view value)
 Puts the given string into the preferences table. More...
 
static void InitString (std::string_view key, std::string_view value)
 Puts the given string into the preferences table if it doesn't already exist. More...
 
static void SetInt (std::string_view key, int value)
 Puts the given int into the preferences table. More...
 
static void InitInt (std::string_view key, int value)
 Puts the given int into the preferences table if it doesn't already exist. More...
 
static void SetDouble (std::string_view key, double value)
 Puts the given double into the preferences table. More...
 
static void InitDouble (std::string_view key, double value)
 Puts the given double into the preferences table if it doesn't already exist. More...
 
static void SetFloat (std::string_view key, float value)
 Puts the given float into the preferences table. More...
 
static void InitFloat (std::string_view key, float value)
 Puts the given float into the preferences table if it doesn't already exist. More...
 
static void SetBoolean (std::string_view key, bool value)
 Puts the given boolean into the preferences table. More...
 
static void InitBoolean (std::string_view key, bool value)
 Puts the given boolean into the preferences table if it doesn't already exist. More...
 
static void SetLong (std::string_view key, int64_t value)
 Puts the given long (int64_t) into the preferences table. More...
 
static void InitLong (std::string_view key, int64_t value)
 Puts the given long into the preferences table if it doesn't already exist. More...
 
static bool ContainsKey (std::string_view key)
 Returns whether or not there is a key with the given name. More...
 
static void Remove (std::string_view key)
 Remove a preference. More...
 
static void RemoveAll ()
 Remove all preferences. More...
 

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

◆ ContainsKey()

static bool frc::Preferences::ContainsKey ( std::string_view  key)
static

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

◆ GetBoolean()

static bool frc::Preferences::GetBoolean ( std::string_view  key,
bool  defaultValue = false 
)
static

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

◆ GetDouble()

static double frc::Preferences::GetDouble ( std::string_view  key,
double  defaultValue = 0.0 
)
static

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

◆ GetFloat()

static float frc::Preferences::GetFloat ( std::string_view  key,
float  defaultValue = 0.0 
)
static

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

◆ GetInt()

static int frc::Preferences::GetInt ( std::string_view  key,
int  defaultValue = 0 
)
static

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

◆ GetKeys()

static std::vector< std::string > frc::Preferences::GetKeys ( )
static

Returns a vector of all the keys.

Returns
a vector of the keys

◆ GetLong()

static int64_t frc::Preferences::GetLong ( std::string_view  key,
int64_t  defaultValue = 0 
)
static

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

◆ GetString()

static std::string frc::Preferences::GetString ( std::string_view  key,
std::string_view  defaultValue = "" 
)
static

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

◆ InitBoolean()

static void frc::Preferences::InitBoolean ( std::string_view  key,
bool  value 
)
static

Puts the given boolean into the preferences table if it doesn't already exist.

◆ InitDouble()

static void frc::Preferences::InitDouble ( std::string_view  key,
double  value 
)
static

Puts the given double into the preferences table if it doesn't already exist.

◆ InitFloat()

static void frc::Preferences::InitFloat ( std::string_view  key,
float  value 
)
static

Puts the given float into the preferences table if it doesn't already exist.

◆ InitInt()

static void frc::Preferences::InitInt ( std::string_view  key,
int  value 
)
static

Puts the given int into the preferences table if it doesn't already exist.

◆ InitLong()

static void frc::Preferences::InitLong ( std::string_view  key,
int64_t  value 
)
static

Puts the given long into the preferences table if it doesn't already exist.

◆ InitString()

static void frc::Preferences::InitString ( std::string_view  key,
std::string_view  value 
)
static

Puts the given string into the preferences table if it doesn't already exist.

◆ Remove()

static void frc::Preferences::Remove ( std::string_view  key)
static

Remove a preference.

Parameters
keythe key

◆ RemoveAll()

static void frc::Preferences::RemoveAll ( )
static

Remove all preferences.

◆ SetBoolean()

static void frc::Preferences::SetBoolean ( std::string_view  key,
bool  value 
)
static

Puts the given boolean into the preferences table.

The key may not have any whitespace nor an equals sign.

Parameters
keythe key
valuethe value

◆ SetDouble()

static void frc::Preferences::SetDouble ( std::string_view  key,
double  value 
)
static

Puts the given double into the preferences table.

The key may not have any whitespace nor an equals sign.

Parameters
keythe key
valuethe value

◆ SetFloat()

static void frc::Preferences::SetFloat ( std::string_view  key,
float  value 
)
static

Puts the given float into the preferences table.

The key may not have any whitespace nor an equals sign.

Parameters
keythe key
valuethe value

◆ SetInt()

static void frc::Preferences::SetInt ( std::string_view  key,
int  value 
)
static

Puts the given int into the preferences table.

The key may not have any whitespace nor an equals sign.

Parameters
keythe key
valuethe value

◆ SetLong()

static void frc::Preferences::SetLong ( std::string_view  key,
int64_t  value 
)
static

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

◆ SetString()

static void frc::Preferences::SetString ( std::string_view  key,
std::string_view  value 
)
static

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

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