redistribution of code for different library parts

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23142 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2003-08-23 19:40:04 +00:00
parent 9d5f4fbbd4
commit 9c8046dded
7 changed files with 727 additions and 552 deletions

View File

@@ -16,101 +16,147 @@
#pragma interface "flags.h"
#endif
#include <bitset>
// wxFlags should be applied to an enum, then this can be used like
// bitwise operators but keeps the type safety and information, the
// enums must be in a sequence , their value determines the bit position
// that they represent
// The api is made as close as possible to <bitset>
template <class T> class wxFlags
{
friend class wxEnumData ;
public:
wxFlags(long val) { m_data = val ; }
// creates a wxFlags<> object with all flags initialized to 0
wxFlags() { m_data = 0; }
// created a wxFlags<> object initialized according to the bits of the
// integral value val
wxFlags(unsigned long val) { m_data = val ; }
// copies the content in the new wxFlags<> object from another one
wxFlags(const wxFlags &src) { m_data = src.m_data; }
// creates a wxFlags<> object that has the specific flag set
wxFlags(const T el) { m_data |= 1 << el; }
operator long() const { return m_data ; }
// returns the integral value that the bits of this object represent
unsigned long to_ulong() const { return m_data ; }
// assignment
wxFlags &operator =(const wxFlags &rhs)
{
m_data = rhs.m_data;
return *this;
}
wxFlags &operator +=(const wxFlags &rhs) // union
// bitwise or operator, sets all bits that are in rhs and leaves
// the rest unchanged
wxFlags &operator |=(const wxFlags &rhs)
{
m_data |= rhs.m_data;
return *this;
}
wxFlags &operator -=(const wxFlags &rhs) // difference
// bitwsie exclusive-or operator, toggles the value of all bits
// that are set in bits and leaves all others unchanged
wxFlags &operator ^=(const wxFlags &rhs) // difference
{
m_data ^= rhs.m_data;
return *this;
}
wxFlags &operator *=(const wxFlags &rhs) // intersection
// bitwise and operator, resets all bits that are not in rhs and leaves
// all others unchanged
wxFlags &operator &=(const wxFlags &rhs) // intersection
{
m_data &= rhs.m_data;
return *this;
}
wxFlags operator +(const wxFlags &rhs) const // union
// bitwise or operator, returns a new bitset that has all bits set that set are in
// bitset2 or in this bitset
wxFlags operator |(const wxFlags &bitset2) const // union
{
wxFlags<T> s;
s.m_data = m_data | rhs.m_data;
return s;
}
wxFlags operator -(const wxFlags &rhs) const // difference
{
wxFlags<T> s;
s.m_data = m_data ^ rhs.m_data;
return s;
}
wxFlags operator *(const wxFlags &rhs) const // intersection
{
wxFlags<T> s;
s.m_data = m_data & rhs.m_data;
s.m_data = m_data | bitset2.m_data;
return s;
}
wxFlags& Set(const T el) //Add element
// bitwise exclusive-or operator, returns a new bitset that has all bits set that are set either in
// bitset2 or in this bitset but not in both
wxFlags operator ^(const wxFlags &bitset2) const // difference
{
wxFlags<T> s;
s.m_data = m_data ^ bitset2.m_data;
return s;
}
// bitwise and operator, returns a new bitset that has all bits set that are set both in
// bitset2 and in this bitset
wxFlags operator &(const wxFlags &bitset2) const // intersection
{
wxFlags<T> s;
s.m_data = m_data & bitset2.m_data;
return s;
}
// sets appropriate the bit to true
wxFlags& set(const T el) //Add element
{
m_data |= 1 << el;
return *this;
}
wxFlags& Clear(const T el) //remove element
// clears the appropriate flag to false
wxFlags& reset(const T el) //remove element
{
m_data &= ~(1 << el);
return *this;
}
bool Contains(const T el) const
{
return (m_data & (1 << el)) ? true : false;
}
wxFlags &Clear()
// clear all flags
wxFlags& reset()
{
m_data = 0;
return *this;
}
bool Empty() const
// true if this flag is set
bool test(const T el) const
{
return (m_data & (1 << el)) ? true : false;
}
// true if no flag is set
bool none() const
{
return m_data == 0;
}
// true if any flag is set
bool any() const
{
return m_data != 0;
}
// true if both have the same flags
bool operator ==(const wxFlags &rhs) const
{
return m_data == rhs.m_data;
}
// true if both differ in their flags set
bool operator !=(const wxFlags &rhs) const
{
return !operator==(rhs);
}
bool operator[] (const T el) const { return test(el) ; }
private :
int m_data;
unsigned long m_data;
};

