// Name: wx/xtistrm.h
// Purpose: streaming runtime metadata information (extended class info)
// Author: Stefan Csomor
-// Modified by:
+// Modified by:
// Created: 27/07/03
// RCS-ID: $Id$
// Copyright: (c) 2003 Stefan Csomor
#ifndef _WX_XTISTRMH__
#define _WX_XTISTRMH__
-#if defined(__GNUG__) && !defined(__APPLE__)
-#pragma interface "xtistrm.h"
-#endif
-
-#include "wx/wx.h"
+#include "wx/defs.h"
#if wxUSE_EXTENDED_RTTI
+#include "wx/object.h"
+
+const int wxInvalidObjectID = -2;
+const int wxNullObjectID = -3;
+
// Filer contains the interfaces for streaming objects in and out of XML,
// rendering them either to objects in memory, or to code. Note: We
// consider the process of generating code to be one of *depersisting* the
// object from xml, *not* of persisting the object to code from an object
-// in memory. This distincation can be confusing, and should be kept
+// in memory. This distinction can be confusing, and should be kept
// in mind when looking at the property streamers and callback interfaces
// listed below.
-/*
- Main interface for streaming out an object to XML.
-*/
-void WriteComponent(wxObject *Object, const wxClassInfo *ClassInfo, wxXmlNode *parent, const wxString& nodeName );
+// ----------------------------------------------------------------------------
+// wxObjectWriterCallback
+//
+// This class will be asked during the streaming-out process about every single
+// property or object instance. It can veto streaming out by returning false
+// or modify the value before it is streamed-out.
+// ----------------------------------------------------------------------------
+
+class WXDLLIMPEXP_BASE wxObjectWriter;
+class WXDLLIMPEXP_BASE wxObjectReader;
+class WXDLLIMPEXP_BASE wxClassInfo;
+class WXDLLIMPEXP_BASE wxAnyList;
+class WXDLLIMPEXP_BASE wxPropertyInfo;
+class WXDLLIMPEXP_BASE wxAny;
+class WXDLLIMPEXP_BASE wxObjectWriter;
+class WXDLLIMPEXP_BASE wxHandlerInfo;
+
+class WXDLLIMPEXP_BASE wxObjectWriterCallback
+{
+public:
+ virtual ~wxObjectWriterCallback() {}
+
+ // will be called before an object is written, may veto by returning false
+ virtual bool BeforeWriteObject( wxObjectWriter *WXUNUSED(writer),
+ const wxObject *WXUNUSED(object),
+ const wxClassInfo *WXUNUSED(classInfo),
+ const wxStringToAnyHashMap &WXUNUSED(metadata))
+ { return true; }
+
+ // will be called after this object has been written, may be
+ // needed for adjusting stacks
+ virtual void AfterWriteObject( wxObjectWriter *WXUNUSED(writer),
+ const wxObject *WXUNUSED(object),
+ const wxClassInfo *WXUNUSED(classInfo) )
+ {}
+
+ // will be called before a property gets written, may change the value,
+ // eg replace a concrete wxSize by wxSize( wxDefaultCoord, wxDefaultCoord )
+ // or veto writing that property at all by returning false
+ virtual bool BeforeWriteProperty( wxObjectWriter *WXUNUSED(writer),
+ const wxObject *WXUNUSED(object),
+ const wxPropertyInfo *WXUNUSED(propInfo),
+ const wxAny &WXUNUSED(value) )
+ { return true; }
+
+ // will be called before a property gets written, may change the value,
+ // eg replace a concrete wxSize by wxSize( wxDefaultCoord, wxDefaultCoord )
+ // or veto writing that property at all by returning false
+ virtual bool BeforeWriteProperty( wxObjectWriter *WXUNUSED(writer),
+ const wxObject *WXUNUSED(object),
+ const wxPropertyInfo *WXUNUSED(propInfo),
+ const wxAnyList &WXUNUSED(value) )
+ { return true; }
+
+ // will be called after a property has been written out, may be needed
+ // for adjusting stacks
+ virtual void AfterWriteProperty( wxObjectWriter *WXUNUSED(writer),
+ const wxPropertyInfo *WXUNUSED(propInfo) )
+ {}
+
+ // will be called before this delegate gets written
+ virtual bool BeforeWriteDelegate( wxObjectWriter *WXUNUSED(writer),
+ const wxObject *WXUNUSED(object),
+ const wxClassInfo* WXUNUSED(classInfo),
+ const wxPropertyInfo *WXUNUSED(propInfo),
+ const wxObject *&WXUNUSED(eventSink),
+ const wxHandlerInfo* &WXUNUSED(handlerInfo) )
+ { return true; }
+
+ virtual void AfterWriteDelegate( wxObjectWriter *WXUNUSED(writer),
+ const wxObject *WXUNUSED(object),
+ const wxClassInfo* WXUNUSED(classInfo),
+ const wxPropertyInfo *WXUNUSED(propInfo),
+ const wxObject *&WXUNUSED(eventSink),
+ const wxHandlerInfo* &WXUNUSED(handlerInfo) )
+ { }
+};
+
+class WXDLLIMPEXP_BASE wxObjectWriterFunctor: public wxObjectFunctor
+{
+};
+
+class WXDLLIMPEXP_BASE wxObjectWriter: public wxObject
+{
+ friend class wxObjectWriterFunctor;
+public:
+ wxObjectWriter();
+ virtual ~wxObjectWriter();
+
+ // with this call you start writing out a new top-level object
+ void WriteObject(const wxObject *object, const wxClassInfo *classInfo,
+ wxObjectWriterCallback *writercallback, const wxString &name,
+ const wxStringToAnyHashMap &metadata);
+
+ // Managing the object identity table a.k.a context
+ //
+ // these methods make sure that no object gets written twice,
+ // because sometimes multiple calls to the WriteObject will be
+ // made without wanting to have duplicate objects written, the
+ // object identity table will be reset manually
+ virtual void ClearObjectContext();
+
+ // gets the object Id for a passed in object in the context
+ int GetObjectID(const wxObject *obj);
+
+ // returns true if this object has already been written in this context
+ bool IsObjectKnown( const wxObject *obj );
+
+ //
+ // 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 ) = 0;
+
+ // ends writing out a new toplevel entry which has the indicated unique name
+ virtual void DoEndWriteTopLevelEntry( const wxString &name ) = 0;
+
+ // start of writing an object having the passed in ID
+ virtual void DoBeginWriteObject(const wxObject *object, const wxClassInfo *classInfo,
+ int objectID, const wxStringToAnyHashMap &metadata ) = 0;
+
+ // 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 ) = 0;
+
+ // writes a simple property in the stream format
+ virtual void DoWriteSimpleType( const wxAny &value ) = 0;
+
+ // start of writing a complex property into the stream (
+ virtual void DoBeginWriteProperty( const wxPropertyInfo *propInfo ) = 0;
+
+ // end of writing a complex property into the stream
+ virtual void DoEndWriteProperty( const wxPropertyInfo *propInfo ) = 0;
+
+ virtual void DoBeginWriteElement() = 0;
+ virtual void DoEndWriteElement() = 0;
+ // insert an object reference to an already written object
+ virtual void DoWriteRepeatedObject( int objectID ) = 0;
+
+ // insert a null reference
+ virtual void DoWriteNullObject() = 0;
+
+ // 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 ) = 0;
+
+ void WriteObject(const wxObject *object, const wxClassInfo *classInfo,
+ wxObjectWriterCallback *writercallback, bool isEmbedded, const wxStringToAnyHashMap &metadata );
+
+protected:
+ struct wxObjectWriterInternal;
+ wxObjectWriterInternal* m_data;
+
+ struct wxObjectWriterInternalPropertiesData;
+
+ void WriteAllProperties( const wxObject * obj, const wxClassInfo* ci,
+ wxObjectWriterCallback *writercallback,
+ wxObjectWriterInternalPropertiesData * data );
+
+ void WriteOneProperty( const wxObject *obj, const wxClassInfo* ci,
+ const wxPropertyInfo* pi, wxObjectWriterCallback *writercallback,
+ wxObjectWriterInternalPropertiesData *data );
+
+
+ void FindConnectEntry(const wxEvtHandler * evSource,
+ const wxEventSourceTypeInfo* dti, const wxObject* &sink,
+ const wxHandlerInfo *&handler);
+};
+
-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 WXDLLIMPEXP_BASE wxObjectReaderCallback;
/*
- wxReader handles streaming in a class from XML. Maintains a list of
- objects, and names, and issues calls out to interfaces to depersist the
- guts from the XML tree.
+wxObjectReader handles streaming in a class from a arbitrary format.
+While walking through it issues calls out to interfaces to readercallback
+the guts from the underlying storage format.
*/
-class wxReader : wxObject
+
+class WXDLLIMPEXP_BASE wxObjectReader: public wxObject
{
- struct wxReaderInternal;
- wxReaderInternal *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();
+ wxObjectReader();
+ virtual ~wxObjectReader();
- // 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 ) ; }
-};
+ // the only thing wxObjectReader knows about is the class info by object ID
+ wxClassInfo *GetObjectClassInfo(int objectID);
+ bool HasObjectClassInfo( int objectID );
+ void SetObjectClassInfo(int objectID, wxClassInfo* classInfo);
-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;
+ // 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
+ // if there was a problem you will get back wxInvalidObjectID and the current
+ // error log will carry the problems encoutered
+ virtual int ReadObject( const wxString &name, wxObjectReaderCallback *readercallback ) = 0;
+
+private:
+ struct wxObjectReaderInternal;
+ wxObjectReaderInternal *m_data;
};
-/*
- wxIDepersistRuntime implements the callbacks that will depersist
- an object into a running memory image, as opposed to writing
- C++ initialization code to bring the object to life.
-*/
-class wxIDepersistRuntime : public wxIDepersist
+// 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 WXDLLIMPEXP_BASE wxObjectReaderCallback
{
- wxReader *Reader;
public:
- virtual void NotifyReader(wxReader *_Reader)
- {
- Reader = _Reader;
- }
- virtual void AllocateObject(int ObjectID, wxClassInfo *ClassInfo);
- virtual void CreateObject(int ObjectID, wxClassInfo *ClassInfo, int ParamCount, wxxVariant *VariantValues);
- virtual void SetProperty(int ObjectID, wxClassInfo *ClassInfo, const wxPropertyInfo* PropertyInfo, const wxxVariant &VariantValue);
+ virtual ~wxObjectReaderCallback() {}
+
+ // allocate the new object on the heap, that object will have the passed in ID
+ virtual void AllocateObject(int objectID, wxClassInfo *classInfo,
+ wxStringToAnyHashMap &metadata) = 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,
+ wxAny *VariantValues,
+ int *objectIDValues,
+ const wxClassInfo **objectClassInfos,
+ wxStringToAnyHashMap &metadata) = 0;
+
+ // construct the new object on the heap, that object will have the passed in ID
+ // (for objects that don't support allocate-create type of creation)
+ // creation parameters which are objects are having their Ids passed in
+ // objectIDValues having objectId <> wxInvalidObjectID
+
+ virtual void ConstructObject(int objectID,
+ const wxClassInfo *classInfo,
+ int paramCount,
+ wxAny *VariantValues,
+ int *objectIDValues,
+ const wxClassInfo **objectClassInfos,
+ wxStringToAnyHashMap &metadata) = 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 wxAny &VariantValue) = 0;
+
+ // sets the corresponding property (value is an object)
+ virtual void SetPropertyAsObject(int objectID,
+ const wxClassInfo *classInfo,
+ const wxPropertyInfo* propertyInfo,
+ int valueObjectId) = 0;
+
+ // adds an element to a property collection
+ virtual void AddToPropertyCollection( int objectID,
+ const wxClassInfo *classInfo,
+ const wxPropertyInfo* propertyInfo,
+ const wxAny &VariantValue) = 0;
+
+ // sets the corresponding property (value is an object)
+ virtual void AddToPropertyCollectionAsObject(int objectID,
+ const wxClassInfo *classInfo,
+ const wxPropertyInfo* propertyInfo,
+ int valueObjectId) = 0;
+
+ // sets the corresponding event handler
virtual void SetConnect(int EventSourceObjectID,
- wxClassInfo *EventSourceClassInfo,
- int eventType ,
- const wxString &handlerName ,
- int EventSinkObjectID ) ;
+ const wxClassInfo *EventSourceClassInfo,
+ const wxPropertyInfo *delegateInfo,
+ const wxClassInfo *EventSinkClassInfo,
+ const wxHandlerInfo* handlerInfo,
+ int EventSinkObjectID ) = 0;
};
/*
- wxIDepersistCode implements the callbacks that will depersist
- an object into a C++ initialization function.
+wxObjectRuntimeReaderCallback implements the callbacks that will bring back
+an object into a life memory instance
*/
-class wxTextOutputStream ;
-
-class wxIDepersistCode : public wxIDepersist
+class WXDLLIMPEXP_BASE wxObjectRuntimeReaderCallback: public wxObjectReaderCallback
{
- wxReader *Reader;
- wxTextOutputStream *fp;
+ struct wxObjectRuntimeReaderCallbackInternal;
+ wxObjectRuntimeReaderCallbackInternal * m_data;
+
public:
- wxIDepersistCode(wxTextOutputStream *out) : fp(out) { }
- virtual void NotifyReader(wxReader *_Reader)
- {
- Reader = _Reader;
- }
- virtual void AllocateObject(int ObjectID, wxClassInfo *ClassInfo);
- virtual void CreateObject(int ObjectID, wxClassInfo *ClassInfo, int ParamCount, wxxVariant *VariantValues);
- virtual void SetProperty(int ObjectID, wxClassInfo *ClassInfo, const wxPropertyInfo* PropertyInfo, const wxxVariant &VariantValue);
- virtual void SetConnect(int EventSourceObjectID,
- wxClassInfo *EventSourceClassInfo,
- int eventType ,
- const wxString &handlerName ,
- int EventSinkObjectID ) ;
+ wxObjectRuntimeReaderCallback();
+ virtual ~wxObjectRuntimeReaderCallback();
+
+ // 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,
+ wxStringToAnyHashMap &metadata);
+
+ // 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,
+ wxAny *VariantValues,
+ int *objectIDValues,
+ const wxClassInfo **objectClassInfos,
+ wxStringToAnyHashMap &metadata
+ );
+
+ // construct the new object on the heap, that object will have the
+ // passed in ID (for objects that don't support allocate-create type of
+ // creation) creation parameters which are objects are having their Ids
+ // passed in objectIDValues having objectId <> wxInvalidObjectID
+
+ virtual void ConstructObject(int objectID,
+ const wxClassInfo *classInfo,
+ int paramCount,
+ wxAny *VariantValues,
+ int *objectIDValues,
+ const wxClassInfo **objectClassInfos,
+ wxStringToAnyHashMap &metadata);
+
+ // 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 wxAny &variantValue);
+
+ // sets the corresponding property (value is an object)
+ virtual void SetPropertyAsObject(int objectId,
+ const wxClassInfo *classInfo,
+ const wxPropertyInfo* propertyInfo,
+ int valueObjectId);
+
+ // adds an element to a property collection
+ virtual void AddToPropertyCollection( int objectID,
+ const wxClassInfo *classInfo,
+ const wxPropertyInfo* propertyInfo,
+ const wxAny &VariantValue);
+
+ // sets the corresponding property (value is an object)
+ virtual void AddToPropertyCollectionAsObject(int objectID,
+ const wxClassInfo *classInfo,
+ const wxPropertyInfo* propertyInfo,
+ int valueObjectId);
+
+ // sets the corresponding event handler
+ virtual void SetConnect(int eventSourceObjectID,
+ const wxClassInfo *eventSourceClassInfo,
+ const wxPropertyInfo *delegateInfo,
+ const wxClassInfo *eventSinkClassInfo,
+ const wxHandlerInfo* handlerInfo,
+ int eventSinkObjectID );
};
#endif // wxUSE_EXTENDED_RTTI
-#endif
\ No newline at end of file
+#endif