]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/persist.cpp
Make wxSpinCtrlGeneric usable as wxDVC editor control.
[wxWidgets.git] / src / common / persist.cpp
index 80df492e5e85c92ea267cb71d62af577b030b97a..7f8898f3274c98e119621dc8d5ef61727bbfd075 100644 (file)
@@ -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 <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
+
+#endif // wxUSE_CONFIG