22 #ifndef INCLUDE_OLAD_PREFERENCES_H_ 23 #define INCLUDE_OLAD_PREFERENCES_H_ 27 #include <ola/io/SelectServer.h> 30 #include <ola/thread/Thread.h> 48 virtual bool IsValid(
const std::string &value)
const = 0;
59 m_empty_ok(empty_ok) {
61 bool IsValid(
const std::string &value)
const;
64 const bool m_empty_ok;
74 explicit SetValidator(
const std::set<T> &values) : m_values(values) {}
75 bool IsValid(
const std::string &value)
const;
88 bool IsValid(
const std::string &value)
const;
93 static const char ENABLED[];
94 static const char DISABLED[];
103 UIntValidator(
unsigned int greater_than,
unsigned int less_than)
104 : m_gt(greater_than),
106 bool IsValid(
const std::string &value)
const;
109 unsigned int m_gt, m_lt;
119 : m_gt(greater_than),
121 bool IsValid(
const std::string &value)
const;
134 m_empty_ok(empty_ok) {}
136 bool IsValid(
const std::string &value)
const;
149 explicit Preferences(
const std::string name): m_preference_name(name) {}
159 virtual bool Load() = 0;
164 virtual bool Save()
const = 0;
169 virtual void Clear() = 0;
175 virtual std::string ConfigLocation()
const = 0;
182 virtual void SetValue(
const std::string &key,
const std::string &value) = 0;
190 virtual void SetValue(
const std::string &key,
unsigned int value) = 0;
198 virtual void SetValue(
const std::string &key,
int value) = 0;
205 virtual void SetMultipleValue(
const std::string &key,
206 const std::string &value) = 0;
214 virtual void SetMultipleValue(
const std::string &key,
unsigned int value) = 0;
222 virtual void SetMultipleValue(
const std::string &key,
int value) = 0;
233 virtual bool SetDefaultValue(
const std::string &key,
235 const std::string &value) = 0;
247 virtual bool SetDefaultValue(
const std::string &key,
249 const char value[]) = 0;
260 virtual bool SetDefaultValue(
const std::string &key,
262 unsigned int value) = 0;
273 virtual bool SetDefaultValue(
const std::string &key,
286 virtual bool SetDefaultValue(
const std::string &key,
296 virtual std::string GetValue(
const std::string &key)
const = 0;
303 virtual std::vector<std::string> GetMultipleValue(
304 const std::string &key)
const = 0;
311 virtual bool HasKey(
const std::string &key)
const = 0;
317 virtual void RemoveValue(
const std::string &key) = 0;
325 virtual bool GetValueAsBool(
const std::string &key)
const = 0;
332 virtual void SetValueAsBool(
const std::string &key,
bool value) = 0;
335 std::string m_preference_name;
357 virtual Preferences *NewPreference(
const std::string &name);
363 virtual std::string ConfigLocation()
const = 0;
366 virtual Preferences *Create(
const std::string &name) = 0;
367 std::map<std::string, Preferences*> m_preferences_map;
378 virtual bool Load() {
return true; }
379 virtual bool Save()
const {
return true; }
380 virtual void Clear();
384 virtual void SetValue(
const std::string &key,
const std::string &value);
385 virtual void SetValue(
const std::string &key,
unsigned int value);
386 virtual void SetValue(
const std::string &key,
int value);
387 virtual void SetMultipleValue(
const std::string &key,
388 const std::string &value);
389 virtual void SetMultipleValue(
const std::string &key,
unsigned int value);
390 virtual void SetMultipleValue(
const std::string &key,
int value);
391 virtual bool SetDefaultValue(
const std::string &key,
393 const std::string &value);
394 virtual bool SetDefaultValue(
const std::string &key,
397 virtual bool SetDefaultValue(
const std::string &key,
400 virtual bool SetDefaultValue(
const std::string &key,
403 virtual bool SetDefaultValue(
const std::string &key,
407 virtual std::string GetValue(
const std::string &key)
const;
408 virtual std::vector<std::string> GetMultipleValue(
409 const std::string &key)
const;
410 virtual bool HasKey(
const std::string &key)
const;
412 virtual void RemoveValue(
const std::string &key);
415 virtual bool GetValueAsBool(
const std::string &key)
const;
416 virtual void SetValueAsBool(
const std::string &key,
bool value);
419 return m_pref_map == other.m_pref_map;
423 typedef std::multimap<std::string, std::string> PreferencesMap;
424 PreferencesMap m_pref_map;
444 typedef std::multimap<std::string, std::string> PreferencesMap;
447 void SavePreferences(
const std::string &filename,
448 const PreferencesMap &preferences);
458 bool Join(
void *ptr = NULL);
484 const std::string &name,
487 m_directory(directory),
488 m_saver_thread(saver_thread) {}
491 virtual bool Save()
const;
497 bool LoadFromFile(
const std::string &filename);
502 const std::string m_directory;
505 bool ChangeDir()
const;
510 const std::string FileName()
const;
511 static const char OLA_CONFIG_PREFIX[];
512 static const char OLA_CONFIG_SUFFIX[];
519 : m_directory(directory) {
520 m_saver_thread.Start();
524 m_saver_thread.Join();
530 const std::string m_directory;
538 #endif // INCLUDE_OLAD_PREFERENCES_H_ Definition: Preferences.h:131
Definition: Preferences.h:516
Definition: Preferences.h:345
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Creates dummy copy constructor and assignment operator declarations.
Definition: Macro.h:44
Definition: Preferences.h:481
virtual bool Save() const
Definition: Preferences.h:379
virtual std::string ConfigLocation() const
The location where preferences will be stored.
Definition: Preferences.h:527
Definition: Preferences.h:43
Definition: Preferences.h:72
std::string ConfigLocation() const
The location of where these preferences are stored.
Definition: Preferences.h:499
Definition: Preferences.h:101
Definition: Preferences.h:374
A single threaded I/O event management system.
Definition: SelectServer.h:63
Definition: Preferences.h:55
Definition: Preferences.h:147
Definition: Preferences.h:428
virtual bool Load()
Definition: Preferences.h:378
virtual std::string ConfigLocation() const
The location where preferences will be stored.
Definition: Preferences.h:430
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Definition: Preferences.h:442
Header file for OLA Logging.
virtual std::string ConfigLocation() const
The location of where these preferences are stored.
Definition: Preferences.h:382
virtual ~Preferences()
Definition: Preferences.h:154
Definition: Preferences.h:85
Definition: Preferences.h:116