#include <serial.h>
Public Member Functions | |
SerializableObject () | |
virtual | ~SerializableObject () |
virtual const string * | name (void) const =0 |
virtual SerializableObject * | create () const =0 throw (Exception) |
virtual SerializableObject * | create (const chain &s) const =0 throw (Exception) |
virtual bool | pack (chain &c)=0 |
virtual bool | unpack (const chain &c)=0 |
Glass has to serialize objects to send them to other nodes. If you derive your class SerializableObject, plugins that use serialization will work easily with your class, and you'll have better control of the process.
Your class must also declare a static RegisterObject. Here's how your class should look like:
class YourClass : public SerializableObject { private: // your data goes here static RegisterObject ro; public: // your constructor and public methods. const string *name(void) const { static const string name = string("YourClass"); return &name; } SerializableObject *create() const throw(Exception) { return new YourClass(); } SerializableObject *create(const chain &c) const throw(Exception) { YourClass *t = new YourClass(); if (t->unpack(c) == false) { throw Exception("Error unserializing"); } return t; } bool pack(chain &c) { // your serialization method return true; } bool unpack(const chain &c) { // your serialization method return true; } }; RegisterObject YourClass::ro = RegisterObject(new YourClass());
Definition at line 85 of file serial.h.
libglass::SerializableObject::SerializableObject | ( | ) | [inline] |
virtual libglass::SerializableObject::~SerializableObject | ( | ) | [inline, virtual] |
virtual SerializableObject* libglass::SerializableObject::create | ( | const chain & | s | ) | const throw (Exception) [pure virtual] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
s | A serialized object |
virtual SerializableObject* libglass::SerializableObject::create | ( | ) | const throw (Exception) [pure virtual] |
Virtual constructor.
virtual const string* libglass::SerializableObject::name | ( | void | ) | const [pure virtual] |
A portable RTTI.
virtual bool libglass::SerializableObject::pack | ( | chain & | c | ) | [pure virtual] |
Serialization function.
virtual bool libglass::SerializableObject::unpack | ( | const chain & | c | ) | [pure virtual] |
Unserialization function.
c | The serialized object. |
true | if unserialization was successful. | |
false | otherwise. |