22 #ifndef INCLUDE_OLAD_PREFERENCES_H_
23 #define INCLUDE_OLAD_PREFERENCES_H_
26 #include <ola/thread/Thread.h>
27 #include <ola/io/SelectServer.h>
51 virtual bool IsValid(
const string &value)
const = 0;
62 m_empty_ok(empty_ok) {
64 bool IsValid(
const string &value)
const;
67 const bool m_empty_ok;
78 bool IsValid(
const string &value)
const;
91 bool IsValid(
const string &value)
const;
96 static const char ENABLED[];
97 static const char DISABLED[];
106 IntValidator(
unsigned int greater_than,
unsigned int less_than):
109 bool IsValid(
const string &value)
const;
112 unsigned int m_gt, m_lt;
122 m_empty_ok(empty_ok) {}
124 bool IsValid(
const string &value)
const;
135 explicit Preferences(
const string name): m_preference_name(name) {}
138 virtual bool Load() = 0;
139 virtual bool Save()
const = 0;
140 virtual void Clear() = 0;
143 virtual string Source()
const = 0;
145 virtual void SetValue(
const string &key,
const string &value) = 0;
146 virtual void SetMultipleValue(
const string &key,
const string &value) = 0;
147 virtual bool SetDefaultValue(
const string &key,
149 const string &value) = 0;
151 virtual string GetValue(
const string &key)
const = 0;
152 virtual vector<string> GetMultipleValue(
const string &key)
const = 0;
153 virtual bool HasKey(
const string &key)
const = 0;
155 virtual void RemoveValue(
const string &key) = 0;
158 virtual bool GetValueAsBool(
const string &key)
const = 0;
159 virtual void SetValueAsBool(
const string &key,
bool value) = 0;
162 string m_preference_name;
179 virtual Preferences *Create(
const string &name) = 0;
180 map<string, Preferences*> m_preferences_map;
191 virtual bool Load() {
return true; }
192 virtual bool Save()
const {
return true; }
193 virtual void Clear();
195 virtual string Source()
const {
return "Not Saved"; }
197 virtual void SetValue(
const string &key,
const string &value);
198 virtual void SetMultipleValue(
const string &key,
const string &value);
199 virtual bool SetDefaultValue(
const string &key,
201 const string &value);
203 virtual string GetValue(
const string &key)
const;
204 virtual vector<string> GetMultipleValue(
const string &key)
const;
205 virtual bool HasKey(
const string &key)
const;
207 virtual void RemoveValue(
const string &key);
210 virtual bool GetValueAsBool(
const string &key)
const;
211 virtual void SetValueAsBool(
const string &key,
bool value);
214 return m_pref_map == other.m_pref_map;
218 typedef multimap<string, string> PreferencesMap;
219 PreferencesMap m_pref_map;
236 typedef multimap<string, string> PreferencesMap;
239 void SavePreferences(
const string &filename,
240 const PreferencesMap &preferences);
243 bool Join(
void *ptr = NULL);
249 void SaveToFile(
const string *filename,
const PreferencesMap *preferences);
264 m_directory(directory),
265 m_saver_thread(saver_thread) {}
267 virtual bool Save()
const;
268 bool LoadFromFile(
const string &filename);
270 string Source()
const {
return FileName(); }
273 const string m_directory;
276 bool ChangeDir()
const;
277 const string FileName()
const;
278 static const char OLA_CONFIG_PREFIX[];
279 static const char OLA_CONFIG_SUFFIX[];
286 : m_directory(directory) {
287 m_saver_thread.Start();
291 m_saver_thread.
Join();
295 const string m_directory;
303 #endif // INCLUDE_OLAD_PREFERENCES_H_