xti introduction
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22333 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
9a069b7279
commit
a095505c96
@ -28,6 +28,16 @@ class WXDLLIMPEXP_BASE wxObject;
|
||||
|
||||
#if wxUSE_DYNAMIC_CLASSES
|
||||
|
||||
#ifndef wxUSE_XTI
|
||||
#define wxUSE_XTI 0
|
||||
#endif
|
||||
|
||||
#if wxUSE_XTI
|
||||
|
||||
#include "wx/xti.h"
|
||||
|
||||
#else
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// conditional compilation
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -104,6 +114,7 @@ public:
|
||||
|
||||
static void CleanUpClasses();
|
||||
|
||||
|
||||
public:
|
||||
const wxChar *m_className;
|
||||
const wxChar *m_baseClassName1;
|
||||
@ -198,6 +209,9 @@ WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name);
|
||||
#define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
|
||||
#define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
|
||||
|
||||
#endif // !wxUSE_XTI
|
||||
|
||||
|
||||
// -----------------------------------
|
||||
// for pluggable classes
|
||||
// -----------------------------------
|
||||
@ -265,7 +279,6 @@ name##PluginSentinel m_pluginsentinel;
|
||||
#define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) \
|
||||
IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2)
|
||||
|
||||
|
||||
#define CLASSINFO(name) (&name::sm_class##name)
|
||||
|
||||
#else // !wxUSE_DYNAMIC_CLASSES
|
||||
@ -298,7 +311,6 @@ name##PluginSentinel m_pluginsentinel;
|
||||
|
||||
#endif // wxUSE_DYNAMIC_CLASSES
|
||||
|
||||
|
||||
#define wxIS_KIND_OF(obj, className) obj->IsKindOf(&className::sm_class##className)
|
||||
|
||||
// Just seems a bit nicer-looking (pretend it's not a macro)
|
||||
|
1110
include/wx/xti.h
Normal file
1110
include/wx/xti.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -422,6 +422,7 @@ void wxPluginLibrary::UpdateClassInfo()
|
||||
}
|
||||
}
|
||||
|
||||
#if wxUSE_XTI == 0
|
||||
for(info = m_after; info != m_before; info = info->m_next)
|
||||
{
|
||||
if( info->m_baseClassName1 )
|
||||
@ -429,6 +430,7 @@ void wxPluginLibrary::UpdateClassInfo()
|
||||
if( info->m_baseClassName2 )
|
||||
info->m_baseInfo2 = (wxClassInfo *)t->Get(info->m_baseClassName2);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void wxPluginLibrary::RestoreClassInfo()
|
||||
|
@ -51,9 +51,26 @@
|
||||
#pragma optimize("", off)
|
||||
#endif
|
||||
|
||||
#if wxUSE_XTI
|
||||
const wxClassInfo* wxObject::sm_classParentswxObject[] = { NULL } ;
|
||||
wxObject* wxVariantToObjectConverterwxObject ( const wxxVariant &data )
|
||||
{ return data.Get<wxObject*>() ; }
|
||||
wxxVariant wxObjectToVariantConverterwxObject ( wxObject *data )
|
||||
{ return wxxVariant( dynamic_cast<wxObject*> (data) ) ; }
|
||||
wxClassInfo wxObject::sm_classwxObject(sm_classParentswxObject , wxT("") , wxT("wxObject"),
|
||||
(int) sizeof(wxObject), \
|
||||
(wxObjectConstructorFn) 0 ,
|
||||
(wxPropertyInfo*) NULL,0 , 0 ,
|
||||
0 , wxVariantToObjectConverterwxObject , wxObjectToVariantConverterwxObject);
|
||||
template<> void wxStringReadValue(const wxString & , wxObject * & ){assert(0) ;}
|
||||
template<> void wxStringWriteValue(wxString & , wxObject* const & ){assert(0) ;}
|
||||
template<> const wxTypeInfo* wxGetTypeInfo( wxObject ** )
|
||||
{ static wxClassTypeInfo s_typeInfo(&wxObject::sm_classwxObject) ; return &s_typeInfo ; }
|
||||
#else
|
||||
wxClassInfo wxObject::sm_classwxObject( wxT("wxObject"), 0, 0,
|
||||
(int) sizeof(wxObject),
|
||||
(wxObjectConstructorFn) 0 );
|
||||
#endif
|
||||
|
||||
// restore optimizations
|
||||
#if defined __VISUALC__ && __VISUALC__ >= 1300
|
||||
@ -171,6 +188,9 @@ wxClassInfo::~wxClassInfo()
|
||||
info = info->m_next;
|
||||
}
|
||||
}
|
||||
#if wxUSE_XTI
|
||||
Unregister( m_className ) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
wxClassInfo *wxClassInfo::FindClass(const wxChar *className)
|
||||
@ -244,6 +264,7 @@ void wxClassInfo::InitializeClasses()
|
||||
}
|
||||
}
|
||||
|
||||
#if wxUSE_XTI == 0
|
||||
// Set base pointers for each wxClassInfo
|
||||
|
||||
for(info = sm_first; info; info = info->m_next)
|
||||
@ -251,6 +272,7 @@ void wxClassInfo::InitializeClasses()
|
||||
info->m_baseInfo1 = GetBaseByName(info->GetBaseClassName1());
|
||||
info->m_baseInfo2 = GetBaseByName(info->GetBaseClassName2());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void wxClassInfo::CleanUpClasses()
|
||||
@ -259,7 +281,6 @@ void wxClassInfo::CleanUpClasses()
|
||||
wxClassInfo::sm_classTable = NULL;
|
||||
}
|
||||
|
||||
|
||||
wxObject *wxCreateDynamicObject(const wxChar *name)
|
||||
{
|
||||
#if defined(__WXDEBUG__) || wxUSE_DEBUG_CONTEXT
|
||||
|
362
src/common/xti.cpp
Normal file
362
src/common/xti.cpp
Normal file
@ -0,0 +1,362 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/common/xti.cpp
|
||||
// Purpose: runtime metadata information (extended class info
|
||||
// Author: Stefan Csomor
|
||||
// Modified by:
|
||||
// Created: 27/07/03
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 1997 Julian Smart
|
||||
// (c) 2003 Stefan Csomor
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "xti.h"
|
||||
#endif
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/hash.h"
|
||||
#include "wx/object.h"
|
||||
#endif
|
||||
|
||||
#include "wx/xml/xml.h"
|
||||
#include "wx/tokenzr.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if wxUSE_XTI
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Enum Support
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxEnumData::wxEnumData( wxEnumMemberData* data )
|
||||
{
|
||||
m_members = data ;
|
||||
for ( m_count = 0; m_members[m_count].m_name ; m_count++)
|
||||
{} ;
|
||||
}
|
||||
|
||||
bool wxEnumData::HasEnumMemberValue(const wxChar *name, int *value)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; m_members[i].m_name ; i++ )
|
||||
{
|
||||
if (!strcmp(name, m_members[i].m_name))
|
||||
{
|
||||
if ( value )
|
||||
*value = m_members[i].m_value;
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
return false ;
|
||||
}
|
||||
|
||||
int wxEnumData::GetEnumMemberValue(const wxChar *name)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; m_members[i].m_name ; i++ )
|
||||
{
|
||||
if (!strcmp(name, m_members[i].m_name))
|
||||
{
|
||||
return m_members[i].m_value;
|
||||
}
|
||||
}
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
const wxChar *wxEnumData::GetEnumMemberName(int value)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; m_members[i].m_name ; i++)
|
||||
if (value == m_members[i].m_value)
|
||||
return m_members[i].m_name;
|
||||
|
||||
return wxT("") ;
|
||||
}
|
||||
|
||||
int wxEnumData::GetEnumMemberValueByIndex( int idx )
|
||||
{
|
||||
// we should cache the count in order to avoid out-of-bounds errors
|
||||
return m_members[idx].m_value ;
|
||||
}
|
||||
|
||||
const char * wxEnumData::GetEnumMemberNameByIndex( int idx )
|
||||
{
|
||||
// we should cache the count in order to avoid out-of-bounds errors
|
||||
return m_members[idx].m_name ;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Type Information
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
const wxTypeInfo* wxGetTypeInfo( void * )
|
||||
{
|
||||
static wxBuiltInTypeInfo s_typeInfo( wxT_VOID ) ;
|
||||
return &s_typeInfo ;
|
||||
}
|
||||
|
||||
const wxTypeInfo* wxGetTypeInfo( bool * )
|
||||
{
|
||||
static wxBuiltInTypeInfo s_typeInfo( wxT_BOOL ) ;
|
||||
return &s_typeInfo ;
|
||||
}
|
||||
|
||||
const wxTypeInfo* wxGetTypeInfo( char * )
|
||||
{
|
||||
static wxBuiltInTypeInfo s_typeInfo( wxT_CHAR ) ;
|
||||
return &s_typeInfo ;
|
||||
}
|
||||
|
||||
const wxTypeInfo* wxGetTypeInfo( unsigned char * )
|
||||
{
|
||||
static wxBuiltInTypeInfo s_typeInfo( wxT_UCHAR ) ;
|
||||
return &s_typeInfo ;
|
||||
}
|
||||
|
||||
const wxTypeInfo* wxGetTypeInfo( int * )
|
||||
{
|
||||
static wxBuiltInTypeInfo s_typeInfo( wxT_CHAR ) ;
|
||||
return &s_typeInfo ;
|
||||
}
|
||||
|
||||
const wxTypeInfo* wxGetTypeInfo( unsigned int * )
|
||||
{
|
||||
static wxBuiltInTypeInfo s_typeInfo( wxT_UCHAR ) ;
|
||||
return &s_typeInfo ;
|
||||
}
|
||||
|
||||
const wxTypeInfo* wxGetTypeInfo( long * )
|
||||
{
|
||||
static wxBuiltInTypeInfo s_typeInfo( wxT_CHAR ) ;
|
||||
return &s_typeInfo ;
|
||||
}
|
||||
|
||||
const wxTypeInfo* wxGetTypeInfo( unsigned long * )
|
||||
{
|
||||
static wxBuiltInTypeInfo s_typeInfo( wxT_UCHAR ) ;
|
||||
return &s_typeInfo ;
|
||||
}
|
||||
|
||||
const wxTypeInfo* wxGetTypeInfo( float * )
|
||||
{
|
||||
static wxBuiltInTypeInfo s_typeInfo( wxT_FLOAT ) ;
|
||||
return &s_typeInfo ;
|
||||
}
|
||||
|
||||
const wxTypeInfo* wxGetTypeInfo( double * )
|
||||
{
|
||||
static wxBuiltInTypeInfo s_typeInfo( wxT_DOUBLE ) ;
|
||||
return &s_typeInfo ;
|
||||
}
|
||||
|
||||
const wxTypeInfo* wxGetTypeInfo( wxString * )
|
||||
{
|
||||
static wxBuiltInTypeInfo s_typeInfo( wxT_STRING ) ;
|
||||
return &s_typeInfo ;
|
||||
}
|
||||
|
||||
// this is a compiler induced specialization which is never used anywhere
|
||||
// const char * should never be active
|
||||
|
||||
const wxTypeInfo* wxGetTypeInfo( char const ** )
|
||||
{
|
||||
assert(0) ;
|
||||
static wxBuiltInTypeInfo s_typeInfo( wxT_VOID ) ;
|
||||
return &s_typeInfo ;
|
||||
}
|
||||
|
||||
void wxStringReadValue(const wxString & , const char* & )
|
||||
{
|
||||
assert(0) ;
|
||||
}
|
||||
|
||||
void wxStringWriteValue(wxString & , char const * const & )
|
||||
{
|
||||
assert(0) ;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// value streaming
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// convenience function (avoids including xml headers in users code)
|
||||
|
||||
void wxXmlAddContentToNode( wxXmlNode* node , const wxString& data )
|
||||
{
|
||||
node->AddChild(new wxXmlNode(wxXML_TEXT_NODE, "value", data ) );
|
||||
}
|
||||
|
||||
wxString wxXmlGetContentFromNode( wxXmlNode *node )
|
||||
{
|
||||
return node->GetChildren()->GetContent() ;
|
||||
}
|
||||
|
||||
// streamer specializations
|
||||
|
||||
// TODO for all built-in types
|
||||
|
||||
// long
|
||||
|
||||
void wxStringReadValue(const wxString &s , long &data )
|
||||
{
|
||||
wxSscanf(s, _T("%ld"), &data ) ;
|
||||
}
|
||||
|
||||
void wxStringWriteValue(wxString &s , const long &data )
|
||||
{
|
||||
s = wxString::Format("%ld", data ) ;
|
||||
}
|
||||
|
||||
// long
|
||||
|
||||
void wxStringReadValue(const wxString &s , int &data )
|
||||
{
|
||||
wxSscanf(s, _T("%d"), &data ) ;
|
||||
}
|
||||
|
||||
void wxStringWriteValue(wxString &s , const int &data )
|
||||
{
|
||||
s = wxString::Format("%d", data ) ;
|
||||
}
|
||||
|
||||
// wxString
|
||||
|
||||
void wxStringReadValue(const wxString &s , wxString &data )
|
||||
{
|
||||
data = s ;
|
||||
}
|
||||
|
||||
void wxStringWriteValue(wxString &s , const wxString &data )
|
||||
{
|
||||
s = data ;
|
||||
}
|
||||
|
||||
/*
|
||||
Custom Data Streaming / Type Infos
|
||||
we will have to add this for all wx non object types, but it is also an example
|
||||
for custom data structures
|
||||
*/
|
||||
|
||||
// wxPoint
|
||||
|
||||
void wxStringReadValue(const wxString &s , wxPoint &data )
|
||||
{
|
||||
wxSscanf(s, _T("%d,%d"), &data.x , &data.y ) ;
|
||||
}
|
||||
|
||||
void wxStringWriteValue(wxString &s , const wxPoint &data )
|
||||
{
|
||||
s = wxString::Format("%d,%d", data.x , data.y ) ;
|
||||
}
|
||||
|
||||
WX_CUSTOM_TYPE_INFO(wxPoint)
|
||||
|
||||
// removing header dependancy on string tokenizer
|
||||
|
||||
void wxSetStringToArray( const wxString &s , wxArrayString &array )
|
||||
{
|
||||
wxStringTokenizer tokenizer(s, wxT("| \t\n"), wxTOKEN_STRTOK);
|
||||
wxString flag;
|
||||
array.Clear() ;
|
||||
while (tokenizer.HasMoreTokens())
|
||||
{
|
||||
array.Add(tokenizer.GetNextToken()) ;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxClassInfo
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
void wxClassInfo::Register(const char *WXUNUSED(name), wxClassInfo *WXUNUSED(info))
|
||||
{
|
||||
/*
|
||||
if (!ExtendedTypeMap)
|
||||
ExtendedTypeMap = new ClassMap;
|
||||
(*ExtendedTypeMap)[string(Name)] = Info;
|
||||
*/
|
||||
}
|
||||
|
||||
void wxClassInfo::Unregister(const char *WXUNUSED(name))
|
||||
{
|
||||
/*
|
||||
assert(ExtendedTypeMap);
|
||||
ExtendedTypeMap->erase(Name);
|
||||
*/
|
||||
}
|
||||
|
||||
const wxPropertyAccessor *wxClassInfo::FindAccessor(const char *PropertyName)
|
||||
{
|
||||
const wxPropertyInfo* info = FindPropInfo( PropertyName ) ;
|
||||
|
||||
if ( info )
|
||||
return info->GetAccessor() ;
|
||||
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
const wxPropertyInfo *wxClassInfo::FindPropInfo (const char *PropertyName) const
|
||||
{
|
||||
const wxPropertyInfo* info = GetFirstProperty() ;
|
||||
|
||||
while( info )
|
||||
{
|
||||
if ( strcmp( info->GetName() , PropertyName ) == 0 )
|
||||
return info ;
|
||||
info = info->GetNext() ;
|
||||
}
|
||||
|
||||
const wxClassInfo** parents = GetParents() ;
|
||||
for ( int i = 0 ; parents[i] ; ++ i )
|
||||
{
|
||||
if ( ( info = parents[i]->FindPropInfo( PropertyName ) ) != NULL )
|
||||
return info ;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void wxClassInfo::SetProperty(wxObject *object, const char *propertyName, const wxxVariant &value)
|
||||
{
|
||||
const wxPropertyAccessor *accessor;
|
||||
|
||||
accessor = FindAccessor(propertyName);
|
||||
wxASSERT(accessor->HasSetter());
|
||||
accessor->SetProperty( object , value ) ;
|
||||
}
|
||||
|
||||
wxxVariant wxClassInfo::GetProperty(wxObject *object, const char *propertyName)
|
||||
{
|
||||
const wxPropertyAccessor *accessor;
|
||||
|
||||
accessor = FindAccessor(propertyName);
|
||||
wxASSERT(accessor->HasGetter());
|
||||
return accessor->GetProperty(object);
|
||||
}
|
||||
|
||||
/*
|
||||
VARIANT TO OBJECT
|
||||
*/
|
||||
|
||||
wxObject* wxxVariant::GetAsObject() const
|
||||
{
|
||||
const wxClassTypeInfo *ti = dynamic_cast<const wxClassTypeInfo*>( m_data->GetTypeInfo() ) ;
|
||||
if ( ti )
|
||||
return ti->GetClassInfo()->VariantToInstance(*this) ;
|
||||
else
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user