+// wxConfigBase
+// ----------------------------------------------------------------------------
+
+// Not all args will always be used by derived classes, but including them all
+// in each class ensures compatibility.
+wxConfigBase::wxConfigBase(const wxString& appName,
+ const wxString& vendorName,
+ const wxString& WXUNUSED(localFilename),
+ const wxString& WXUNUSED(globalFilename),
+ long style)
+ : m_appName(appName), m_vendorName(vendorName), m_style(style)
+{
+ m_bExpandEnvVars = TRUE; m_bRecordDefaults = FALSE;
+}
+
+wxConfigBase::~wxConfigBase()
+{
+}
+
+wxConfigBase *wxConfigBase::Set(wxConfigBase *pConfig)
+{
+ wxConfigBase *pOld = ms_pConfig;
+ ms_pConfig = pConfig;
+ return pOld;
+}
+
+wxConfigBase *wxConfigBase::Create()
+{
+ if ( ms_bAutoCreate && ms_pConfig == NULL ) {
+ ms_pConfig =
+ #if defined(__WXMSW__) && wxUSE_CONFIG_NATIVE
+ #ifdef __WIN32__
+ new wxRegConfig(wxTheApp->GetAppName(), wxTheApp->GetVendorName());
+ #else //WIN16
+ new wxIniConfig(wxTheApp->GetAppName(), wxTheApp->GetVendorName());
+ #endif
+ #else // either we're under Unix or wish to use files even under Windows
+ new wxFileConfig(wxTheApp->GetAppName());
+ #endif
+ }
+
+ return ms_pConfig;
+}
+
+// ----------------------------------------------------------------------------
+// wxConfigBase reading entries
+// ----------------------------------------------------------------------------
+
+// implement both Read() overloads for the given type in terms of DoRead()
+#define IMPLEMENT_READ_FOR_TYPE(name, type, deftype, extra) \
+ bool wxConfigBase::Read(const wxString& key, type *val) const \
+ { \
+ wxCHECK_MSG( val, FALSE, _T("wxConfig::Read(): NULL parameter") ); \
+ \
+ return DoRead##name(key, val); \
+ } \
+ \
+ bool wxConfigBase::Read(const wxString& key, \
+ type *val, \
+ deftype defVal) const \
+ { \
+ wxCHECK_MSG( val, FALSE, _T("wxConfig::Read(): NULL parameter") ); \
+ \
+ if ( DoRead##name(key, val) ) \
+ return TRUE; \
+ \
+ if ( IsRecordingDefaults() ) \
+ { \
+ ((wxConfigBase *)this)->DoWrite##name(key, defVal); \
+ } \
+ \
+ *val = extra(defVal); \
+ \
+ return FALSE; \
+ }
+
+
+IMPLEMENT_READ_FOR_TYPE(String, wxString, const wxString&, ExpandEnvVars)
+IMPLEMENT_READ_FOR_TYPE(Long, long, long, long)
+IMPLEMENT_READ_FOR_TYPE(Int, int, int, int)
+IMPLEMENT_READ_FOR_TYPE(Double, double, double, double)
+IMPLEMENT_READ_FOR_TYPE(Bool, bool, bool, bool)
+
+#undef IMPLEMENT_READ_FOR_TYPE
+
+// the DoReadXXX() for the other types have implementation in the base class
+// but can be overridden in the derived ones
+bool wxConfigBase::DoReadInt(const wxString& key, int *pi) const
+{
+ wxCHECK_MSG( pi, FALSE, _T("wxConfig::Read(): NULL parameter") );
+
+ long l;
+ if ( !DoReadLong(key, &l) )
+ return FALSE;
+
+ wxASSERT_MSG( l < INT_MAX, _T("overflow in wxConfig::DoReadInt") );
+
+ *pi = (int)l;
+
+ return TRUE;
+}
+
+bool wxConfigBase::DoReadBool(const wxString& key, bool* val) const
+{
+ wxCHECK_MSG( val, FALSE, _T("wxConfig::Read(): NULL parameter") );
+
+ long l;
+ if ( !DoReadLong(key, &l) )
+ return FALSE;
+
+ wxASSERT_MSG( l == 0 || l == 1, _T("bad bool value in wxConfig::DoReadInt") );
+
+ *val = l != 0;
+
+ return TRUE;
+}
+
+bool wxConfigBase::DoReadDouble(const wxString& key, double* val) const
+{
+ wxString str;
+ if ( Read(key, &str) )
+ {
+ return str.ToDouble(val);
+ }
+
+ return FALSE;
+}
+
+// string reading helper
+wxString wxConfigBase::ExpandEnvVars(const wxString& str) const
+{
+ wxString tmp; // Required for BC++
+ if (IsExpandingEnvVars())
+ tmp = wxExpandEnvVars(str);
+ else
+ tmp = str;
+ return tmp;
+}
+
+// ----------------------------------------------------------------------------
+// wxConfigBase writing