X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0fa541e8706f74887efeba9e475eae618873da2a..74a8f67d96591cec101def2a7d47c64072aff7fd:/src/common/persist.cpp diff --git a/src/common/persist.cpp b/src/common/persist.cpp index 80df492e5e..7f8898f327 100644 --- a/src/common/persist.cpp +++ b/src/common/persist.cpp @@ -23,6 +23,8 @@ #pragma hdrstop #endif +#if wxUSE_CONFIG + #ifndef WX_PRECOMP #endif // WX_PRECOMP @@ -40,6 +42,10 @@ wxPersistenceManager& wxPersistenceManager::Get() return s_manager; } +wxPersistenceManager::~wxPersistenceManager() +{ +} + wxString wxPersistenceManager::GetKey(const wxPersistentObject& who, const wxString& name) const @@ -107,3 +113,45 @@ bool wxPersistenceManager::Restore(void *obj) return it->second->Restore(); } +namespace +{ + +template +inline bool +DoSaveValue(wxConfigBase *conf, const wxString& key, T value) +{ + return conf && conf->Write(key, value); +} + +template +bool +DoRestoreValue(wxConfigBase *conf, const wxString& key, T *value) +{ + return conf && conf->Read(key, value); +} + +} // anonymous namespace + +#define wxPERSIST_DEFINE_SAVE_RESTORE_FOR(Type) \ + bool wxPersistenceManager::SaveValue(const wxPersistentObject& who, \ + const wxString& name, \ + Type value) \ + { \ + return DoSaveValue(GetConfig(), GetKey(who, name), value); \ + } \ + \ + bool wxPersistenceManager::RestoreValue(const wxPersistentObject& who, \ + const wxString& name, \ + Type *value) \ + { \ + return DoRestoreValue(GetConfig(), GetKey(who, name), value); \ + } + +wxPERSIST_DEFINE_SAVE_RESTORE_FOR(bool) +wxPERSIST_DEFINE_SAVE_RESTORE_FOR(int) +wxPERSIST_DEFINE_SAVE_RESTORE_FOR(long) +wxPERSIST_DEFINE_SAVE_RESTORE_FOR(wxString) + +#undef wxPERSIST_DEFINE_SAVE_RESTORE_FOR + +#endif // wxUSE_CONFIG