View File

@@ -167,7 +167,7 @@ template<typename e>
void wxSetFromString(const wxString &s , wxFlags<e> &data )
{
wxEnumData* edata = wxGetEnumData((e) 0) ;
data.Clear() ;
data.reset() ;
wxArrayString array ;
wxSetStringToArray( s , array ) ;
@@ -178,7 +178,7 @@ void wxSetFromString(const wxString &s , wxFlags<e> &data )
int ivalue ;
if ( edata->HasEnumMemberValue( flag , &ivalue ) )
{
data.Set( (e) ivalue ) ;
data.set( (e) ivalue ) ;
}
}
}
@@ -193,7 +193,7 @@ void wxSetToString( wxString &s , const wxFlags<e> &data )
for ( i = 0 ; i < count ; i++ )
{
e value = (e) edata->GetEnumMemberValueByIndex(i) ;
if ( data.Contains( value ) )
if ( data.test( value ) )
{
// this could also be done by the templated calls
if ( !s.IsEmpty() )
@@ -215,8 +215,8 @@ void wxSetToString( wxString &s , const wxFlags<e> &data )
{ \
wxSetToString( s , data ) ; \
} \
void FromLong##SetName( long data , wxxVariant& result ) { result = wxxVariant(SetName(data)) ;} \
void ToLong##SetName( const wxxVariant& data , long &result ) { result = (long) data.Get<SetName>() ;} \
void FromLong##SetName( long data , wxxVariant& result ) { result = wxxVariant(SetName((unsigned long)data)) ;} \
void ToLong##SetName( const wxxVariant& data , long &result ) { result = (long) data.Get<SetName>().to_ulong() ;} \
template<> const wxTypeInfo* wxGetTypeInfo( SetName * ) \
{ \
static wxEnumTypeInfo s_typeInfo(wxT_SET , &s_enumData##e , &wxToStringConverter<SetName> , &wxFromStringConverter<SetName> , &ToLong##SetName , &FromLong##SetName, #SetName ) ; return &s_typeInfo ; \
@@ -749,6 +749,8 @@ enum {
wxPROP_OBJECT_GRAPH = 0x00000002 ,
// this will only be streamed out and in as enum/set, the internal representation is still a long
wxPROP_ENUM_STORE_LONG = 0x00000004 ,
// don't stream out this property, needed eg to avoid streaming out children that are always created by their parents
wxPROP_DONT_STREAM = 0x00000008 ,
} ;
class WXDLLIMPEXP_BASE wxPropertyInfo
@@ -838,7 +840,8 @@ WX_DECLARE_EXPORTED_STRING_HASH_MAP( wxPropertyInfo* , wxPropertyInfoMap ) ;
#define WX_END_PROPERTIES_TABLE() \
return first ; }
#define WX_HIDE_PROPERTY( name ) \
static wxPropertyInfo _propertyInfo##name( first , class_t::GetClassInfoStatic() , #name , wxGetTypeInfo( (void*) NULL ) ,NULL , wxxVariant() , wxPROP_DONT_STREAM , wxEmptyString , wxEmptyString ) ;
#define WX_PROPERTY( name , type , setter , getter ,defaultValue , flags , help , group) \
WX_SETTER( name , class_t , type , setter ) \
@@ -1192,6 +1195,9 @@ struct wxConstructorBridge_8 : public wxConstructorBridge
typedef wxObject *(*wxObjectConstructorFn)(void);
typedef wxObject* (*wxVariantToObjectConverter)( wxxVariant &data ) ;
typedef wxxVariant (*wxObjectToVariantConverter)( wxObject* ) ;
class wxWriter ;
class wxPersister ;
typedef bool (*wxObjectStreamingCallback) ( const wxObject *, wxWriter * , wxPersister * , wxxVariantArray & ) ;
class WXDLLIMPEXP_BASE wxClassInfo
{
@@ -1208,11 +1214,13 @@ public:
const int _ConstructorPropertiesCount ,
wxVariantToObjectConverter _PtrConverter1 ,
wxVariantToObjectConverter _Converter2 ,
wxObjectToVariantConverter _Converter3
wxObjectToVariantConverter _Converter3 ,
wxObjectStreamingCallback _streamingCallback = NULL
) : m_parents(_Parents) , m_unitName(_UnitName) ,m_className(_ClassName),
m_objectSize(size), m_objectConstructor(ctor) , m_firstProperty(_Props ) , m_firstHandler(_Handlers ) , m_constructor( _Constructor ) ,
m_constructorProperties(_ConstructorProperties) , m_constructorPropertiesCount(_ConstructorPropertiesCount),
m_variantOfPtrToObjectConverter( _PtrConverter1 ) , m_variantToObjectConverter( _Converter2 ) , m_objectToVariantConverter( _Converter3 ) , m_next(sm_first)
m_variantOfPtrToObjectConverter( _PtrConverter1 ) , m_variantToObjectConverter( _Converter2 ) , m_objectToVariantConverter( _Converter3 ) ,
m_next(sm_first) , m_streamingCallback( _streamingCallback )
{
sm_first = this;
Register() ;
@@ -1221,7 +1229,8 @@ public:
wxClassInfo(const wxChar *_UnitName, const wxChar *_ClassName, const wxClassInfo **_Parents) : m_parents(_Parents) , m_unitName(_UnitName) ,m_className(_ClassName),
m_objectSize(0), m_objectConstructor(NULL) , m_firstProperty(NULL ) , m_firstHandler(NULL ) , m_constructor( NULL ) ,
m_constructorProperties(NULL) , m_constructorPropertiesCount(NULL),
m_variantOfPtrToObjectConverter( NULL ) , m_variantToObjectConverter( NULL ) , m_objectToVariantConverter( NULL ) , m_next(sm_first)
m_variantOfPtrToObjectConverter( NULL ) , m_variantToObjectConverter( NULL ) , m_objectToVariantConverter( NULL ) , m_next(sm_first) ,
m_streamingCallback( NULL )
{
sm_first = this;
Register() ;
@@ -1237,6 +1246,7 @@ public:
wxObject *CreateObject() const { return AllocateObject() ; }
const wxChar *GetClassName() const { return m_className; }
const wxChar *GetIncludeName() const { return m_unitName ; }
const wxClassInfo **GetParents() const { return m_parents; }
int GetSize() const { return m_objectSize; }
@@ -1264,6 +1274,15 @@ public:
return false ;
}
// if there is a callback registered with that class it will be called before this
// object will be written to disk, it can veto streaming out this object by returning
// false, if this class has not registered a callback, the search will go up the inheritance tree
// if no callback has been registered true will be returned by default
bool BeforeWriteObject( const wxObject *obj, wxWriter *streamer , wxPersister *persister , wxxVariantArray &metadata) const ;
// gets the streaming callback from this class or any superclass
wxObjectStreamingCallback GetStreamingCallback() const ;
#ifdef WXWIN_COMPATIBILITY_2_4
// Initializes parent pointers and hash table for fast searching.
wxDEPRECATED( static void InitializeClasses() );
@@ -1353,7 +1372,7 @@ private:
wxVariantToObjectConverter m_variantOfPtrToObjectConverter ;
wxVariantToObjectConverter m_variantToObjectConverter ;
wxObjectToVariantConverter m_objectToVariantConverter ;
wxObjectStreamingCallback m_streamingCallback ;
const wxPropertyAccessor *FindAccessor (const wxChar *propertyName) const ;
@@ -1441,7 +1460,7 @@ public :
// Single inheritance with one base class
#define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit) \
#define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit , callback) \
wxObject* wxConstructorFor##name() \
{ return new name; } \
const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
@@ -1451,7 +1470,7 @@ public :
(int) sizeof(name), \
(wxObjectConstructorFn) wxConstructorFor##name , \
name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name); \
name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , NULL , wxObjectToVariantConverter##name , callback); \
template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
@@ -1462,7 +1481,7 @@ public :
template<> const wxTypeInfo* wxGetTypeInfo( name * ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &name::sm_class##name) ; return &s_typeInfo ; } \
template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
#define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit) \
#define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit, callback ) \
wxObject* wxConstructorFor##name() \
{ return new name; } \
const wxClassInfo* name::sm_classParents##name[] = { &basename::sm_class##basename ,NULL } ; \
@@ -1473,7 +1492,7 @@ public :
(int) sizeof(name), \
(wxObjectConstructorFn) wxConstructorFor##name , \
name::GetPropertiesStatic(),name::GetHandlersStatic(),name::sm_constructor##name , name::sm_constructorProperties##name , \
name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name); \
name::sm_constructorPropertiesCount##name , wxVariantOfPtrToObjectConverter##name , wxVariantToObjectConverter##name , wxObjectToVariantConverter##name, callback); \
template<> void wxStringReadValue(const wxString & , name & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
template<> void wxStringWriteValue(wxString & , name const & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") );}\
template<> void wxStringReadValue(const wxString & , name * & ){wxASSERT_MSG( 0 , wxT("Illegal Spezialication Called") ) ;}\
@@ -1485,22 +1504,25 @@ public :
template<> const wxTypeInfo* wxGetTypeInfo( name ** ){ static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &name::sm_class##name) ; return &s_typeInfo ; }
#define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename ) \
_IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , "" ) \
_IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , "" , NULL ) \
const wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
const wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
WX_CONSTRUCTOR_DUMMY( name )
#define IMPLEMENT_DYNAMIC_CLASS( name , basename ) \
_IMPLEMENT_DYNAMIC_CLASS( name , basename , "" ) \
_IMPLEMENT_DYNAMIC_CLASS( name , basename , "" , NULL ) \
wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL ; } \
wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL ; } \
WX_CONSTRUCTOR_DUMMY( name )
#define IMPLEMENT_DYNAMIC_CLASS_XTI( name , basename , unit ) \
_IMPLEMENT_DYNAMIC_CLASS( name , basename , unit )
_IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , NULL )
#define IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name , basename , unit , callback ) \
_IMPLEMENT_DYNAMIC_CLASS( name , basename , unit , &callback )
#define IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name , basename , unit ) \
_IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit )
_IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name , basename , unit , NULL )
// this is for classes that do not derive from wxobject, there are no creators for these

View File

@@ -144,64 +144,9 @@ private :
void WriteAllProperties( const wxObject * obj , const wxClassInfo* ci , wxPersister *persister, wxWriterInternalPropertiesData * data ) ;
void WriteOneProperty( const wxObject *obj , const wxClassInfo* ci , const wxPropertyInfo* pi , wxPersister *persister , wxWriterInternalPropertiesData *data ) ;
void WriteObject(const wxObject *object, const wxClassInfo *classInfo , wxPersister *persister , bool isEmbedded, wxxVariantArray &metadata ) ;
void FindConnectEntry(const wxWindow * evSource,const wxDelegateTypeInfo* dti, const wxObject* &sink , const wxHandlerInfo *&handler) ;
void FindConnectEntry(const wxEvtHandler * evSource,const wxDelegateTypeInfo* dti, const wxObject* &sink , const wxHandlerInfo *&handler) ;
} ;
class wxXmlWriter : public wxWriter
{
public :
wxXmlWriter( wxXmlNode * parent ) ;
~wxXmlWriter() ;
//
// streaming callbacks
//
// these callbacks really write out the values in the stream format
//
//
// streaming callbacks
//
// these callbacks really write out the values in the stream format
// begins writing out a new toplevel entry which has the indicated unique name
virtual void DoBeginWriteTopLevelEntry( const wxString &name ) ;
// ends writing out a new toplevel entry which has the indicated unique name
virtual void DoEndWriteTopLevelEntry( const wxString &name ) ;
// start of writing an object having the passed in ID
virtual void DoBeginWriteObject(const wxObject *object, const wxClassInfo *classInfo, int objectID , wxxVariantArray &metadata ) ;
// end of writing an toplevel object name param is used for unique identification within the container
virtual void DoEndWriteObject(const wxObject *object, const wxClassInfo *classInfo, int objectID ) ;
// writes a simple property in the stream format
virtual void DoWriteSimpleType( wxxVariant &value ) ;
// start of writing a complex property into the stream (
virtual void DoBeginWriteProperty( const wxPropertyInfo *propInfo ) ;
// end of writing a complex property into the stream
virtual void DoEndWriteProperty( const wxPropertyInfo *propInfo ) ;
virtual void DoBeginWriteElement() ;
virtual void DoEndWriteElement() ;
// insert an object reference to an already written object
virtual void DoWriteRepeatedObject( int objectID ) ;
// insert a null reference
virtual void DoWriteNullObject() ;
// writes a delegate in the stream format
virtual void DoWriteDelegate( const wxObject *object, const wxClassInfo* classInfo , const wxPropertyInfo *propInfo ,
const wxObject *eventSink , int sinkObjectID , const wxClassInfo* eventSinkClassInfo , const wxHandlerInfo* handlerIndo ) ;
private :
struct wxXmlWriterInternal ;
wxXmlWriterInternal* m_data ;
} ;
/*
Streaming callbacks for depersisting XML to code, or running objects
@@ -235,31 +180,6 @@ private :
wxReaderInternal *m_data;
} ;
/*
wxXmlReader handles streaming in a class from XML
*/
class wxXmlReader : public wxReader
{
public:
wxXmlReader(wxXmlNode *parent) { m_parent = parent ; }
~wxXmlReader() {}
// Reads a component from XML. The return value is the root object ID, which can
// then be used to ask the depersister about that object
virtual int ReadObject( const wxString &name , wxDepersister *depersist ) ;
private :
int ReadComponent(wxXmlNode *parent, wxDepersister *callbacks);
// read the content of this node (simple type) and return the corresponding value
wxxVariant ReadValue(wxXmlNode *Node,
const wxTypeInfo *type );
wxXmlNode * m_parent ;
};
// This abstract class matches the allocate-init/create model of creation of objects.
// At runtime, these will create actual instances, and manipulate them.
// When generating code, these will just create statements of C++

