#include <Serialization.h>
A Serializable class must be accompanied with a Serializer in order to be dynamically serializable. A convenient way of creating the serializer is an inner class:
class MyClass : public Serializable
{
public:
class Serializer;
...
};
class MyClass::Serializer : public util::Serializer
{
public:
void writeToStream(ostream& out, const Serializable& obj) throw (IOException&);
Serializable* readFromStream(istream& in) throw (IOException&);
};
Now you'll be able to use MyClass::Serializer as a serializer for MyClass.
Public Methods | |
| virtual void | writeToStream (std::ostream &out, const Serializable &obj)=0 throw (io::IOException&) |
| Write an object to a stream. | |
| virtual Serializable * | readFromStream (std::istream &in)=0 throw (io::IOException&) |
| Read an object from a stream. | |
|
|
Read an object from a stream. This method should return a pointer to a newly allocated object whose contents were read from the given stream by using a stream operator, for example.
|
|
||||||||||||
|
Write an object to a stream. This method shoud write the contents of an object to the given stream by using a stream operator, for example. Note that the data output to stream must always be started with a fully-qualified class name (namespace::class). One may want to use Util::getClassName to make the class name correctly formatted.
|