Add support for size_t to wxConfig
Allow writing and reading size_t values directly too, there were not previously accepted unlike all the other arithmetic types. Closes #19091.
This commit is contained in:
@@ -192,6 +192,9 @@ public:
|
|||||||
bool Read(const wxString& key, wxLongLong_t *pl, wxLongLong_t defVal) const;
|
bool Read(const wxString& key, wxLongLong_t *pl, wxLongLong_t defVal) const;
|
||||||
#endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
|
#endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
|
||||||
|
|
||||||
|
bool Read(const wxString& key, size_t* val) const;
|
||||||
|
bool Read(const wxString& key, size_t* val, size_t defVal) const;
|
||||||
|
|
||||||
#if wxUSE_BASE64
|
#if wxUSE_BASE64
|
||||||
// read a binary data block
|
// read a binary data block
|
||||||
bool Read(const wxString& key, wxMemoryBuffer* data) const
|
bool Read(const wxString& key, wxMemoryBuffer* data) const
|
||||||
|
@@ -571,7 +571,29 @@ public:
|
|||||||
@endWxPerlOnly
|
@endWxPerlOnly
|
||||||
*/
|
*/
|
||||||
bool Read(const wxString& key, wxLongLong_t* ll,
|
bool Read(const wxString& key, wxLongLong_t* ll,
|
||||||
wxLongLong_t defaultVal) const;
|
/**
|
||||||
|
Reads a size_t value, returning @true if the value was found.
|
||||||
|
If the value was not found, @a value is not changed.
|
||||||
|
|
||||||
|
@since 3.1.5
|
||||||
|
|
||||||
|
@beginWxPerlOnly
|
||||||
|
Not supported by wxPerl.
|
||||||
|
@endWxPerlOnly
|
||||||
|
*/
|
||||||
|
bool Read(const wxString& key, size_t* value) const;
|
||||||
|
/**
|
||||||
|
Reads a size_t value, returning @true if the value was found.
|
||||||
|
If the value was not found, @a defaultVal is used instead.
|
||||||
|
|
||||||
|
@since 3.1.5
|
||||||
|
|
||||||
|
@beginWxPerlOnly
|
||||||
|
Not supported by wxPerl.
|
||||||
|
@endWxPerlOnly
|
||||||
|
*/
|
||||||
|
bool Read(const wxString& key, size_t* value,
|
||||||
|
size_t defaultVal) const;
|
||||||
/**
|
/**
|
||||||
Reads a double value, returning @true if the value was found. If the
|
Reads a double value, returning @true if the value was found. If the
|
||||||
value was not found, @a d is not changed.
|
value was not found, @a d is not changed.
|
||||||
|
@@ -177,6 +177,40 @@ bool wxConfigBase::Read(const wxString& key, int *pi, int defVal) const
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// size_t is stored either as long or long long (Win64)
|
||||||
|
#if SIZEOF_SIZE_T == SIZEOF_LONG
|
||||||
|
typedef long SizeSameSizeAsSizeT;
|
||||||
|
#elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG
|
||||||
|
typedef wxLongLong_t SizeSameSizeAsSizeT;
|
||||||
|
#else
|
||||||
|
#error Unexpected sizeof(size_t)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool wxConfigBase::Read(const wxString& key, size_t* val) const
|
||||||
|
{
|
||||||
|
wxCHECK_MSG( val, false, wxT("wxConfig::Read(): NULL parameter") );
|
||||||
|
|
||||||
|
SizeSameSizeAsSizeT tmp;
|
||||||
|
if ( !Read(key, &tmp) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
*val = static_cast<size_t>(tmp);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxConfigBase::Read(const wxString& key, size_t* val, size_t defVal) const
|
||||||
|
{
|
||||||
|
wxCHECK_MSG( val, false, wxT("wxConfig::Read(): NULL parameter") );
|
||||||
|
|
||||||
|
if ( !Read(key, val) )
|
||||||
|
{
|
||||||
|
*val = defVal;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Read floats as doubles then just type cast it down.
|
// Read floats as doubles then just type cast it down.
|
||||||
bool wxConfigBase::Read(const wxString& key, float* val) const
|
bool wxConfigBase::Read(const wxString& key, float* val) const
|
||||||
{
|
{
|
||||||
|
@@ -53,6 +53,7 @@ TEST_CASE("wxConfig::ReadWriteLocal", "[config]")
|
|||||||
const wxULongLong_t uval64 = wxULL(0x9000000000000009);
|
const wxULongLong_t uval64 = wxULL(0x9000000000000009);
|
||||||
config->Write("ull", uval64);
|
config->Write("ull", uval64);
|
||||||
|
|
||||||
|
config->Write("size", size_t(UINT_MAX));
|
||||||
#ifdef wxHAS_CONFIG_TEMPLATE_RW
|
#ifdef wxHAS_CONFIG_TEMPLATE_RW
|
||||||
config->Write("color1", wxColour(11,22,33,44));
|
config->Write("color1", wxColour(11,22,33,44));
|
||||||
#endif // wxHAS_CONFIG_TEMPLATE_RW
|
#endif // wxHAS_CONFIG_TEMPLATE_RW
|
||||||
@@ -110,6 +111,10 @@ TEST_CASE("wxConfig::ReadWriteLocal", "[config]")
|
|||||||
CHECK( ll == static_cast<wxLongLong_t>(uval64) );
|
CHECK( ll == static_cast<wxLongLong_t>(uval64) );
|
||||||
CHECK( config->ReadLongLong("ull", 0) == static_cast<wxLongLong_t>(uval64) );
|
CHECK( config->ReadLongLong("ull", 0) == static_cast<wxLongLong_t>(uval64) );
|
||||||
|
|
||||||
|
size_t size;
|
||||||
|
CHECK( config->Read("size", &size) );
|
||||||
|
CHECK( size == UINT_MAX );
|
||||||
|
|
||||||
#ifdef wxHAS_CONFIG_TEMPLATE_RW
|
#ifdef wxHAS_CONFIG_TEMPLATE_RW
|
||||||
wxColour color1;
|
wxColour color1;
|
||||||
r = config->Read("color1", &color1);
|
r = config->Read("color1", &color1);
|
||||||
|
Reference in New Issue
Block a user