LRT13  1.0
 All Classes Namespaces Functions Variables Enumerations Enumerator
ConfigManager.h
1 #ifndef CONFIG_MANAGER_H_
2 #define CONFIG_MANAGER_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 #include "Configurable.h"
15 
16 using namespace std;
17 
23 struct Config
24 {
25  string value;
26  list<string>::iterator position;
27 };
28 typedef map<string, map<string, Config> > config;
29 
30 class ConfigManager
31 {
32 public:
33  static ConfigManager* Instance();
34  static void Finalize();
35 
36  ~ConfigManager();
37 
38  void Load();
39  void Save();
43  template<typename T> T Get(string section, string key, T defaultValue);
47  template<typename T> void Set(string section, string key, T value);
51  static void Register(Configurable* configurable);
55  static void ConfigureAll();
59  void CheckForFileUpdates();
60 
61 private:
62  ConfigManager();
63  static ConfigManager* m_instance;
64  static vector<Configurable*> configurables;
65 
69  void LoadConfig(string path);
73  void SaveConfig(string path);
74  list<string> *fileData;
75  config* configData;
76  map<string, list<string>::iterator> *sectionMap;
77  time_t lastReadTime;
78  bool KeyExists(string section, string key);
79  string Trim(string str);
80 
81  const static string ConfigManager::CONFIG_FILE_PATH;
82  const static string ConfigManager::COMMENT_DELIMITERS;
83 
84  DISALLOW_COPY_AND_ASSIGN(ConfigManager);
85 };
86 
87 #endif