Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef __APP_CONFIG_H__
- #define __APP_CONFIG_H__
- #include <wx/wx.h>
- #include <wx/config.h>
- class AppConfig
- {
- public:
- AppConfig() : m_config("bmp2oled", "LStudio") { }
- ~AppConfig() { }
- template<typename T>
- bool registerItem(const wxString& key, const T& default_value)
- {
- if (!m_config.Exists(key))
- {
- m_config.Write(key, default_value);
- return true;
- }
- return false;
- }
- bool read(const wxString& key, int& result) {
- return read_base(key, result, wxConfigBase::Type_Integer);
- }
- bool read(const wxString& key, wxString& result) {
- return read_base(key, result, wxConfigBase::Type_String);
- }
- bool write(const wxString& key, int value) {
- return write_base(key, value, wxConfigBase::Type_Integer);
- }
- bool write(const wxString& key, const wxString& value) {
- return write_base(key, value, wxConfigBase::Type_String);
- }
- private:
- wxConfig m_config;
- template<typename T>
- bool read_base(const wxString& key, T& result, wxConfigBase::EntryType type)
- {
- if (m_config.HasEntry(key) &&
- m_config.GetEntryType(key) == type)
- {
- return m_config.Read(key, &result);
- }
- return false;
- }
- template<typename T>
- bool write_base(const wxString& key, T value, wxConfigBase::EntryType type)
- {
- if (m_config.HasEntry(key) &&
- m_config.GetEntryType(key) == type)
- {
- return m_config.Write(key, value);
- }
- return false;
- }
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement