]> git.saurik.com Git - wxWidgets.git/commitdiff
attempt to fix DLL samples link with VC6 which has trouble instantiating template...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 31 Jan 2009 22:47:28 +0000 (22:47 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 31 Jan 2009 22:47:28 +0000 (22:47 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58575 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/persist.h
src/common/persist.cpp

index 23cf0691db510e693cd6a92e6b218094c38be182..0873ecdda28a52b88f3a51b2be5d8f69963e9fde 100644 (file)
@@ -108,32 +108,25 @@ public:
 \r
     // methods used by the persistent objects to save and restore the data\r
     //\r
-    // currently these methods simply use wxConfig::Get()\r
-    //\r
-    // TODO: make this customizable by allowing\r
-    //          (a) specifying custom wxConfig object to use\r
-    //          (b) allowing to use something else entirely\r
-    template <typename T>\r
-    bool\r
-    SaveValue(const wxPersistentObject& who, const wxString& name, T value)\r
-    {\r
-        wxConfigBase * const conf = GetConfig();\r
-        if ( !conf )\r
-            return false;\r
-\r
-        return conf->Write(GetKey(who, name), value);\r
-    }\r
-\r
-    template <typename T>\r
-    bool\r
-    RestoreValue(const wxPersistentObject& who, const wxString& name, T *value)\r
-    {\r
-        wxConfigBase * const conf = GetConfig();\r
-        if ( !conf )\r
-            return false;\r
-\r
-        return conf->Read(GetKey(who, name), value);\r
-    }\r
+    // currently these methods simply use wxConfig::Get() but they may be\r
+    // overridden in the derived class (once we allow creating custom\r
+    // persistent managers)\r
+#define wxPERSIST_DECLARE_SAVE_RESTORE_FOR(Type)                              \\r
+    virtual bool SaveValue(const wxPersistentObject& who,                     \\r
+                           const wxString& name,                              \\r
+                           Type value);                                       \\r
+                                                                              \\r
+    virtual bool                                                              \\r
+    RestoreValue(const wxPersistentObject& who,                               \\r
+                 const wxString& name,                                        \\r
+                 Type *value)\r
+\r
+    wxPERSIST_DECLARE_SAVE_RESTORE_FOR(bool);\r
+    wxPERSIST_DECLARE_SAVE_RESTORE_FOR(int);\r
+    wxPERSIST_DECLARE_SAVE_RESTORE_FOR(long);\r
+    wxPERSIST_DECLARE_SAVE_RESTORE_FOR(wxString);\r
+\r
+#undef wxPERSIST_DECLARE_SAVE_RESTORE_FOR\r
 \r
 private:\r
     // ctor is private, use Get()\r
@@ -143,7 +136,11 @@ private:
         m_doRestore = true;\r
     }\r
 \r
-    // helpers of Save/Restore(), will be customized later\r
+    // helpers of Save/Restore()\r
+    //\r
+    // TODO: make this customizable by allowing\r
+    //          (a) specifying custom wxConfig object to use\r
+    //          (b) allowing to use something else entirely\r
     wxConfigBase *GetConfig() const { return wxConfigBase::Get(); }\r
     wxString GetKey(const wxPersistentObject& who, const wxString& name) const;\r
 \r
index 80df492e5e85c92ea267cb71d62af577b030b97a..52c4513924da38efd06d3ecb28c716bc5c8a6cff 100644 (file)
@@ -107,3 +107,43 @@ bool wxPersistenceManager::Restore(void *obj)
     return it->second->Restore();
 }
 
+namespace
+{
+
+template <typename T>
+inline bool
+DoSaveValue(wxConfigBase *conf, const wxString& key, T value)
+{
+    return conf && conf->Write(key, value);
+}
+
+template <typename T>
+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