Now you can download a copy of these docs so you can use them offline! Download now
Preferences.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2011. 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 $(WIND_BASE)/WPILib. */
5 /*----------------------------------------------------------------------------*/
6 
7 #ifndef __PREFERENCES_H__
8 #define __PREFERENCES_H__
9 
10 #include "ErrorBase.h"
11 #include "Task.h"
12 #include <map>
13 #include <semLib.h>
14 #include <string>
15 #include <vector>
16 #include "tables/ITableListener.h"
17 #include "networktables/NetworkTable.h"
18 
34 class Preferences : public ErrorBase, public ITableListener
35 {
36 public:
37  static Preferences *GetInstance();
38 
39  std::vector<std::string> GetKeys();
40  std::string GetString(const char *key, const char *defaultValue = "");
41  int GetString(const char *key, char *value, int valueSize, const char *defaultValue = "");
42  int GetInt(const char *key, int defaultValue = 0);
43  double GetDouble(const char *key, double defaultValue = 0.0);
44  float GetFloat(const char *key, float defaultValue = 0.0);
45  bool GetBoolean(const char *key, bool defaultValue = false);
46  INT64 GetLong(const char *key, INT64 defaultValue = 0);
47  void PutString(const char *key, const char *value);
48  void PutInt(const char *key, int value);
49  void PutDouble(const char *key, double value);
50  void PutFloat(const char *key, float value);
51  void PutBoolean(const char *key, bool value);
52  void PutLong(const char *key, INT64 value);
53  void Save();
54  bool ContainsKey(const char *key);
55  void Remove(const char *key);
56 
57  void ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew);
58 
59 protected:
60  Preferences();
61  virtual ~Preferences();
62 
63 private:
64  std::string Get(const char *key);
65  void Put(const char *key, std::string value);
66 
67  void ReadTaskRun();
68  void WriteTaskRun();
69 
70  static int InitReadTask(Preferences *obj) {obj->ReadTaskRun();return 0;}
71  static int InitWriteTask(Preferences *obj) {obj->WriteTaskRun();return 0;}
72 
73  static Preferences *_instance;
74 
76  SEM_ID m_fileLock;
78  SEM_ID m_fileOpStarted;
80  SEM_ID m_tableLock;
81  typedef std::map<std::string, std::string> StringMap;
83  StringMap m_values;
85  std::vector<std::string> m_keys;
87  StringMap m_comments;
89  std::string m_endComment;
90  Task m_readTask;
91  Task m_writeTask;
92 };
93 
94 #endif
std::vector< std::string > GetKeys()
Definition: Preferences.cpp:74
std::string GetString(const char *key, const char *defaultValue="")
Definition: Preferences.cpp:86
void ValueChanged(ITable *source, const std::string &key, EntryValue value, bool isNew)
Definition: ITable.h:26
bool GetBoolean(const char *key, bool defaultValue=false)
void PutDouble(const char *key, double value)
void PutBoolean(const char *key, bool value)
void PutFloat(const char *key, float value)
void Remove(const char *key)
void PutString(const char *key, const char *value)
int GetInt(const char *key, int defaultValue=0)
void PutInt(const char *key, int value)
double GetDouble(const char *key, double defaultValue=0.0)
void PutLong(const char *key, INT64 value)
INT64 GetLong(const char *key, INT64 defaultValue=0)
Definition: Task.h:17
bool ContainsKey(const char *key)
Definition: ITable.h:13
float GetFloat(const char *key, float defaultValue=0.0)
static Preferences * GetInstance()
Definition: Preferences.cpp:63

Generated on Sat Apr 26 2014 12:26:45 for WPILibC++ by doxygen 1.8.6