MCPcopy Create free account
hub / github.com/BeneficialCode/WinArk / Settings

Class Settings

WinArk/Settings.h:92–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90 void name(std::vector<std::wstring> const& value) { Set(L#name, value); }
91
92class Settings {
93public:
94 Settings() = default;
95
96 bool LoadFromKey(PCWSTR registryPath = nullptr);
97 bool SaveToKey(PCWSTR registryPath = nullptr) const;
98 bool LoadFromFile(PCWSTR path = nullptr);
99 bool SaveToFile(PCWSTR path = nullptr) const;
100 bool Load(PCWSTR path);
101 bool Save() const;
102
103 template<typename T>
104 void Set(const std::wstring& name, const T& value, SettingType type = SettingType::Binary) {
105 auto it = _settings.find(name);
106 if (it != _settings.end()) {
107 it->second.Set(value);
108 }
109 else {
110 Setting s(name, value, type);
111 _settings.insert({ name,std::move(s) });
112 }
113 }
114
115 void Set(PCWSTR name, int value);
116 void Set(PCWSTR name, std::vector<std::wstring> const& values);
117 void SetString(PCWSTR name, PCWSTR value);
118
119 std::wstring GetString(PCWSTR name) const;
120
121 template<typename T>
122 T GetValue(PCWSTR name) const {
123 auto it = _settings.find(name);
124 ATLASSERT(it != _settings.end());
125 ATLASSERT(it->second.Size == sizeof(T));
126 return *(T*)it->second.Buffer.get();
127 }
128
129 template<typename T>
130 T& GetValueRef(PCWSTR name) const {
131 auto it = _settings.find(name);
132 ATLASSERT(it != _settings.end());
133 ATLASSERT(it->second.Size == sizeof(T));
134 return *(T*)it->second.Buffer.get();
135 }
136
137 template<typename T>
138 T GetValueOrDefault(PCWSTR name, const T& def = T()) const {
139 auto it = _settings.find(name);
140 if (it == _settings.end())
141 return def;
142 ATLASSERT(it->second.Size == sizeof(T));
143 return *(T*)it->second.Buffer.get();
144 }
145
146 int GetInt32(PCWSTR name) const;
147
148 std::vector<std::wstring> GetMultiString(PCWSTR name) const {
149 auto it = _settings.find(name);

Callers

nothing calls this directly

Calls 1

endMethod · 0.45

Tested by

no test coverage detected