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
This commit is contained in:
Vadim Zeitlin 2009-01-31 22:47:28 +00:00
parent 5c6aad4737
commit c7c8fac6f8
2 changed files with 62 additions and 25 deletions

View File

@ -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 <typename T>
bool
SaveValue(const wxPersistentObject& who, const wxString& name, T value)
{
wxConfigBase * const conf = GetConfig();
if ( !conf )
return false;
// 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)
return conf->Write(GetKey(who, name), 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);
template <typename T>
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);
}
#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;

View 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