LRT14  1.0
 All Classes Namespaces Functions Variables Enumerations Enumerator
ConfigRuntime.h
1 #ifndef CONFIG_RUNTINE_H_
2 #define CONFIG_RUNTINE_H_
3 
4 #include <string>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <unistd.h>
8 #include <ctype.h>
9 #include <WPILib.h>
10 #include <vector>
11 #include <sys/stat.h>
12 #include <sys/types.h>
13 
14 class Configurable;
15 
19 struct Config
20 {
21  string value;
22  list<string>::iterator position;
23 };
24 typedef map<string, map<string, Config> > config;
25 
26 class ConfigRuntime
27 {
28 public:
29  static ConfigRuntime* Instance();
30  static void Finalize();
31 
32  ~ConfigRuntime();
33 
34  void Load();
35  void Save();
39  template<typename T> T Get(std::string section, std::string key, T defaultValue);
43  template<typename T> void Set(std::string section, std::string key, T value);
47  static void Register(Configurable* configurable);
51  static void ConfigureAll();
55  void CheckForFileUpdates();
56 
57 private:
58  ConfigRuntime();
59  static ConfigRuntime* m_instance;
60  static std::vector<Configurable*> configurables;
61 
65  void LoadConfig(std::string path);
69  void SaveConfig(std::string path);
70  std::list<string>* fileData;
71  config* configData;
72  std::map<string, std::list<std::string>::iterator>* sectionMap;
73  std::time_t lastReadTime;
74  bool KeyExists(std::string section, std::string key);
75 
76  const static std::string ConfigRuntime::CONFIG_FILE_PATH;
77  const static std::string ConfigRuntime::COMMENT_DELIMITERS;
78 
79  DISALLOW_COPY_AND_ASSIGN(ConfigRuntime);
80 };
81 
82 #endif