WPILibC++  2020.3.2-60-g3011ebe
Preferences.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2011-2020 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <stdint.h>
11 
12 #include <memory>
13 #include <string>
14 #include <vector>
15 
16 #include <networktables/NetworkTable.h>
17 
18 #include "frc/ErrorBase.h"
19 
20 namespace frc {
21 
36 class Preferences : public ErrorBase {
37  public:
43  static Preferences* GetInstance();
44 
50  std::vector<std::string> GetKeys();
51 
60  std::string GetString(wpi::StringRef key, wpi::StringRef defaultValue = "");
61 
70  int GetInt(wpi::StringRef key, int defaultValue = 0);
71 
80  double GetDouble(wpi::StringRef key, double defaultValue = 0.0);
81 
90  float GetFloat(wpi::StringRef key, float defaultValue = 0.0);
91 
100  bool GetBoolean(wpi::StringRef key, bool defaultValue = false);
101 
111  int64_t GetLong(wpi::StringRef key, int64_t defaultValue = 0);
112 
122  void PutString(wpi::StringRef key, wpi::StringRef value);
123 
128  void InitString(wpi::StringRef key, wpi::StringRef value);
129 
138  void PutInt(wpi::StringRef key, int value);
139 
144  void InitInt(wpi::StringRef key, int value);
145 
154  void PutDouble(wpi::StringRef key, double value);
155 
160  void InitDouble(wpi::StringRef key, double value);
161 
170  void PutFloat(wpi::StringRef key, float value);
171 
176  void InitFloat(wpi::StringRef key, float value);
177 
186  void PutBoolean(wpi::StringRef key, bool value);
187 
192  void InitBoolean(wpi::StringRef key, bool value);
193 
202  void PutLong(wpi::StringRef key, int64_t value);
203 
208  void InitLong(wpi::StringRef key, int64_t value);
209 
216  bool ContainsKey(wpi::StringRef key);
217 
223  void Remove(wpi::StringRef key);
224 
228  void RemoveAll();
229 
230  protected:
231  Preferences();
232  virtual ~Preferences() = default;
233 
234  Preferences(Preferences&&) = default;
235  Preferences& operator=(Preferences&&) = default;
236 
237  private:
238  std::shared_ptr<nt::NetworkTable> m_table;
239  NT_EntryListener m_listener;
240 };
241 
242 } // namespace frc
frc::Preferences::InitDouble
void InitDouble(wpi::StringRef key, double value)
Puts the given double into the preferences table if it doesn't already exist.
frc::Preferences::PutBoolean
void PutBoolean(wpi::StringRef key, bool value)
Puts the given boolean into the preferences table.
frc::Preferences::ContainsKey
bool ContainsKey(wpi::StringRef key)
Returns whether or not there is a key with the given name.
frc::Preferences::GetDouble
double GetDouble(wpi::StringRef key, double defaultValue=0.0)
Returns the double at the given key.
frc::Preferences::GetLong
int64_t GetLong(wpi::StringRef key, int64_t defaultValue=0)
Returns the long (int64_t) at the given key.
frc::Preferences::PutFloat
void PutFloat(wpi::StringRef key, float value)
Puts the given float into the preferences table.
frc::Preferences::InitBoolean
void InitBoolean(wpi::StringRef key, bool value)
Puts the given boolean into the preferences table if it doesn't already exist.
frc::Preferences::Remove
void Remove(wpi::StringRef key)
Remove a preference.
frc::ErrorBase
Base class for most objects.
Definition: ErrorBase.h:104
wpi::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
frc::Preferences::PutDouble
void PutDouble(wpi::StringRef key, double value)
Puts the given double into the preferences table.
frc::Preferences::InitLong
void InitLong(wpi::StringRef key, int64_t value)
Puts the given long into the preferences table if it doesn't already exist.
frc::Preferences::GetKeys
std::vector< std::string > GetKeys()
Returns a vector of all the keys.
frc::Preferences::GetBoolean
bool GetBoolean(wpi::StringRef key, bool defaultValue=false)
Returns the boolean at the given key.
frc::Preferences::RemoveAll
void RemoveAll()
Remove all preferences.
frc::Preferences::PutLong
void PutLong(wpi::StringRef key, int64_t value)
Puts the given long (int64_t) into the preferences table.
frc::Preferences::PutInt
void PutInt(wpi::StringRef key, int value)
Puts the given int into the preferences table.
frc::Preferences::GetFloat
float GetFloat(wpi::StringRef key, float defaultValue=0.0)
Returns the float at the given key.
frc::Preferences::InitString
void InitString(wpi::StringRef key, wpi::StringRef value)
Puts the given string into the preferences table if it doesn't already exist.
frc::Preferences::GetInstance
static Preferences * GetInstance()
Get the one and only Preferences object.
frc
A class that enforces constraints on the differential drive kinematics.
Definition: PDPSim.h:16
frc::Preferences::GetInt
int GetInt(wpi::StringRef key, int defaultValue=0)
Returns the int at the given key.
frc::Preferences::InitFloat
void InitFloat(wpi::StringRef key, float value)
Puts the given float into the preferences table if it doesn't already exist.
frc::Preferences::GetString
std::string GetString(wpi::StringRef key, wpi::StringRef defaultValue="")
Returns the string at the given key.
frc::Preferences
The preferences class provides a relatively simple way to save important values to the roboRIO to acc...
Definition: Preferences.h:36
frc::Preferences::PutString
void PutString(wpi::StringRef key, wpi::StringRef value)
Puts the given string into the preferences table.
frc::Preferences::InitInt
void InitInt(wpi::StringRef key, int value)
Puts the given int into the preferences table if it doesn't already exist.