110
include/wx/xtixml.h Normal file
View File

@@ -0,0 +1,110 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/xtixml.h
// Purpose: xml streaming runtime metadata information (extended class info)
// Author: Stefan Csomor
// Modified by:
// Created: 27/07/03
// RCS-ID: $Id$
// Copyright: (c) 2003 Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_XTIXMLH__
#define _WX_XTIXMLH__
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma interface "xtixml.h"
#endif
#include "wx/wx.h"
#if wxUSE_EXTENDED_RTTI
#include "wx/xtistrm.h"
class wxXmlNode ;
class wxXmlWriter : public wxWriter
{
public :
wxXmlWriter( wxXmlNode * parent ) ;
~wxXmlWriter() ;
//
// streaming callbacks
//
// these callbacks really write out the values in the stream format
//
//
// streaming callbacks
//
// these callbacks really write out the values in the stream format
// begins writing out a new toplevel entry which has the indicated unique name
virtual void DoBeginWriteTopLevelEntry( const wxString &name ) ;
// ends writing out a new toplevel entry which has the indicated unique name
virtual void DoEndWriteTopLevelEntry( const wxString &name ) ;
// start of writing an object having the passed in ID
virtual void DoBeginWriteObject(const wxObject *object, const wxClassInfo *classInfo, int objectID , wxxVariantArray &metadata ) ;
// end of writing an toplevel object name param is used for unique identification within the container
virtual void DoEndWriteObject(const wxObject *object, const wxClassInfo *classInfo, int objectID ) ;
// writes a simple property in the stream format
virtual void DoWriteSimpleType( wxxVariant &value ) ;
// start of writing a complex property into the stream (
virtual void DoBeginWriteProperty( const wxPropertyInfo *propInfo ) ;
// end of writing a complex property into the stream
virtual void DoEndWriteProperty( const wxPropertyInfo *propInfo ) ;
virtual void DoBeginWriteElement() ;
virtual void DoEndWriteElement() ;
// insert an object reference to an already written object
virtual void DoWriteRepeatedObject( int objectID ) ;
// insert a null reference
virtual void DoWriteNullObject() ;
// writes a delegate in the stream format
virtual void DoWriteDelegate( const wxObject *object, const wxClassInfo* classInfo , const wxPropertyInfo *propInfo ,
const wxObject *eventSink , int sinkObjectID , const wxClassInfo* eventSinkClassInfo , const wxHandlerInfo* handlerIndo ) ;
private :
struct wxXmlWriterInternal ;
wxXmlWriterInternal* m_data ;
} ;
/*
wxXmlReader handles streaming in a class from XML
*/
class wxXmlReader : public wxReader
{
public:
wxXmlReader(wxXmlNode *parent) { m_parent = parent ; }
~wxXmlReader() {}
// Reads a component from XML. The return value is the root object ID, which can
// then be used to ask the depersister about that object
virtual int ReadObject( const wxString &name , wxDepersister *depersist ) ;
private :
int ReadComponent(wxXmlNode *parent, wxDepersister *callbacks);
// read the content of this node (simple type) and return the corresponding value
wxxVariant ReadValue(wxXmlNode *Node,
const wxTypeInfo *type );
wxXmlNode * m_parent ;
};
#endif // wxUSE_EXTENDED_RTTI
#endif