\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
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
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