22 #ifndef INCLUDE_OLAD_PREFERENCES_H_
23 #define INCLUDE_OLAD_PREFERENCES_H_
27 #include <ola/thread/Thread.h>
28 #include <ola/io/SelectServer.h>
46 virtual bool IsValid(
const std::string &value)
const = 0;
57 m_empty_ok(empty_ok) {
59 bool IsValid(
const std::string &value)
const;
62 const bool m_empty_ok;
72 explicit SetValidator(
const std::set<T> &values) : m_values(values) {}
73 bool IsValid(
const std::string &value)
const;
86 bool IsValid(
const std::string &value)
const;
91 static const char ENABLED[];
92 static const char DISABLED[];
101 UIntValidator(
unsigned int greater_than,
unsigned int less_than)
102 : m_gt(greater_than),
104 bool IsValid(
const std::string &value)
const;
107 unsigned int m_gt, m_lt;
117 : m_gt(greater_than),
119 bool IsValid(
const std::string &value)
const;
132 m_empty_ok(empty_ok) {}
134 bool IsValid(
const std::string &value)
const;
147 explicit Preferences(
const std::string name): m_preference_name(name) {}
157 virtual bool Load() = 0;
162 virtual bool Save()
const = 0;
167 virtual void Clear() = 0;
180 virtual void SetValue(
const std::string &key,
const std::string &value) = 0;
188 virtual void SetValue(
const std::string &key,
unsigned int value) = 0;
196 virtual void SetValue(
const std::string &key,
int value) = 0;
204 const std::string &value) = 0;
212 virtual void SetMultipleValue(
const std::string &key,
unsigned int value) = 0;
233 const std::string &value) = 0;
247 const char value[]) = 0;
260 unsigned int value) = 0;
294 virtual std::string
GetValue(
const std::string &key)
const = 0;
302 const std::string &key)
const = 0;
309 virtual bool HasKey(
const std::string &key)
const = 0;
315 virtual void RemoveValue(
const std::string &key) = 0;
330 virtual void SetValueAsBool(
const std::string &key,
bool value) = 0;
333 std::string m_preference_name;
364 virtual Preferences *Create(
const std::string &name) = 0;
365 std::map<std::string, Preferences*> m_preferences_map;
376 virtual bool Load() {
return true; }
377 virtual bool Save()
const {
return true; }
378 virtual void Clear();
382 virtual void SetValue(
const std::string &key,
const std::string &value);
383 virtual void SetValue(
const std::string &key,
unsigned int value);
384 virtual void SetValue(
const std::string &key,
int value);
386 const std::string &value);
391 const std::string &value);
405 virtual std::string
GetValue(
const std::string &key)
const;
407 const std::string &key)
const;
408 virtual bool HasKey(
const std::string &key)
const;
417 return m_pref_map == other.m_pref_map;
421 typedef std::multimap<std::string, std::string> PreferencesMap;
422 PreferencesMap m_pref_map;
442 typedef std::multimap<std::string, std::string> PreferencesMap;
445 void SavePreferences(
const std::string &filename,
446 const PreferencesMap &preferences);
456 bool Join(
void *ptr = NULL);
482 const std::string &name,
485 m_directory(directory),
486 m_saver_thread(saver_thread) {}
489 virtual bool Save()
const;
500 const std::string m_directory;
503 bool ChangeDir()
const;
508 const std::string FileName()
const;
509 static const char OLA_CONFIG_PREFIX[];
510 static const char OLA_CONFIG_SUFFIX[];
517 : m_directory(directory) {
518 m_saver_thread.
Start();
522 m_saver_thread.
Join();
528 const std::string m_directory;
536 #endif // INCLUDE_OLAD_PREFERENCES_H_
virtual std::string ConfigLocation() const =0
The location of where these preferences are stored.
bool Join(void *ptr=NULL)
Definition: Preferences.cpp:370
virtual bool SetDefaultValue(const std::string &key, const Validator &validator, const std::string &value)
Set a preference value if it doesn't already exist, or if it exists and doesn't pass the validator...
Definition: Preferences.cpp:249
Definition: Preferences.h:129
Definition: Preferences.h:514
virtual bool GetValueAsBool(const std::string &key) const
Get a preference value as a bool.
Definition: Preferences.cpp:325
Definition: Preferences.h:343
virtual bool HasKey(const std::string &key) const
Check if a preference key exists.
Definition: Preferences.cpp:315
virtual std::string GetValue(const std::string &key) const
Get a preference value.
Definition: Preferences.cpp:293
virtual void RemoveValue(const std::string &key)
Remove a preference value.
Definition: Preferences.cpp:320
virtual bool Save() const
Definition: Preferences.cpp:408
Definition: Preferences.h:479
virtual void SetValue(const std::string &key, const std::string &value)
Set a preference value, overriding the existing value.
Definition: Preferences.cpp:215
Definition: Preferences.h:41
virtual bool Save() const
Definition: Preferences.h:377
Definition: Preferences.h:70
virtual std::string ConfigLocation() const
The location where preferences will be stored.
Definition: Preferences.h:525
virtual bool Save() const =0
virtual bool Start()
Start the thread and wait for the thread to be running.
Definition: Thread.cpp:84
bool LoadFromFile(const std::string &filename)
Load these preferences from a file.
Definition: Preferences.cpp:420
virtual std::string ConfigLocation() const
The location of where these preferences are stored.
Definition: Preferences.h:380
virtual void RemoveValue(const std::string &key)=0
Remove a preference value.
virtual void SetValue(const std::string &key, const std::string &value)=0
Set a preference value, overriding the existing value.
virtual std::string ConfigLocation() const =0
The location where preferences will be stored.
virtual std::string ConfigLocation() const
The location where preferences will be stored.
Definition: Preferences.h:428
virtual void SetValueAsBool(const std::string &key, bool value)
Set a value as a bool.
Definition: Preferences.cpp:335
Definition: Preferences.h:99
virtual std::string GetValue(const std::string &key) const =0
Get a preference value.
Definition: Preferences.h:372
A single threaded I/O event management system.
Definition: SelectServer.h:63
virtual bool SetDefaultValue(const std::string &key, const Validator &validator, const std::string &value)=0
Set a preference value if it doesn't already exist, or if it exists and doesn't pass the validator...
std::string ConfigLocation() const
The location of where these preferences are stored.
Definition: Preferences.h:497
Definition: Preferences.h:53
virtual void SetValueAsBool(const std::string &key, bool value)=0
Set a value as a bool.
virtual bool GetValueAsBool(const std::string &key) const =0
Get a preference value as a bool.
Definition: Preferences.h:145
Definition: Preferences.h:426
virtual bool Load()
Definition: Preferences.h:376
virtual ~PreferencesFactory()
Definition: Preferences.cpp:180
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
virtual std::vector< std::string > GetMultipleValue(const std::string &key) const =0
Returns all preference values corresponding to this key.
virtual std::vector< std::string > GetMultipleValue(const std::string &key) const
Returns all preference values corresponding to this key.
Definition: Preferences.cpp:303
Definition: Preferences.h:440
Header file for OLA Logging.
virtual Preferences * NewPreference(const std::string &name)
Definition: Preferences.cpp:190
void * Run()
Definition: Preferences.cpp:364
virtual void Clear()
Definition: Preferences.cpp:210
void Syncronize()
Definition: Preferences.cpp:376
virtual bool HasKey(const std::string &key) const =0
Check if a preference key exists.
virtual bool Load()
Definition: Preferences.cpp:403
virtual ~Preferences()
Definition: Preferences.h:152
Definition: Preferences.h:83
virtual void SetMultipleValue(const std::string &key, const std::string &value)
Adds this preference value to the store.
Definition: Preferences.cpp:232
Definition: Preferences.h:114
virtual void SetMultipleValue(const std::string &key, const std::string &value)=0
Adds this preference value to the store.