#include "wx/xti.h"
#include "wx/xml/xml.h"
#include "wx/tokenzr.h"
+#include "wx/range.h"
+
#include <string.h>
#include "wx/beforestd.h"
s = wxString::Format(_T("%ld"), data );
}
+#ifdef wxLongLong_t
+template<> void wxStringReadValue(const wxString &s, wxLongLong_t &data )
+{
+ wxSscanf(s, _T("%lld"), &data );
+}
+
+template<> void wxStringWriteValue(wxString &s, const wxLongLong_t &data )
+{
+ s = wxString::Format(_T("%lld"), data );
+}
+
+template<> void wxStringReadValue(const wxString &s, wxULongLong_t &data )
+{
+ wxSscanf(s, _T("%lld"), &data );
+}
+
+template<> void wxStringWriteValue(wxString &s, const wxULongLong_t &data )
+{
+ s = wxString::Format(_T("%lld"), data );
+}
+#endif
// float
template<> void wxStringReadValue(const wxString &s, float &data )
&wxFromStringConverter<type>, typeid(type).name());
#else
#define wxBUILTIN_TYPE_INFO( element, type ) \
- void _toString##element( const wxVariantBase& data, wxString &result ) \
+ void _toString##element( const wxAny& data, wxString &result ) \
{ wxToStringConverter<type, data, result); } \
- void _fromString##element( const wxString& data, wxVariantBase &result ) \
+ void _fromString##element( const wxString& data, wxAny &result ) \
{ wxFromStringConverter<type, data, result); } \
wxBuiltInTypeInfo s_typeInfo##type(element, &_toString##element, \
&_fromString##element, typeid(type).name());
wxBUILTIN_TYPE_INFO( wxT_DOUBLE, double);
wxBUILTIN_TYPE_INFO( wxT_STRING, wxString);
+#ifdef wxLongLong_t
+wxBUILTIN_TYPE_INFO(wxT_LONGLONG, wxLongLong_t)
+wxBUILTIN_TYPE_INFO(wxT_ULONGLONG, wxULongLong_t)
+#endif
// this are compiler induced specialization which are never used anywhere
wxILLEGAL_TYPE_SPECIALIZATION( long * )
wxILLEGAL_TYPE_SPECIALIZATION( wxString * )
+// wxRange
+
+template<> void wxStringReadValue(const wxString &s , wxRange &data)
+{
+ int minValue, maxValue;
+ wxSscanf(s, wxT("%d,%d"), &minValue , &maxValue);
+ data = wxRange(minValue, maxValue);
+}
+
+template<> void wxStringWriteValue(wxString &s , const wxRange &data)
+{
+ s = wxString::Format(wxT("%d,%d"), data.GetMin() , data.GetMax());
+}
+
+wxCUSTOM_TYPE_INFO(wxRange, wxToStringConverter<wxRange> , wxFromStringConverter<wxRange>)
+
+// other types
+
wxCOLLECTION_TYPE_INFO( wxString, wxArrayString );
template<> void wxCollectionToVariantArray( wxArrayString const &theArray,
- wxVariantBaseArray &value)
+ wxAnyList &value)
{
wxArrayCollectionToVariantArray( theArray, value );
}
wxTypeInfoMap *wxTypeInfo::ms_typeTable = NULL;
-wxTypeInfo *wxTypeInfo::FindType(const wxChar *typeName)
+wxTypeInfo *wxTypeInfo::FindType(const wxString& typeName)
{
wxTypeInfoMap::iterator iter = ms_typeTable->find(typeName);
- //wxASSERT_MSG( iter != ms_typeTable->end(),
- // wxT("lookup for a non-existent type-info") );
- // FM 3/6/2007 - disabled because otherwise
- // wxPropertyInfo::GetCollectionElementTypeInfo
- // may easily crash
if (iter == ms_typeTable->end())
return NULL;
return (wxTypeInfo *)iter->second;
}
-#if wxUSE_UNICODE
-wxClassTypeInfo::wxClassTypeInfo( wxTypeKind kind, wxClassInfo* classInfo,
- wxVariant2StringFnc to,
- wxString2VariantFnc from,
- const char *name) :
- wxTypeInfo( kind, to, from, name)
-{
- wxASSERT_MSG( kind == wxT_OBJECT_PTR ||
- kind == wxT_OBJECT,
- wxT("Illegal Kind for Enum Type")); m_classInfo = classInfo;
-}
-#endif
-
wxClassTypeInfo::wxClassTypeInfo( wxTypeKind kind, wxClassInfo* classInfo,
wxVariant2StringFnc to,
wxString2VariantFnc from,
info = info->m_next;
}
}
+
}
// ----------------------------------------------------------------------------
// wxClassInfo
// ----------------------------------------------------------------------------
-bool wxClassInfo::Create(wxObject *object, int ParamCount, wxVariantBase *Params) const
+bool wxClassInfo::Create(wxObject *object, int ParamCount, wxAny *Params) const
{
if ( ParamCount != m_constructorPropertiesCount )
{
return m_constructor->Create( object, Params );
}
-wxObject *wxClassInfo::ConstructObject(int ParamCount, wxVariantBase *Params) const
+wxObject *wxClassInfo::ConstructObject(int ParamCount, wxAny *Params) const
{
if ( ParamCount != m_constructorPropertiesCount )
{
wxPropertyInfo *wxClassInfo::FindPropertyInfoInThisClass (const wxChar *PropertyName) const
{
- wxPropertyInfo* info = m_firstProperty;
+ wxPropertyInfo* info = GetFirstProperty();
while( info )
{
wxHandlerInfo *wxClassInfo::FindHandlerInfoInThisClass (const wxChar *PropertyName) const
{
- wxHandlerInfo* info = m_firstHandler;
+ wxHandlerInfo* info = GetFirstHandler();
while( info )
{
}
bool wxClassInfo::BeforeWriteObject( const wxObject *obj, wxObjectWriter *streamer,
- wxObjectReaderCallback *persister, wxVariantBaseArray &metadata) const
+ wxObjectWriterCallback *writercallback, const wxStringToAnyHashMap &metadata) const
{
wxObjectStreamingCallback sb = GetStreamingCallback();
if ( sb )
- return (*sb)(obj, streamer, persister, metadata );
+ return (*sb)(obj, streamer, writercallback, metadata );
return true;
}
void wxClassInfo::SetProperty(wxObject *object, const wxChar *propertyName,
- const wxVariantBase &value) const
+ const wxAny &value) const
{
const wxPropertyAccessor *accessor;
accessor->SetProperty( object, value );
}
-wxVariantBase wxClassInfo::GetProperty(wxObject *object, const wxChar *propertyName) const
+wxAny wxClassInfo::GetProperty(wxObject *object, const wxChar *propertyName) const
{
const wxPropertyAccessor *accessor;
accessor = FindAccessor(propertyName);
wxASSERT(accessor->HasGetter());
- wxVariantBase result;
+ wxAny result;
accessor->GetProperty(object,result);
return result;
}
-wxVariantBaseArray wxClassInfo::GetPropertyCollection(wxObject *object,
+wxAnyList wxClassInfo::GetPropertyCollection(wxObject *object,
const wxChar *propertyName) const
{
const wxPropertyAccessor *accessor;
accessor = FindAccessor(propertyName);
wxASSERT(accessor->HasGetter());
- wxVariantBaseArray result;
+ wxAnyList result;
accessor->GetPropertyCollection(object,result);
return result;
}
void wxClassInfo::AddToPropertyCollection(wxObject *object, const wxChar *propertyName,
- const wxVariantBase& value) const
+ const wxAny& value) const
{
const wxPropertyAccessor *accessor;
}
}
+wxObject* wxClassInfo::AnyToObjectPtr( const wxAny &data) const
+{
+ return m_variantOfPtrToObjectConverter(data);
+}
+
+void wxClassInfo::CallOnAny( const wxAny &data, wxObjectFunctor* functor ) const
+{
+ if ( data.GetTypeInfo()->GetKind() == wxT_OBJECT )
+ return m_variantToObjectConverter(data, functor);
+ else
+ return (*functor)(m_variantOfPtrToObjectConverter(data));
+}
+
+wxAny wxClassInfo::ObjectPtrToAny( wxObject* obj) const
+{
+ return m_objectToVariantConverter(obj);
+}
+
+bool wxClassInfo::NeedsDirectConstruction() const
+{
+ return wx_dynamic_cast(wxObjectAllocator*, m_constructor) != NULL;
+}
// ----------------------------------------------------------------------------
// wxDynamicObject support
{
wxDynamicObjectInternal() {}
-#if wxUSE_UNICODE
- map<wstring,wxVariantBase> m_properties;
-#else
- map<string,wxVariantBase> m_properties;
-#endif
+ wxStringToAnyHashMap m_properties;
};
typedef list< wxDynamicObject* > wxDynamicObjectList;
delete m_superClassInstance;
}
-void wxDynamicObject::SetProperty (const wxChar *propertyName, const wxVariantBase &value)
+void wxDynamicObject::SetProperty (const wxChar *propertyName, const wxAny &value)
{
wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(propertyName),
wxT("Accessing Unknown Property in a Dynamic Object") );
m_data->m_properties[propertyName] = value;
}
-wxVariantBase wxDynamicObject::GetProperty (const wxChar *propertyName) const
+wxAny wxDynamicObject::GetProperty (const wxChar *propertyName) const
{
wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(propertyName),
wxT("Accessing Unknown Property in a Dynamic Object") );
wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(oldPropertyName),
wxT("Renaming Unknown Property in a Dynamic Object") );
- wxVariantBase value = m_data->m_properties[oldPropertyName];
+ wxAny value = m_data->m_properties[oldPropertyName];
m_data->m_properties.erase( oldPropertyName );
m_data->m_properties[newPropertyName] = value;
}
return obj;
}
-bool wxDynamicClassInfo::Create (wxObject *object, int paramCount, wxVariantBase *params) const
+bool wxDynamicClassInfo::Create (wxObject *object, int paramCount, wxAny *params) const
{
wxDynamicObject *dynobj = wx_dynamic_cast( wxDynamicObject *, object );
wxASSERT_MSG( dynobj,
return GetParents()[0]->GetCreateParamName( i );
}
-void wxDynamicClassInfo::SetProperty(wxObject *object, const wxChar *propertyName, const wxVariantBase &value) const
+void wxDynamicClassInfo::SetProperty(wxObject *object, const wxChar *propertyName, const wxAny &value) const
{
wxDynamicObject* dynobj = wx_dynamic_cast(wxDynamicObject*, object);
wxASSERT_MSG( dynobj, wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") );
GetParents()[0]->SetProperty( dynobj->GetSuperClassInstance(), propertyName, value );
}
-wxVariantBase wxDynamicClassInfo::GetProperty(wxObject *object, const wxChar *propertyName) const
+wxAny wxDynamicClassInfo::GetProperty(wxObject *object, const wxChar *propertyName) const
{
wxDynamicObject* dynobj = wx_dynamic_cast(wxDynamicObject*, object);
wxASSERT_MSG( dynobj, wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") );
void wxDynamicClassInfo::AddProperty( const wxChar *propertyName, const wxTypeInfo* typeInfo )
{
- new wxPropertyInfo( m_firstProperty, this, propertyName, typeInfo->GetTypeName(), new wxGenericPropertyAccessor( propertyName ), wxVariantBase() );
+ EnsureInfosInited();
+ new wxPropertyInfo( m_firstProperty, this, propertyName, typeInfo->GetTypeName(), new wxGenericPropertyAccessor( propertyName ), wxAny() );
}
void wxDynamicClassInfo::AddHandler( const wxChar *handlerName, wxObjectEventFunction address, const wxClassInfo* eventClassInfo )
{
+ EnsureInfosInited();
new wxHandlerInfo( m_firstHandler, this, handlerName, address, eventClassInfo );
}
delete m_data;
}
-void wxGenericPropertyAccessor::SetProperty(wxObject *object, const wxVariantBase &value) const
+void wxGenericPropertyAccessor::SetProperty(wxObject *object, const wxAny &value) const
{
wxDynamicObject* dynobj = wx_dynamic_cast(wxDynamicObject*, object);
wxASSERT_MSG( dynobj, wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") );
- dynobj->SetProperty(m_propertyName, value );
+ dynobj->SetProperty(m_propertyName.c_str(), value );
}
-void wxGenericPropertyAccessor::GetProperty(const wxObject *object, wxVariantBase& value) const
+void wxGenericPropertyAccessor::GetProperty(const wxObject *object, wxAny& value) const
{
const wxDynamicObject* dynobj = wx_dynamic_cast( const wxDynamicObject * , object );
wxASSERT_MSG( dynobj, wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") );
- value = dynobj->GetProperty( m_propertyName );
+ value = dynobj->GetProperty( m_propertyName.c_str() );
}
+// ----------------------------------------------------------------------------
+// wxGenericPropertyAccessor
+// ----------------------------------------------------------------------------
+
+wxString wxAnyGetAsString( const wxAny& data)
+{
+ if ( data.IsNull() || data.GetTypeInfo()==NULL )
+ return wxEmptyString;
+
+ wxString s;
+ data.GetTypeInfo()->ConvertToString(data,s);
+ return s;
+}
+
+const wxObject* wxAnyGetAsObjectPtr( const wxAny& data)
+{
+ if ( !data.IsNull() )
+ {
+ const wxClassTypeInfo* ti = wx_dynamic_cast(const wxClassTypeInfo*, data.GetTypeInfo());
+ if( ti )
+ return ti->GetClassInfo()->AnyToObjectPtr(data);
+ }
+ return NULL;
+}
+
+wxObjectFunctor::~wxObjectFunctor()
+{};
+
#endif // wxUSE_EXTENDED_RTTI