Source: fun/Serializable.h
|
|
|
|
// Serializable - base class for objects which can save/restore themselves
// Copyright (C) 2000 rusty, rusty@sgi.com
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef _FUN_SERIALIZABLE_H
#define _FUN_SERIALIZABLE_H
#include
#include
#include
namespace fun {
class Serializer;
class Deserializer;
/**
* Serializable objects can save and restore themselves from Serializers
* and Deserializers.
*
* As a Serializable is a LoadableClass, somewhere in the source file for
* class Foo, you need this line:
*
* INITIALIZER(Foo);
*
* You also want to make sure the serialize() method for the Foo class
* has the line
*
* ser.setSerializableClass("Foo");
*
* after calling any base class serialize() methods.
*
* See Serializer and Deserializer for methods for storing and retrieving
* elements from (S|Des)erializers, and for examples.
*
* Right now, there's no error handling during loading etc.; this should
* throw exceptions.
*/
class Serializable : public LoadableClass
{
public:
Serializable() {}
virtual ~Serializable() {}
/**
* Loads the Serializable object (and any sub-objects) from the given
* Deserializable.
*
* Derived classes should always start by calling the superclass'
* deserialize().
*
THIS IS NONSENSE
* For example, suppose you had a simple XML file:
*
*
* 2
* 17
* Mean/hungry
*
*
* Calling getTreeable("bunny") would cause a new instance of DevilBunny
* to be created (and the class to be loaded from a shared object, if
* necessary), and the new instance would be loaded from the bunny XML
* node. See Treeable for more information, but presumably
* DevilBunny::loadFromTree() would look something like this:
*
* void
* DevilBunnyBox::deserialize(const Deserializer &node)
* {
* Serializable::deserialize(node);
* xpos = node.getInt("xpos");
* ypos = node.getInt("ypos");
* disp = node.getString("disposition");
* // maybe some error checking, or loading other stuff
* }
*/
virtual void deserialize(const Deserializer &) { }
/**
* Stores the Serializable object in the given Serializer.
*
* Derived classes should always start by calling the superclass'
* serialize(). They should also call setSerializableClass() with their
* own class name. NOT_DONE include a simple example here.
*/
virtual void serialize(Serializer &) const { }
};
} // namespace fun
#endif // _FUN_SERIALIZABLE_H
| Generated by: stephan on cheyenne on Mon Aug 11 14:06:52 2003, using kdoc 2.0a54. |