]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/persist.cpp
No changes, just a typo fix in wxRichTextCtrl UI code.
[wxWidgets.git] / src / common / persist.cpp
index 80df492e5e85c92ea267cb71d62af577b030b97a..4ca337cc0ccba07f770e8e749f32868f95747875 100644 (file)
     #pragma hdrstop
 #endif
 
+#if wxUSE_CONFIG
+
 #ifndef WX_PRECOMP
 #endif // WX_PRECOMP
 
 #include "wx/persist.h"
 
+namespace
+{
+
+wxPersistenceManager* gs_manager = NULL;
+
+} // anonymous namespace
+
 // ============================================================================
 // wxPersistenceManager implementation
 // ============================================================================
 
+/* static */
+void wxPersistenceManager::Set(wxPersistenceManager& manager)
+{
+    gs_manager = &manager;
+}
+
 /* static */
 wxPersistenceManager& wxPersistenceManager::Get()
 {
-    static wxPersistenceManager s_manager;
+    if ( !gs_manager )
+    {
+        static wxPersistenceManager s_manager;
 
-    return s_manager;
+        gs_manager = &s_manager;
+    }
+
+    return *gs_manager;
+}
+
+wxPersistenceManager::~wxPersistenceManager()
+{
 }
 
 wxString
@@ -107,3 +131,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