Public Member Functions | Static Public Member Functions | Protected Member Functions

vtkKWESerializableObject Class Reference

Superclass for serializable objects. More...

#include <vtkKWESerializableObject.h>

Inheritance diagram for vtkKWESerializableObject:
Inheritance graph
[legend]
Collaboration diagram for vtkKWESerializableObject:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 vtkTypeRevisionMacro (vtkKWESerializableObject, vtkObject)
virtual void Serialize (vtkKWESerializer *)

Static Public Member Functions

static vtkKWESerializableObjectNew ()

Protected Member Functions

 vtkKWESerializableObject ()
 ~vtkKWESerializableObject ()

Detailed Description

Superclass for serializable objects.

vtkKWESerializableObject works with vtkKWESerializer and its subclasses to provide a serialization framework. The user asks a vtkKWESerializer to write or read an archive consisting of a collection of vtkKWESerializableObjects. The serializer then reads/writes the archive in collaboration with the serializable objects. When reading an archive, the serializer creates the appropriate objects (usually using the instantiator) and then calls Serialize() on them. It is then the responsability of these objects to restore their state by calling functions provided by the serializer. For example, this may look like:

 void vtkKWEObjectTreeNodeBase::Serialize(vtkKWESerializer* ser)
 {
 ser->Serialize("Attributes", this->Attributes);
 ser->Serialize("Properties", this->Properties);
 vtkKWESerializableObject *parent = this->Parent;
 ser->Serialize("Parent", parent, true); // true indicates it is a weak ptr
 if (ser->IsWriting())
   {
   vtkstd::vector< vtkSmartPointer<vtkKWESerializableObject> > myVector =
     vtkKWESerializer::ToBase<vtkstd::vector<vtkSmartPointer<vtkKWEObjectTreeNodeBase> > >(
        *this->Children );
   ser->Serialize("Children", myVector);
   }
 else
   {
   this->Parent = vtkKWEObjectTreeNodeBase::SafeDownCast(parent);
   vtkstd::vector< vtkSmartPointer<vtkKWESerializableObject> > myVector;
   ser->Serialize("Children", myVector);
   vtkKWESerializer::FromBase<vtkKWEObjectTreeNodeBase>(myVector, *this->Children);
   }

When writing the archive, the serializer calls Serialize() on the "root" objects (the ones passed by the user) which then use the serializer methods to write themselves in the archive.

Note that there is only one Serialize() method that does reading and writing. This works because the methods in vtkKWESerializer take references to data member and can read or write them as appropriate. In cases where the class needs to do something different during reading or writing, you can separate the implementation using if (ser->IsWriting()) {..} else {..} as shown in the example above.

You can also implement more sophisticated serialization code by using temporaries during reading and writing and copying them to the actual data members yourself. Something like:

 void vtkSomeSerializableObject::Serialize(vtkKWESerializer* ser)
 {
   int foo;
   if (ser->IsWriting)
     {
     // ...
     }
   else
     {
     int foo;
     ser->Serialize(foo);
     // Based on the value of foo, do something to data members
     }

The serializer also supports versioning. You can get the version of the archive being written or read using vtkKWESerializer::GetArchiveVersion()

Definition at line 98 of file vtkKWESerializableObject.h.


Constructor & Destructor Documentation

vtkKWESerializableObject::vtkKWESerializableObject (  )  [protected]
vtkKWESerializableObject::~vtkKWESerializableObject (  )  [protected]

Member Function Documentation

static vtkKWESerializableObject* vtkKWESerializableObject::New (  )  [static]
vtkKWESerializableObject::vtkTypeRevisionMacro ( vtkKWESerializableObject  ,
vtkObject   
)
virtual void vtkKWESerializableObject::Serialize ( vtkKWESerializer  )  [inline, virtual]

Reads the state of an instance from an archive OR writes the state of an instance to an archive. See the documentation for this class for details.

Reimplemented in vtkKWEObjectTreeNodeBase, vtkKWEObjectTreePropertyBase, and vtkKWEObjectTreeTransformableNode.

Definition at line 107 of file vtkKWESerializableObject.h.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines