7 #include "../ipreference.h" 8 #include "../iapplication.h" 12 namespace Standalone {
14 static const char* DefaultPreferencesGroupSeparator =
"::";
23 Preferences (
const std::initializer_list<const char*>& groups,
const char* groupSeparator = DefaultPreferencesGroupSeparator)
24 : groupSeparator (groupSeparator)
26 for (
auto& g : groups)
30 Preferences (
const UTF8String& inGroupKey =
"",
const char* groupSeparator = DefaultPreferencesGroupSeparator)
31 : groupKey (inGroupKey)
32 , groupSeparator (groupSeparator)
34 if (!groupKey.empty ())
35 groupKey += groupSeparator;
40 return Preferences (groupKey + subGroup, groupSeparator);
45 if (!groupKey.empty ())
46 return preferences.
set (groupKey + key, value);
47 return preferences.
set (key, value);
52 if (!groupKey.empty ())
53 return preferences.
get (groupKey + key);
54 return preferences.
get (key);
58 inline bool setNumber (
const UTF8String& key, T value)
const 60 return set (key, toString (value));
64 inline bool setFloat (
const UTF8String& key, T value, uint32_t precision = 8)
const 66 std::ostringstream sstream;
67 sstream.imbue (std::locale::classic ());
68 sstream.precision (static_cast<std::streamsize> (precision));
76 if (
auto p =
get (key))
83 inline bool setPoint (
const UTF8String& key,
CPoint p, uint32_t precision = 8)
const 85 std::ostringstream sstream;
86 sstream.imbue (std::locale::classic ());
87 sstream.precision (static_cast<std::streamsize> (precision));
98 if (
auto p =
get (key))
100 std::istringstream sstream (p->getString ());
101 sstream.imbue (std::locale::classic ());
104 if (sstream.fail () || c !=
'{')
109 if (sstream.fail () || c !=
';')
114 if (sstream.fail () || c !=
'}')
121 inline const UTF8String& getGroupKey ()
const {
return groupKey; }
122 inline const UTF8String& getGroupSeparator ()
const {
return groupSeparator; }
virtual IPreference & getPreferences() const =0
Definition: customcontrols.cpp:8
virtual bool set(const UTF8String &key, const UTF8String &value)=0
a view on a null terminated UTF-8 String
Definition: cstring.h:172
static IApplication & instance()
Definition: application.cpp:451
Definition: preferences.h:17
holds an UTF8 encoded string and a platform representation of it
Definition: cstring.h:56
Definition: optional.h:18
virtual Optional< UTF8String > get(const UTF8String &key)=0
Point structure.
Definition: cpoint.h:17
Definition: ipreference.h:22