Main Page   Class Hierarchy   Alphabetical List   Compound List   Compound Members  

util::Serialization Class Reference

#include <Serialization.h>

Inheritance diagram for util::Serialization:

util::Hashtable< std::string, Serializer * > util::Map< std::string, Serializer * > util::Iterator< Pair< std::string, Serializer * > > util::Object util::Object List of all members.

Detailed Description

A class for collecting all dynamic type serializers together.

Whenever a dynamic type (i.e. a data pointed to by a base class pointer) is to be deserialized, this class does the task. All classes that can be read are added to the associative array prior to calling the readObject method.

To make a class "dynamic type" serializable, you must do the following:

Here's how it goes in real life:
 namespace mynamespace
   class MyBase : public Serializable { ... };
   class MyDerived : public MyBase { ... };

   //These could also be inner classes
   class MyBaseSerializer : public Serializer { ... };
   class MyDerivedSerializer : public Serializer { ... };


   Serialization s;
   MyBaseSerializer baseSerializer;
   MyDerivedSerializer derivedSerializer;

   //Now, cin must start with either mynamespace::MyBase or
   //mynamespace::MyDerived. The actual type can be unknown
   //to us.

   MyBase* m = (MyBase*)s.readObject(cin);

   MyDerived d;
   MyBase* m2 = &d;

   //Now, the contents of d are written to cout.
   //The Serializer must write the fully-qualified class name
   //of the object (mynamespace::MyDerived) first.



Public Methods

 Serialization ()
 The default constructor.

SerializablereadObject (std::istream &in) throw (io::IOException&)
 Read an object from a stream.

void writeObject (std::ostream &out, const Serializable &obj) throw (io::IOException&)
 Write an object to a stream.

void setStripTemplateParams (bool strip)
 The Serialization can be set to ignore template parameters.

bool getStripTemplateParams (void) const
 Check if this Serialization is currently stripping template parameters.

Constructor & Destructor Documentation

util::Serialization::Serialization   [inline]

The default constructor.

Turns template parameter stripping on.

Member Function Documentation

Serializable * util::Serialization::readObject std::istream &    in throw (io::IOException&)

Read an object from a stream.

Serializer first reads a class name, then consults the internal associative array for a Serializer that is able to read the class and gives it the turn. The Serializer reads the object from a stream, and a newly allocated object is returned to the caller.

IOException  & if an error occurs while reading

void util::Serialization::setStripTemplateParams bool    strip [inline]

The Serialization can be set to ignore template parameters.

That is, all instances of a template class are treated with the same Serializer. If you have MyClass<int> and MyClass<double>, the class name written to and read from a stream must be "MyClass".

strip  if true, template parameters are stripped. The default value is true.

void util::Serialization::writeObject std::ostream &    out,
const Serializable   obj
throw (io::IOException&)

Write an object to a stream.

The referenced object may be any type inherited from Serializable. Its class name is fetched on-line, and a corresponding Serializer is searched. If a Serializer for the class is found, it will be responsible for creating a new object and reading it from a stream.

IOException  & if an error occurs while writing

The documentation for this class was generated from the following files:
Documentation generated on 11.09.2003 with Doxygen.
The documentation is copyrighted material.
Copyright © Topi Mäenpää 2003. All rights reserved.