From c7c8fac6f809de2fcf9aa2092429aa320be9c750 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 31 Jan 2009 22:47:28 +0000 Subject: [PATCH] attempt to fix DLL samples link with VC6 which has trouble instantiating template methods of dll-exported classes apparently git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58575 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/persist.h | 51 ++++++++++++++++++++---------------------- src/common/persist.cpp | 40 +++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 27 deletions(-) diff --git a/include/wx/persist.h b/include/wx/persist.h index 23cf0691db..0873ecdda2 100644 --- a/include/wx/persist.h +++ b/include/wx/persist.h @@ -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; diff --git a/src/common/persist.cpp b/src/common/persist.cpp index 80df492e5e..52c4513924 100644 --- a/src/common/persist.cpp +++ b/src/common/persist.cpp @@ -107,3 +107,43 @@ 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 -- 2.45.2