X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0bf14ab8b14d3a999fe1159d2bec33740e066a53..ab7049776d45e622f621dd06216a4c1a1ad34b15:/src/common/any.cpp diff --git a/src/common/any.cpp b/src/common/any.cpp index 1049b42efa..c8681efec7 100644 --- a/src/common/any.cpp +++ b/src/common/any.cpp @@ -28,31 +28,25 @@ #include "wx/vector.h" #include "wx/module.h" #include "wx/hashmap.h" +#include "wx/hashset.h" using namespace wxPrivate; +#if wxUSE_VARIANT + //------------------------------------------------------------------------- // wxAnyValueTypeGlobals //------------------------------------------------------------------------- -#if wxUSE_VARIANT - WX_DECLARE_HASH_MAP(wxAnyValueType*, wxVariantDataFactory, wxPointerHash, wxPointerEqual, wxAnyTypeToVariantDataFactoryMap); -#endif - // -// Helper class to manage wxAnyValueType instances and and other -// related global variables (such as wxAny<->wxVariant type association). -// -// NB: We really need to have wxAnyValueType instances allocated -// in heap. They are stored as static template member variables, -// and with them we just can't be too careful (eg. not allocating -// them in heap broke the type identification in GCC). +// Helper class to manage global variables related to type conversion +// between wxAny and wxVariant. // class wxAnyValueTypeGlobals { @@ -62,19 +56,9 @@ public: } ~wxAnyValueTypeGlobals() { - #if wxUSE_VARIANT m_anyToVariant.clear(); - #endif - for ( size_t i=0; i(type_); + wxAnyTypeToVariantDataFactoryMap& anyToVariant = m_anyToVariant; wxAnyTypeToVariantDataFactoryMap::const_iterator it; it = anyToVariant.find(type); @@ -127,19 +115,14 @@ public: // Nothing found return NULL; } -#endif private: - wxVector m_valueTypes; -#if wxUSE_VARIANT wxAnyTypeToVariantDataFactoryMap m_anyToVariant; wxVector m_anyToVariantRegs; -#endif }; static wxAnyValueTypeGlobals* g_wxAnyValueTypeGlobals = NULL; -#if wxUSE_VARIANT WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImplVariantData) @@ -165,10 +148,13 @@ bool wxConvertAnyToVariant(const wxAny& any, wxVariant* variant) if ( wxANY_CHECK_TYPE(any, signed int) ) { #ifdef wxLongLong_t - wxLongLong_t ll; + wxLongLong_t ll = 0; if ( any.GetAs(&ll) ) { - if ( ll > LONG_MAX ) + // NB: Do not use LONG_MAX here. Explicitly using 32-bit + // integer constraint yields more consistent behaviour across + // builds. + if ( ll > wxINT32_MAX || ll < wxINT32_MIN ) *variant = wxLongLong(ll); else *variant = (long) wxLongLong(ll).GetLo(); @@ -191,8 +177,8 @@ bool wxConvertAnyToVariant(const wxAny& any, wxVariant* variant) wxVariantDataFactory f = g_wxAnyValueTypeGlobals->FindVariantDataFactory(any.GetType()); - wxVariantData* data; - + wxVariantData* data = NULL; + if ( f ) { data = f(any); @@ -201,7 +187,13 @@ bool wxConvertAnyToVariant(const wxAny& any, wxVariant* variant) { // Check if wxAny wrapped wxVariantData* if ( !any.GetAs(&data) ) + { + // Ok, one last chance: while unlikely, it is possible that the + // wxAny actually contains wxVariant. + if ( wxANY_CHECK_TYPE(any, wxVariant) ) + *variant = wxANY_AS(any, wxVariant); return false; + } // Wrapper's GetValue() does not increase reference // count, se have to do it before the data gets passed @@ -213,8 +205,6 @@ bool wxConvertAnyToVariant(const wxAny& any, wxVariant* variant) return true; } -#endif // wxUSE_VARIANT - // // This class is to make sure that wxAnyValueType instances // etc. get freed correctly. We must use a separate wxAnyValueTypeGlobals @@ -233,26 +223,15 @@ public: } virtual void OnExit() { - delete g_wxAnyValueTypeGlobals; - g_wxAnyValueTypeGlobals = NULL; + wxDELETE(g_wxAnyValueTypeGlobals); } private: }; IMPLEMENT_DYNAMIC_CLASS(wxAnyValueTypeGlobalsManager, wxModule) +#endif // wxUSE_VARIANT -//------------------------------------------------------------------------- -// wxAnyValueType -//------------------------------------------------------------------------- - -wxAnyValueType::wxAnyValueType() -{ - if ( !g_wxAnyValueTypeGlobals ) - g_wxAnyValueTypeGlobals = new wxAnyValueTypeGlobals(); - - g_wxAnyValueTypeGlobals->RegisterValueType(this); -} //------------------------------------------------------------------------- // Dynamic conversion member functions @@ -361,12 +340,16 @@ bool wxAnyValueTypeImplUint::ConvertValue(const wxAnyValueBuffer& src, return true; } -bool wxAnyValueTypeImplString::ConvertValue(const wxAnyValueBuffer& src, - wxAnyValueType* dstType, - wxAnyValueBuffer& dst) const +// Convert wxString to destination wxAny value type +bool wxAnyConvertString(const wxString& value, + wxAnyValueType* dstType, + wxAnyValueBuffer& dst) { - wxString value = GetValue(src); - if ( wxANY_VALUE_TYPE_CHECK_TYPE(dstType, wxAnyBaseIntType) ) + if ( wxANY_VALUE_TYPE_CHECK_TYPE(dstType, wxString) ) + { + wxAnyValueTypeImpl::SetValue(value, dst); + } + else if ( wxANY_VALUE_TYPE_CHECK_TYPE(dstType, wxAnyBaseIntType) ) { wxAnyBaseIntType value2; #ifdef wxLongLong_t @@ -398,14 +381,15 @@ bool wxAnyValueTypeImplString::ConvertValue(const wxAnyValueBuffer& src, else if ( wxANY_VALUE_TYPE_CHECK_TYPE(dstType, bool) ) { bool value2; - value.MakeLower(); - if ( value == wxS("true") || - value == wxS("yes") || - value == wxS('1') ) + wxString s(value); + s.MakeLower(); + if ( s == wxS("true") || + s == wxS("yes") || + s == wxS('1') ) value2 = true; - else if ( value == wxS("false") || - value == wxS("no") || - value == wxS('0') ) + else if ( s == wxS("false") || + s == wxS("no") || + s == wxS('0') ) value2 = false; else return false; @@ -480,11 +464,17 @@ bool wxAnyValueTypeImplDouble::ConvertValue(const wxAnyValueBuffer& src, WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImplInt) WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImplUint) -WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImplString) WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl) WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImplDouble) +WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImplwxString) +WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImplConstCharPtr) +WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImplConstWchar_tPtr) + +#if wxUSE_DATETIME WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl) +#endif // wxUSE_DATETIME + //WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl) //WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl) @@ -526,6 +516,14 @@ public: return false; } +#if wxUSE_EXTENDED_RTTI + virtual const wxTypeInfo* GetTypeInfo() const + { + wxFAIL_MSG("Null Type Info not available"); + return NULL; + } +#endif + private: }; @@ -534,4 +532,7 @@ WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl) wxAnyValueType* wxAnyNullValueType = wxAnyValueTypeImpl::GetInstance(); +#include "wx/listimpl.cpp" +WX_DEFINE_LIST(wxAnyList) + #endif // wxUSE_ANY