xti streaming
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22599 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -20,6 +20,9 @@
|
|||||||
|
|
||||||
#if wxUSE_EXTENDED_RTTI
|
#if wxUSE_EXTENDED_RTTI
|
||||||
|
|
||||||
|
const int wxInvalidObjectID = -2 ;
|
||||||
|
const int wxNullObjectID = -1 ;
|
||||||
|
|
||||||
// Filer contains the interfaces for streaming objects in and out of XML,
|
// Filer contains the interfaces for streaming objects in and out of XML,
|
||||||
// rendering them either to objects in memory, or to code. Note: We
|
// rendering them either to objects in memory, or to code. Note: We
|
||||||
// consider the process of generating code to be one of *depersisting* the
|
// consider the process of generating code to be one of *depersisting* the
|
||||||
@@ -29,153 +32,233 @@
|
|||||||
// listed below.
|
// listed below.
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Main interface for streaming out an object to XML.
|
Main interface for streaming out an object to XML.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void WriteComponent(wxObject *Object, const wxClassInfo *ClassInfo, wxXmlNode *parent, const wxString& nodeName );
|
void WriteComponent(wxObject *Object, const wxClassInfo *ClassInfo, wxXmlNode *parent, const wxString& nodeName );
|
||||||
|
|
||||||
class wxReader;
|
|
||||||
/*
|
/*
|
||||||
Streaming callbacks for depersisting XML to code, or running objects
|
Streaming callbacks for depersisting XML to code, or running objects
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct wxIDepersist ;
|
class wxDepersister ;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
wxReader handles streaming in a class from XML. Maintains a list of
|
wxReader handles streaming in a class from a arbitrary format. While walking through
|
||||||
objects, and names, and issues calls out to interfaces to depersist the
|
it issues calls out to interfaces to depersist the guts from the underlying storage format.
|
||||||
guts from the XML tree.
|
|
||||||
*/
|
*/
|
||||||
class wxReader : wxObject
|
|
||||||
|
class wxReader : public wxObject
|
||||||
{
|
{
|
||||||
|
public :
|
||||||
|
wxReader() ;
|
||||||
|
~wxReader() ;
|
||||||
|
// the only thing wxReader knows about is the class info by object ID
|
||||||
|
wxClassInfo *GetObjectClassInfo(int objectID) ;
|
||||||
|
bool HasObjectClassInfo( int objectID ) ;
|
||||||
|
void SetObjectClassInfo(int objectID, wxClassInfo* classInfo);
|
||||||
|
|
||||||
|
// Reads the component the reader is pointed at from the underlying format.
|
||||||
|
// The return value is the root object ID, which can
|
||||||
|
// then be used to ask the depersister about that object
|
||||||
|
virtual int ReadObject( wxDepersister *depersist ) = 0 ;
|
||||||
|
|
||||||
|
private :
|
||||||
struct wxReaderInternal;
|
struct wxReaderInternal;
|
||||||
wxReaderInternal *Data;
|
wxReaderInternal *m_data;
|
||||||
|
} ;
|
||||||
wxxVariant ReadPropertyValueNoAssign(wxXmlNode *Node,
|
|
||||||
wxClassInfo *ClassInfo,
|
|
||||||
const wxPropertyInfo *& propertyInfo ,
|
|
||||||
wxIDepersist *Callbacks = NULL);
|
|
||||||
|
|
||||||
void ReadPropertyValue(wxXmlNode *Node,
|
|
||||||
wxClassInfo *ClassInfo,
|
|
||||||
int ObjectId ,
|
|
||||||
wxIDepersist *Callbacks = NULL );
|
|
||||||
|
|
||||||
bool genCode; // true if the reader should generate code.
|
|
||||||
// ISSUE: ick!
|
|
||||||
// this interface is getting crufty. Why the
|
|
||||||
// different depersist callbacks in here, if there
|
|
||||||
// is another place that knows that we're generating
|
|
||||||
// code? Needs some repair work.
|
|
||||||
public:
|
|
||||||
wxReader(bool GenerateCode = false);
|
|
||||||
~wxReader();
|
|
||||||
|
|
||||||
// Reads a component from XML. The return is the object ID, which can
|
|
||||||
// be used in calls to GetObject or GetObjectName.
|
|
||||||
//
|
|
||||||
// ISSUE: Still needs to implement references to objects.
|
|
||||||
// requires a bit of additional design in the XML (minor).
|
|
||||||
int ReadComponent(wxXmlNode *parent, wxIDepersist *Callbacks);
|
|
||||||
|
|
||||||
// When streaming in, we may we depersisting to code, or to objects
|
|
||||||
// in memory. The depersist callbacks for generating code will
|
|
||||||
// not create the objects, but will create names for them instead.
|
|
||||||
// So internally, we keep track of IDs, not pointers. Depending
|
|
||||||
// on who you are in your callbacks, you can query the names or
|
|
||||||
// pointers of the objects as need be. You should not mix both,
|
|
||||||
// because you will die if you do.
|
|
||||||
|
|
||||||
wxObject *GetObject(int id);
|
|
||||||
wxString GetObjectName(int id);
|
|
||||||
wxClassInfo *GetObjectClassInfo(int id) ;
|
|
||||||
|
|
||||||
void SetObject(int id, wxObject *Object);
|
|
||||||
void SetObjectName(int id, const wxString &Name, wxClassInfo* ClassInfo);
|
|
||||||
|
|
||||||
// Returns the result of a top level ReadComponent call. Used
|
|
||||||
// typically after you have instructed the reader to stream in an
|
|
||||||
// object, and you want the object back now. Only really valid if
|
|
||||||
// you are reading back in to an object in memory, as opposed to code.
|
|
||||||
wxObject *GetRoot() { return GetObject( 0 ) ; }
|
|
||||||
};
|
|
||||||
|
|
||||||
struct wxIDepersist
|
|
||||||
{
|
|
||||||
// NotifyReader is called by wxReader so that we can have access to the
|
|
||||||
// object store functions in the reader when we are called back. Hmm.
|
|
||||||
// probably should have just made the callback functions each take a
|
|
||||||
// wxReader.
|
|
||||||
virtual void NotifyReader(wxReader *Reader) = 0;
|
|
||||||
|
|
||||||
// The next three callbacks match the ACS 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++
|
|
||||||
// code to create the objects.
|
|
||||||
virtual void AllocateObject(int ObjectID, wxClassInfo *ClassInfo) = 0;
|
|
||||||
virtual void CreateObject(int ObjectID,
|
|
||||||
wxClassInfo *ClassInfo,
|
|
||||||
int ParamCount,
|
|
||||||
wxxVariant *VariantValues) = 0;
|
|
||||||
virtual void SetProperty(int ObjectID,
|
|
||||||
wxClassInfo *ClassInfo,
|
|
||||||
const wxPropertyInfo* PropertyInfo ,
|
|
||||||
const wxxVariant &VariantValue) = 0;
|
|
||||||
virtual void SetConnect(int EventSourceObjectID,
|
|
||||||
wxClassInfo *EventSourceClassInfo,
|
|
||||||
int eventType ,
|
|
||||||
const wxString &handlerName ,
|
|
||||||
int EventSinkObjectID ) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
wxIDepersistRuntime implements the callbacks that will depersist
|
wxXmlReader handles streaming in a class from XML
|
||||||
an object into a running memory image, as opposed to writing
|
|
||||||
C++ initialization code to bring the object to life.
|
|
||||||
*/
|
*/
|
||||||
class wxIDepersistRuntime : public wxIDepersist
|
|
||||||
|
class wxXmlReader : public wxReader
|
||||||
{
|
{
|
||||||
wxReader *Reader;
|
|
||||||
public:
|
public:
|
||||||
virtual void NotifyReader(wxReader *_Reader)
|
wxXmlReader(wxXmlNode *parent) { m_parent = parent ; }
|
||||||
{
|
~wxXmlReader() {}
|
||||||
Reader = _Reader;
|
|
||||||
}
|
// Reads a component from XML. The return value is the root object ID, which can
|
||||||
virtual void AllocateObject(int ObjectID, wxClassInfo *ClassInfo);
|
// then be used to ask the depersister about that object
|
||||||
virtual void CreateObject(int ObjectID, wxClassInfo *ClassInfo, int ParamCount, wxxVariant *VariantValues);
|
|
||||||
virtual void SetProperty(int ObjectID, wxClassInfo *ClassInfo, const wxPropertyInfo* PropertyInfo, const wxxVariant &VariantValue);
|
int ReadObject(wxDepersister *callbacks);
|
||||||
|
|
||||||
|
private :
|
||||||
|
int ReadComponent(wxXmlNode *parent, wxDepersister *callbacks);
|
||||||
|
|
||||||
|
// accessor is only used as a temporary measure
|
||||||
|
wxxVariant ReadValue(wxXmlNode *Node,
|
||||||
|
wxPropertyAccessor *accessor );
|
||||||
|
|
||||||
|
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++
|
||||||
|
// code to create the objects.
|
||||||
|
|
||||||
|
class wxDepersister
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
// allocate the new object on the heap, that object will have the passed in ID
|
||||||
|
virtual void AllocateObject(int ObjectID, wxClassInfo *ClassInfo) = 0;
|
||||||
|
|
||||||
|
// initialize the already allocated object having the ID ObjectID with the Create method
|
||||||
|
// creation parameters which are objects are having their Ids passed in objectIDValues
|
||||||
|
// having objectId <> wxInvalidObjectID
|
||||||
|
|
||||||
|
virtual void CreateObject(int ObjectID,
|
||||||
|
const wxClassInfo *ClassInfo,
|
||||||
|
int ParamCount,
|
||||||
|
wxxVariant *VariantValues ,
|
||||||
|
int *objectIDValues ,
|
||||||
|
const wxClassInfo **objectClassInfos
|
||||||
|
) = 0;
|
||||||
|
|
||||||
|
// destroy the heap-allocated object having the ID ObjectID, this may be used if an object
|
||||||
|
// is embedded in another object and set via value semantics, so the intermediate
|
||||||
|
// object can be destroyed after safely
|
||||||
|
virtual void DestroyObject(int ObjectID, wxClassInfo *ClassInfo) = 0;
|
||||||
|
|
||||||
|
// set the corresponding property
|
||||||
|
virtual void SetProperty(int ObjectID,
|
||||||
|
const wxClassInfo *ClassInfo,
|
||||||
|
const wxPropertyInfo* PropertyInfo ,
|
||||||
|
const wxxVariant &VariantValue) = 0;
|
||||||
|
|
||||||
|
// sets the corresponding property (value is an object)
|
||||||
|
virtual void SetPropertyAsObject(int ObjectId,
|
||||||
|
const wxClassInfo *ClassInfo,
|
||||||
|
const wxPropertyInfo* PropertyInfo ,
|
||||||
|
int valueObjectId) = 0;
|
||||||
|
|
||||||
|
|
||||||
|
// sets the corresponding event handler
|
||||||
virtual void SetConnect(int EventSourceObjectID,
|
virtual void SetConnect(int EventSourceObjectID,
|
||||||
wxClassInfo *EventSourceClassInfo,
|
const wxClassInfo *EventSourceClassInfo,
|
||||||
int eventType ,
|
const wxDelegateTypeInfo *delegateInfo ,
|
||||||
const wxString &handlerName ,
|
const wxClassInfo *EventSinkClassInfo ,
|
||||||
int EventSinkObjectID ) ;
|
const wxHandlerInfo* handlerInfo ,
|
||||||
|
int EventSinkObjectID ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
wxIDepersistCode implements the callbacks that will depersist
|
wxRuntimeDepersister implements the callbacks that will depersist
|
||||||
an object into a C++ initialization function.
|
an object into a running memory image, as opposed to writing
|
||||||
|
C++ initialization code to bring the object to life.
|
||||||
|
*/
|
||||||
|
class wxRuntimeDepersister : public wxDepersister
|
||||||
|
{
|
||||||
|
struct wxRuntimeDepersisterInternal ;
|
||||||
|
wxRuntimeDepersisterInternal * m_data ;
|
||||||
|
public :
|
||||||
|
wxRuntimeDepersister() ;
|
||||||
|
~wxRuntimeDepersister() ;
|
||||||
|
|
||||||
|
// returns the object having the corresponding ID fully constructed
|
||||||
|
wxObject *GetObject(int objectID) ;
|
||||||
|
|
||||||
|
// allocate the new object on the heap, that object will have the passed in ID
|
||||||
|
virtual void AllocateObject(int objectID, wxClassInfo *classInfo) ;
|
||||||
|
|
||||||
|
// initialize the already allocated object having the ID ObjectID with the Create method
|
||||||
|
// creation parameters which are objects are having their Ids passed in objectIDValues
|
||||||
|
// having objectId <> wxInvalidObjectID
|
||||||
|
|
||||||
|
virtual void CreateObject(int ObjectID,
|
||||||
|
const wxClassInfo *ClassInfo,
|
||||||
|
int ParamCount,
|
||||||
|
wxxVariant *VariantValues ,
|
||||||
|
int *objectIDValues,
|
||||||
|
const wxClassInfo **objectClassInfos
|
||||||
|
) ;
|
||||||
|
|
||||||
|
// destroy the heap-allocated object having the ID ObjectID, this may be used if an object
|
||||||
|
// is embedded in another object and set via value semantics, so the intermediate
|
||||||
|
// object can be destroyed after safely
|
||||||
|
virtual void DestroyObject(int objectID, wxClassInfo *classInfo) ;
|
||||||
|
|
||||||
|
// set the corresponding property
|
||||||
|
virtual void SetProperty(int objectID,
|
||||||
|
const wxClassInfo *classInfo,
|
||||||
|
const wxPropertyInfo* propertyInfo ,
|
||||||
|
const wxxVariant &variantValue);
|
||||||
|
|
||||||
|
// sets the corresponding property (value is an object)
|
||||||
|
virtual void SetPropertyAsObject(int objectId,
|
||||||
|
const wxClassInfo *classInfo,
|
||||||
|
const wxPropertyInfo* propertyInfo ,
|
||||||
|
int valueObjectId) ;
|
||||||
|
|
||||||
|
|
||||||
|
// sets the corresponding event handler
|
||||||
|
virtual void SetConnect(int eventSourceObjectID,
|
||||||
|
const wxClassInfo *eventSourceClassInfo,
|
||||||
|
const wxDelegateTypeInfo *delegateInfo ,
|
||||||
|
const wxClassInfo *eventSinkClassInfo ,
|
||||||
|
const wxHandlerInfo* handlerInfo ,
|
||||||
|
int eventSinkObjectID ) ;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
wxDepersisterCode implements the callbacks that will depersist
|
||||||
|
an object into a C++ initialization function.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class wxTextOutputStream ;
|
class wxTextOutputStream ;
|
||||||
|
|
||||||
class wxIDepersistCode : public wxIDepersist
|
class wxCodeDepersister : public wxDepersister
|
||||||
{
|
{
|
||||||
wxReader *Reader;
|
private :
|
||||||
wxTextOutputStream *fp;
|
struct wxCodeDepersisterInternal ;
|
||||||
|
wxCodeDepersisterInternal * m_data ;
|
||||||
|
wxTextOutputStream *m_fp;
|
||||||
|
wxString ValueAsCode( const wxxVariant ¶m ) ;
|
||||||
public:
|
public:
|
||||||
wxIDepersistCode(wxTextOutputStream *out) : fp(out) { }
|
wxCodeDepersister(wxTextOutputStream *out) ;
|
||||||
virtual void NotifyReader(wxReader *_Reader)
|
~wxCodeDepersister() ;
|
||||||
{
|
|
||||||
Reader = _Reader;
|
// allocate the new object on the heap, that object will have the passed in ID
|
||||||
}
|
virtual void AllocateObject(int objectID, wxClassInfo *classInfo) ;
|
||||||
virtual void AllocateObject(int ObjectID, wxClassInfo *ClassInfo);
|
|
||||||
virtual void CreateObject(int ObjectID, wxClassInfo *ClassInfo, int ParamCount, wxxVariant *VariantValues);
|
// initialize the already allocated object having the ID ObjectID with the Create method
|
||||||
virtual void SetProperty(int ObjectID, wxClassInfo *ClassInfo, const wxPropertyInfo* PropertyInfo, const wxxVariant &VariantValue);
|
// creation parameters which are objects are having their Ids passed in objectIDValues
|
||||||
virtual void SetConnect(int EventSourceObjectID,
|
// having objectId <> wxInvalidObjectID
|
||||||
wxClassInfo *EventSourceClassInfo,
|
|
||||||
int eventType ,
|
virtual void CreateObject(int objectID,
|
||||||
const wxString &handlerName ,
|
const wxClassInfo *classInfo,
|
||||||
int EventSinkObjectID ) ;
|
int paramCount,
|
||||||
|
wxxVariant *variantValues ,
|
||||||
|
int *objectIDValues,
|
||||||
|
const wxClassInfo **objectClassInfos
|
||||||
|
) ;
|
||||||
|
|
||||||
|
// destroy the heap-allocated object having the ID ObjectID, this may be used if an object
|
||||||
|
// is embedded in another object and set via value semantics, so the intermediate
|
||||||
|
// object can be destroyed after safely
|
||||||
|
virtual void DestroyObject(int objectID, wxClassInfo *classInfo) ;
|
||||||
|
|
||||||
|
// set the corresponding property
|
||||||
|
virtual void SetProperty(int objectID,
|
||||||
|
const wxClassInfo *classInfo,
|
||||||
|
const wxPropertyInfo* propertyInfo ,
|
||||||
|
const wxxVariant &variantValue);
|
||||||
|
|
||||||
|
// sets the corresponding property (value is an object)
|
||||||
|
virtual void SetPropertyAsObject(int objectId,
|
||||||
|
const wxClassInfo *classInfo,
|
||||||
|
const wxPropertyInfo* propertyInfo ,
|
||||||
|
int valueObjectId) ;
|
||||||
|
|
||||||
|
|
||||||
|
// sets the corresponding event handler
|
||||||
|
virtual void SetConnect(int eventSourceObjectID,
|
||||||
|
const wxClassInfo *eventSourceClassInfo,
|
||||||
|
const wxDelegateTypeInfo *delegateInfo ,
|
||||||
|
const wxClassInfo *eventSinkClassInfo ,
|
||||||
|
const wxHandlerInfo* handlerInfo ,
|
||||||
|
int eventSinkObjectID ) ;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // wxUSE_EXTENDED_RTTI
|
#endif // wxUSE_EXTENDED_RTTI
|
||||||
|
Reference in New Issue
Block a user