22 bool Write(
const tstring& key,
const tstring& value)
29 bool Read(
const tstring& key, tstring& result)
const
62 bool Write(
const tstring& key,
const T& value)
64 return configStructWrite(*
this, key, value);
95 bool Read(
const tstring& key, T& result)
const
97 return configStructRead(*
this, key, result);
106 GetWindowRect(window, &r);
117 MoveWindow(window, r.left, r.top, r.Width(), r.Height(), TRUE);
123 virtual bool Remove(
const tstring& key) {
return false; }
132 virtual bool _SetStringImp(
const tstring& key,
const tstring& value) = 0;
136 virtual bool _GetStringImp(
const tstring& key, tstring& result)
const = 0;
141 static std::string
ToUtf8(
const tstring& text)
143 static_assert(
sizeof(TCHAR) ==
sizeof(
wchar_t),
"The config classes only work correctly if the project is setup as Unicode");
144 int n = WideCharToMultiByte(CP_UTF8, 0, text.c_str(), -1, 0, 0, 0, 0);
149 n = WideCharToMultiByte(CP_UTF8, 0, text.c_str(), -1, &result[0], n, 0, 0);
158 static_assert(
sizeof(TCHAR) ==
sizeof(
wchar_t),
"The config classes only work correctly if the project is setup as Unicode");
159 int n = MultiByteToWideChar(CP_UTF8, 0, text.c_str(), -1, 0, 0);
164 n = MultiByteToWideChar(CP_UTF8, 0, text.c_str(), -1, &result[0], n);
170 template<
class T,
class FROMSTRING>
171 bool Read(
const tstring& key, T& result, FROMSTRING fromString)
const
176 result = fromString(buffer);
196 RegistryConfig(
const tstring& subKey, HKEY topKey = HKEY_CURRENT_USER);
211 bool Open(
const tstring& subKey, HKEY topKey = HKEY_CURRENT_USER);
213 virtual bool Remove(
const tstring& key);
216 bool _SetStringImp(
const tstring& key,
const tstring& value);
217 bool _GetStringImp(
const tstring& key, tstring& result)
const;
243 bool Open(
const tstring& filepath);
258 virtual bool Remove(
const tstring& key);
261 bool _SetStringImp(
const tstring& key,
const tstring& value);
262 bool _GetStringImp(
const tstring& key, tstring& result)
const;
264 tstring Trim(
const tstring& text);
273 iniLine(
const iniLine& rhs)
276 , isSection(rhs.isSection)
279 iniLine& operator=(
const iniLine& rhs)
283 isSection = std::move(rhs.isSection);
284 isKey = std::move(rhs.isKey);
287 iniLine(iniLine&& rhs)
288 : text1(std::move(rhs.text1))
289 , text2(std::move(rhs.text2))
290 , isSection(rhs.isSection)
293 iniLine& operator=(iniLine&& rhs)
295 text1 = std::move(rhs.text1);
296 text2 = std::move(rhs.text2);
297 isSection = std::move(rhs.isSection);
298 isKey = std::move(rhs.isKey);
308 typedef std::vector<iniLine> LINES;
309 typedef std::vector<size_t> SECTION_INDEX;
310 typedef std::vector<size_t> KEY_INDEX;
313 SECTION_INDEX sections;
314 SECTION_INDEX::iterator currentSectionIt;
318 SECTION_INDEX::iterator _FindSection(
size_t index);
319 SECTION_INDEX::iterator _FindSection(
const tstring& section);
320 SECTION_INDEX::const_iterator _FindSection(
const tstring& section)
const;
321 size_t _FindValue(SECTION_INDEX::iterator section,
const tstring& key)
const;
322 void _AppendSection(
const tstring& section);
323 void _AppendLine(
const iniLine& line);
324 void _RebuildSectionIndices();
Configuration that writes to an ini-file.
Definition: Config.h:227
virtual bool RemoveEntireConfig()
Removes all values in the config, but the config can still used afterwards.
Definition: Config.h:127
virtual bool Remove(const tstring &key)
Remove a single value.
Definition: Config.inl:193
bool Read(const tstring &key, tstring &result) const
Basic read function.
Definition: Config.h:29
iniConfig()
Unusable until Open() is called.
Definition: Config.inl:92
bool _SetStringImp(const tstring &key, const tstring &value)
Every config value is internally saved as a string.
Definition: Config.inl:40
bool _GetStringImp(const tstring &key, tstring &result) const
Every config value is internally saved as a string.
Definition: Config.inl:241
bool Write(const tstring &key, const tstring &value)
Basic write function.
Definition: Config.h:22
virtual bool _SetStringImp(const tstring &key, const tstring &value)=0
Every config value is internally saved as a string.
void SetCurrentSection(const tstring §ion)
Set the section used by Read() and Write()
Definition: Config.inl:179
bool _SetStringImp(const tstring &key, const tstring &value)
Every config value is internally saved as a string.
Definition: Config.inl:222
Interface for all configuration classes.
Definition: Config.h:14
RegistryConfig & operator=(RegistryConfig &&other)
Move assignment.
Definition: Config.inl:21
virtual bool _GetStringImp(const tstring &key, tstring &result) const =0
Every config value is internally saved as a string.
bool Open(const tstring &subKey, HKEY topKey=HKEY_CURRENT_USER)
Definition: Config.inl:34
bool Open(const tstring &filepath)
Opens an ini file.
Definition: Config.inl:114
bool _GetStringImp(const tstring &key, tstring &result) const
Every config value is internally saved as a string.
Definition: Config.inl:51
virtual bool RemoveEntireConfig()
Removes all values in the config, but the config can still used afterwards.
Definition: Config.inl:213
virtual bool Remove(const tstring &key)
Remove a single value.
Definition: Config.h:123
Windows RECT structure with constructor.
Definition: Rect.h:108
virtual bool Remove(const tstring &key)
Remove a single value.
Definition: Config.inl:75
Configuration that writes to the Window registry.
Definition: Config.h:186
bool Save()
The config is saved in the destructor. This function allows to manually start the saving...
Definition: Config.inl:155
static std::string ToUtf8(const tstring &text)
All config should be saved as UTF-8 for portability.
Definition: Config.h:141
RegistryConfig()
Unusable until Open() is called.
Definition: Config.inl:4
static tstring FromUtf8(const std::string &text)
All config should be saved as UTF-8 for portability.
Definition: Config.h:156
bool Write(const tstring &key, const T &value)
Extendable version of Write.
Definition: Config.h:62
bool Read(const tstring &key, T &result) const
Extendable version of Read.
Definition: Config.h:95
virtual bool RemoveEntireConfig()
Removes all values in the config, but the config can still used afterwards.
Definition: Config.inl:82
void SaveWindowPosition(const tstring &key, HWND window)
Convenience function for window position.
Definition: Config.h:103
void RestoreWindowPosition(const tstring &key, HWND window)
Convenience function for window position.
Definition: Config.h:113