Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #ifndef __APP_CONFIG_H__
  2. #define __APP_CONFIG_H__
  3.  
  4. #include <wx/wx.h>
  5. #include <wx/config.h>
  6.  
  7. class AppConfig
  8. {
  9. public:
  10. AppConfig() : m_config("bmp2oled", "LStudio") { }
  11. ~AppConfig() { }
  12.  
  13. template<typename T>
  14. bool registerItem(const wxString& key, const T& default_value)
  15. {
  16. if (!m_config.Exists(key))
  17. {
  18. m_config.Write(key, default_value);
  19. return true;
  20. }
  21.  
  22. return false;
  23. }
  24.  
  25. bool read(const wxString& key, int& result) {
  26. return read_base(key, result, wxConfigBase::Type_Integer);
  27. }
  28. bool read(const wxString& key, wxString& result) {
  29. return read_base(key, result, wxConfigBase::Type_String);
  30. }
  31.  
  32. bool write(const wxString& key, int value) {
  33. return write_base(key, value, wxConfigBase::Type_Integer);
  34. }
  35. bool write(const wxString& key, const wxString& value) {
  36. return write_base(key, value, wxConfigBase::Type_String);
  37. }
  38.  
  39. private:
  40. wxConfig m_config;
  41.  
  42. template<typename T>
  43. bool read_base(const wxString& key, T& result, wxConfigBase::EntryType type)
  44. {
  45. if (m_config.HasEntry(key) &&
  46. m_config.GetEntryType(key) == type)
  47. {
  48. return m_config.Read(key, &result);
  49. }
  50. return false;
  51. }
  52.  
  53. template<typename T>
  54. bool write_base(const wxString& key, T value, wxConfigBase::EntryType type)
  55. {
  56. if (m_config.HasEntry(key) &&
  57. m_config.GetEntryType(key) == type)
  58. {
  59. return m_config.Write(key, value);
  60. }
  61. return false;
  62. }
  63. };
  64.  
  65. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement