Add wxHAS_CONFIG_AS_{REG,FILE}CONFIG symbols

Sometimes it's useful to have some code used only if wxConfig is defined
as wxRegConfig or only if it is defined as wxFileConfig and testing for
these symbols is more clear than testing for the platform (and more
correct, considering that setting wxUSE_CONFIG_NATIVE to 0 may result in
wxFileConfig being used even under Windows).
This commit is contained in:
Vadim Zeitlin 2024-01-04 02:53:23 +01:00
parent 055c4cbed5
commit ebe0847932
4 changed files with 16 additions and 7 deletions

View file

@ -168,6 +168,10 @@ Currently the following symbols exist:
implemented in a generic way, using a critical section.}
@itemdef{wxHAS_BITMAPTOGGLEBUTTON, Defined in @c wx/tglbtn.h if
wxBitmapToggleButton class is available in addition to wxToggleButton.}
@itemdef{wxHAS_CONFIG_AS_FILECONFIG, Defined if wxConfig is defined as
wxFileConfig. This constant is available since wxWidgets 3.3.0.}
@itemdef{wxHAS_CONFIG_AS_REGCONFIG, Defined if wxConfig is defined as
wxRegConfig. This constant is available since wxWidgets 3.3.0.}
@itemdef{wxHAS_CONFIG_TEMPLATE_RW, Defined if the currently used compiler
supports template Read() and Write() methods in wxConfig.}
@itemdef{wxHAS_DEPRECATED_ATTR, Defined if C++14 @c [[deprecated]] attribute is

View file

@ -23,9 +23,11 @@
#if defined(__WINDOWS__) && wxUSE_CONFIG_NATIVE
#include "wx/msw/regconf.h"
#define wxConfig wxRegConfig
#define wxHAS_CONFIG_AS_REGCONFIG
#else // either we're under Unix or wish to always use config files
#include "wx/fileconf.h"
#define wxConfig wxFileConfig
#define wxHAS_CONFIG_AS_FILECONFIG
#endif
#endif // wxUSE_CONFIG

View file

@ -57,7 +57,9 @@ enum
with the registry under Windows or text-based config files under Unix.
To make writing the portable code even easier, wxWidgets provides a typedef
wxConfig which is mapped onto the native wxConfigBase implementation on the
given platform: i.e. wxRegConfig under Windows and wxFileConfig otherwise.
given platform: i.e. wxRegConfig under Windows (in this case
`wxHAS_CONFIG_AS_REGCONFIG` preprocessor symbol is defined) and
wxFileConfig otherwise (in this case `wxHAS_CONFIG_AS_FILECONFIG` is).
See @ref overview_config for a description of all features of this class.

View file

@ -56,12 +56,13 @@ bool wxConfigBase::ms_bAutoCreate = true;
wxConfigBase *wxAppTraitsBase::CreateConfig()
{
return new
#if defined(__WINDOWS__) && wxUSE_CONFIG_NATIVE
wxRegConfig(wxTheApp->GetAppName(), wxTheApp->GetVendorName());
#else // either we're under Unix or wish to use files even under Windows
wxFileConfig(wxTheApp->GetAppName());
#endif
#if defined(wxHAS_CONFIG_AS_REGCONFIG)
return new wxRegConfig(wxTheApp->GetAppName(), wxTheApp->GetVendorName());
#elif defined(wxHAS_CONFIG_AS_FILECONFIG)
return new wxFileConfig(wxTheApp->GetAppName());
#else
#error No wxConfig implementation defined.
#endif
}
// ----------------------------------------------------------------------------