WPILibC++  unspecified
Preferences.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2011-2017 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 "ErrorBase.h"
17 #include "networktables/NetworkTable.h"
18 
19 namespace frc {
20 
35 class Preferences : public ErrorBase {
36  public:
37  static Preferences* GetInstance();
38 
39  std::vector<std::string> GetKeys();
40  std::string GetString(llvm::StringRef key, llvm::StringRef defaultValue = "");
41  int GetInt(llvm::StringRef key, int defaultValue = 0);
42  double GetDouble(llvm::StringRef key, double defaultValue = 0.0);
43  float GetFloat(llvm::StringRef key, float defaultValue = 0.0);
44  bool GetBoolean(llvm::StringRef key, bool defaultValue = false);
45  int64_t GetLong(llvm::StringRef key, int64_t defaultValue = 0);
46  void PutString(llvm::StringRef key, llvm::StringRef value);
47  void PutInt(llvm::StringRef key, int value);
48  void PutDouble(llvm::StringRef key, double value);
49  void PutFloat(llvm::StringRef key, float value);
50  void PutBoolean(llvm::StringRef key, bool value);
51  void PutLong(llvm::StringRef key, int64_t value);
52  bool ContainsKey(llvm::StringRef key);
53  void Remove(llvm::StringRef key);
54 
55  protected:
56  Preferences();
57  virtual ~Preferences() = default;
58 
59  private:
60  std::shared_ptr<nt::NetworkTable> m_table;
61  NT_EntryListener m_listener;
62 };
63 
64 } // namespace frc
int64_t GetLong(llvm::StringRef key, int64_t defaultValue=0)
Returns the long (int64_t) at the given key.
Definition: Preferences.cpp:119
bool GetBoolean(llvm::StringRef key, bool defaultValue=false)
Returns the boolean at the given key.
Definition: Preferences.cpp:107
std::vector< std::string > GetKeys()
Returns a vector of all the keys.
Definition: Preferences.cpp:48
Definition: Timer.cpp:18
The preferences class provides a relatively simple way to save important values to the roboRIO to acc...
Definition: Preferences.h:35
void PutFloat(llvm::StringRef key, float value)
Puts the given float into the preferences table.
Definition: Preferences.cpp:174
static Preferences * GetInstance()
Get the one and only Preferences object.
Definition: Preferences.cpp:38
std::string GetString(llvm::StringRef key, llvm::StringRef defaultValue="")
Returns the string at the given key.
Definition: Preferences.cpp:58
void PutBoolean(llvm::StringRef key, bool value)
Puts the given boolean into the preferences table.
Definition: Preferences.cpp:188
float GetFloat(llvm::StringRef key, float defaultValue=0.0)
Returns the float at the given key.
Definition: Preferences.cpp:95
void PutString(llvm::StringRef key, llvm::StringRef value)
Puts the given string into the preferences table.
Definition: Preferences.cpp:132
double GetDouble(llvm::StringRef key, double defaultValue=0.0)
Returns the double at the given key.
Definition: Preferences.cpp:83
void PutLong(llvm::StringRef key, int64_t value)
Puts the given long (int64_t) into the preferences table.
Definition: Preferences.cpp:202
bool ContainsKey(llvm::StringRef key)
Returns whether or not there is a key with the given name.
Definition: Preferences.cpp:214
void Remove(llvm::StringRef key)
Remove a preference.
Definition: Preferences.cpp:223
Base class for most objects.
Definition: ErrorBase.h:74
int GetInt(llvm::StringRef key, int defaultValue=0)
Returns the int at the given key.
Definition: Preferences.cpp:71
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:42
void PutDouble(llvm::StringRef key, double value)
Puts the given double into the preferences table.
Definition: Preferences.cpp:160
void PutInt(llvm::StringRef key, int value)
Puts the given int into the preferences table.
Definition: Preferences.cpp:146