libglass::SerializableObject Class Reference

#include <serial.h>

List of all members.

Public Member Functions

 SerializableObject ()
virtual ~SerializableObject ()
virtual const stringname (void) const =0
virtual SerializableObjectcreate () const =0 throw (Exception)
virtual SerializableObjectcreate (const chain &s) const =0 throw (Exception)
virtual bool pack (chain &c)=0
virtual bool unpack (const chain &c)=0


Detailed Description

Object serialization abstract base class.

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());

See also:
RegisterObject.

Definition at line 85 of file serial.h.


Constructor & Destructor Documentation

libglass::SerializableObject::SerializableObject (  )  [inline]

Definition at line 87 of file serial.h.

virtual libglass::SerializableObject::~SerializableObject (  )  [inline, virtual]

Virtual destructor.

Definition at line 92 of file serial.h.


Member Function Documentation

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.

Parameters:
s A serialized object

virtual SerializableObject* libglass::SerializableObject::create (  )  const throw (Exception) [pure virtual]

Virtual constructor.

Returns:
A new object of your class.

virtual const string* libglass::SerializableObject::name ( void   )  const [pure virtual]

A portable RTTI.

Returns:
A pointer to a unique name; usually the name of your class.

virtual bool libglass::SerializableObject::pack ( chain c  )  [pure virtual]

Serialization function.

Returns:
The object, serialized to a string.

virtual bool libglass::SerializableObject::unpack ( const chain c  )  [pure virtual]

Unserialization function.

Parameters:
c The serialized object.
Return values:
true if unserialization was successful.
false otherwise.


The documentation for this class was generated from the following file:

Generated on Fri May 28 13:19:01 2010 for libGlass by  doxygen 1.5.8