X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0fa541e8706f74887efeba9e475eae618873da2a..6d8978f030996c834fcd29d85d95ebe261b8defc:/include/wx/persist.h?ds=sidebyside diff --git a/include/wx/persist.h b/include/wx/persist.h index 7e331b6480..0873ecdda2 100644 --- a/include/wx/persist.h +++ b/include/wx/persist.h @@ -50,8 +50,8 @@ public: // globally disable restoring or saving the persistent properties (both are // enabled by default) - bool DisableSaving() { m_doSave = false; } - bool DisableRestoring() { m_doRestore = false; } + void DisableSaving() { m_doSave = false; } + void DisableRestoring() { m_doRestore = false; } // register an object with the manager: when using the first overload, @@ -108,32 +108,25 @@ public: // methods used by the persistent objects to save and restore the data // - // currently these methods simply use wxConfig::Get() - // - // TODO: make this customizable by allowing - // (a) specifying custom wxConfig object to use - // (b) allowing to use something else entirely - template - bool - SaveValue(const wxPersistentObject& who, const wxString& name, T value) - { - wxConfigBase * const conf = GetConfig(); - if ( !conf ) - return false; - - return conf->Write(GetKey(who, name), value); - } - - template - bool - RestoreValue(const wxPersistentObject& who, const wxString& name, T *value) - { - wxConfigBase * const conf = GetConfig(); - if ( !conf ) - return false; - - return conf->Read(GetKey(who, name), value); - } + // currently these methods simply use wxConfig::Get() but they may be + // overridden in the derived class (once we allow creating custom + // persistent managers) +#define wxPERSIST_DECLARE_SAVE_RESTORE_FOR(Type) \ + virtual bool SaveValue(const wxPersistentObject& who, \ + const wxString& name, \ + Type value); \ + \ + virtual bool \ + RestoreValue(const wxPersistentObject& who, \ + const wxString& name, \ + Type *value) + + wxPERSIST_DECLARE_SAVE_RESTORE_FOR(bool); + wxPERSIST_DECLARE_SAVE_RESTORE_FOR(int); + wxPERSIST_DECLARE_SAVE_RESTORE_FOR(long); + wxPERSIST_DECLARE_SAVE_RESTORE_FOR(wxString); + +#undef wxPERSIST_DECLARE_SAVE_RESTORE_FOR private: // ctor is private, use Get() @@ -143,7 +136,11 @@ private: m_doRestore = true; } - // helpers of Save/Restore(), will be customized later + // helpers of Save/Restore() + // + // TODO: make this customizable by allowing + // (a) specifying custom wxConfig object to use + // (b) allowing to use something else entirely wxConfigBase *GetConfig() const { return wxConfigBase::Get(); } wxString GetKey(const wxPersistentObject& who, const wxString& name) const;