#include <persistenceManager.h>
Inheritance diagram for PersistenceManager:
Public Types | |
Type Definitions | |
typedef void *(* | CreateMethod )() |
Create method type. | |
Public Member Functions | |
Constructors and Destructors | |
PersistenceManager () throw () | |
Default constructor. | |
PersistenceManager (const PersistenceManager &pm) throw () | |
Copy constructor. | |
PersistenceManager (::std::istream &is) throw () | |
Detailed constructor with an input stream. | |
PersistenceManager (::std::ostream &os) throw () | |
Detailed constructor with an output stream. | |
PersistenceManager (::std::istream &is,::std::ostream &os) throw () | |
Detailed constructor with an input stream and an output stream. | |
virtual | ~PersistenceManager () throw () |
Destructor. | |
Layer 2 commands | |
virtual void | registerClass (String signature, const CreateMethod m) throw () |
Register a create method for a class. | |
virtual void * | createObject (String signature) const throw () |
Create an object of a registered class. | |
virtual Size | getNumberOfClasses () const throw () |
Return the number of registerd classes. | |
virtual void | setOstream (::std::ostream &s) throw () |
Set the output stream for persistent objects. | |
virtual void | setIstream (::std::istream &s) throw () |
Set the input stream for persistent objects. | |
void | startOutput () throw () |
Start the output to a persistent stream. | |
void | endOutput () throw () |
Terminate the output to a persistent stream. | |
PersistentObject * | readObject () throw (Exception::GeneralException) |
Read a persistent object from the stream. | |
PersistenceManager & | operator<< (const PersistentObject &object) throw () |
Write a persistent object to the stream. | |
PersistenceManager & | operator>> (PersistentObject *&object_ptr) throw () |
Read a persistent object from a stream. | |
Layer 1 methods | |
template<typename T> | |
bool | checkObjectHeader (const T &, const char *name=0) throw () |
Check an object header by determining its stream name by using. | |
bool | checkObjectHeader (const char *type_name) throw () |
Check an object header by supplying its stream name. | |
template<typename T> | |
void | writeObjectHeader (const T *object, const char *name=0) throw () |
Write an object Header. | |
void | writeObjectTrailer (const char *name=0) throw () |
Write an object trailer by calling. | |
bool | checkObjectTrailer (const char *name=0) throw () |
Check an object trailer by calling. | |
template<typename T> | |
void | writePrimitive (const T &t, const char *name) throw () |
Write a primitive member variable. | |
template<typename T> | |
bool | readPrimitive (T &t, const char *name) throw () |
Read a primitive member variable. | |
template<typename T> | |
void | writeStorableObject (const T &t, const char *name) throw () |
Write a storable object. | |
template<typename T> | |
bool | readStorableObject (T &t, const char *name) throw () |
Read a storable object. | |
template<typename T> | |
void | writeObjectPointer (const T *object, const char *name) throw () |
Write a pointer to a PersistentObject. | |
template<typename T> | |
bool | readObjectPointer (T *&object, const char *name) throw () |
Read a pointer to a PersistentObject. | |
template<typename T> | |
void | writeObjectReference (const T &object, const char *name) throw () |
Write a reference to a PersistentObject. | |
template<typename T> | |
bool | readObjectReference (T &object, const char *name) throw () |
Read a reference to a PersistentObject. | |
template<typename T> | |
void | writeObjectArray (const T *array, const char *name, Size size) throw () |
Write an array of persistent objects. | |
template<typename T> | |
bool | readObjectArray (const T *array, const char *name, Size &size) throw () |
Read an array of persistent objects. | |
template<typename T> | |
void | writeObjectPointerArray (T **arr, const char *name, const Size size) throw () |
Write an array of pointers to persistent objects. | |
template<typename T> | |
bool | readObjectPointerArray (T **array, const char *name, Size &size) throw () |
Read an array of persistent object pointers. | |
Layer 0 methods | |
virtual void | writeHeader (const char *type_name, const char *name, LongSize ptr)=0 |
Write the header for an object. | |
virtual bool | checkHeader (const char *type_name, const char *name, LongSize &ptr)=0 |
Check an object header. | |
virtual void | writeTrailer (const char *name=0)=0 |
Write the trailer for an object. | |
virtual bool | checkTrailer (const char *name=0)=0 |
Check an object trailer. | |
virtual void | writeStreamHeader ()=0 |
Write a start marker to the output stream. | |
virtual void | writeStreamTrailer ()=0 |
Write an end marker to the output stream. | |
virtual bool | checkStreamHeader ()=0 |
Check for the start marker in the input stream. | |
virtual bool | checkStreamTrailer ()=0 |
Check for the end marker in the output stream. | |
virtual bool | getObjectHeader (String &type_name, LongSize &ptr)=0 |
Get an (unknown) object header. | |
virtual void | writeName (const char *name)=0 |
Write a variable/member name. | |
virtual bool | checkName (const char *name)=0 |
Check for variable/member name. | |
virtual void | writeStorableHeader (const char *type_name, const char *name)=0 |
Write storable object header. | |
virtual bool | checkStorableHeader (const char *type_name, const char *name)=0 |
Check for storable object header. | |
virtual void | writeStorableTrailer ()=0 |
Write the trailer for a storable object. | |
virtual bool | checkStorableTrailer ()=0 |
Check for the trailer of a storable object. | |
virtual void | writePrimitiveHeader (const char *type_name, const char *name)=0 |
Write type header and name for a primitive type. | |
virtual bool | checkPrimitiveHeader (const char *type_name, const char *name)=0 |
Check for a type header and name for a primitive type. | |
virtual void | writePrimitiveTrailer ()=0 |
Write the trailer for a primitive type. | |
virtual bool | checkPrimitiveTrailer ()=0 |
Check for the trailer of a primitive type. | |
virtual void | writeObjectPointerHeader (const char *type_name, const char *name)=0 |
Write header for a pointer to a PersistentObject. | |
virtual bool | checkObjectPointerHeader (const char *type_name, const char *name)=0 |
Check for header for a pointer to a PersistentObject. | |
virtual void | writeObjectReferenceHeader (const char *type_name, const char *name)=0 |
Write header for a reference to a PersistentObject. | |
virtual bool | checkObjectReferenceHeader (const char *type_name, const char *name)=0 |
Check for header for a reference to a PersistentObject. | |
virtual void | writeObjectPointerArrayHeader (const char *type_name, const char *name, Size size)=0 |
Write header for an array of pointers to PersistentObjects. | |
virtual bool | checkObjectPointerArrayHeader (const char *type_name, const char *name, Size &size)=0 |
Check for header for an array of pointers to PersistentObjects. | |
virtual void | writeObjectPointerArrayTrailer ()=0 |
Write trailer for an array of pointers to PersistentObjects. | |
virtual bool | checkObjectPointerArrayTrailer ()=0 |
Check for trailer for an array of pointers to PersistentObjects. | |
virtual void | initializeOutputStream () throw () |
Prepare the output stream for output. | |
virtual void | finalizeOutputStream () throw () |
Prepare the output stream for closing. | |
virtual void | initializeInputStream () throw () |
Prepare the input stream for reading. | |
virtual void | finalizeInputStream () throw () |
Prepare the input stream for closing. | |
Put methods for primitive data types. | |
Persistence in BALL supports the following predefined data types: {tabular}{lcc} Name & signed/unsigned & Size (in bit)
| |
virtual void | put (const char c)=0 |
Write a signed char to the output stream. | |
virtual void | put (const Byte c)=0 |
Write a single byte to the output stream. | |
virtual void | put (const Index i)=0 |
Write an Index to the output stream. | |
virtual void | put (const Size p)=0 |
Write a Position or a Size to the output stream. | |
virtual void | put (const bool b)=0 |
Write a boolean value to the output stream. | |
virtual void | put (const Real f)=0 |
Write a single precision floating point number to the output stream. | |
virtual void | put (const DoubleReal d)=0 |
Write a double precision floating point number to the output stream. | |
virtual void | put (const string &s)=0 |
Write a string to the output. | |
virtual void | put (const LongSize p)=0 |
Write a pointer to the output. | |
Get methods for primitive data types. | |
virtual void | get (char &c)=0 |
Read a signed char from the input stream. | |
virtual void | get (Byte &b)=0 |
Read a single Byte from the input stream. | |
virtual void | get (Index &s)=0 |
Read an Index from the input stream. | |
virtual void | get (Size &s)=0 |
Read a Size or a Position from the input stream. | |
virtual void | get (bool &b)=0 |
Read a boolean value from the input stream. | |
virtual void | get (Real &f)=0 |
Read a single precision floating point number from the input stream. | |
virtual void | get (DoubleReal &d)=0 |
Read a double precision floating point number from the input stream. | |
virtual void | get (string &s)=0 |
Read a string from the output stream. | |
virtual void | get (LongSize &p)=0 |
Read a 64-bit pointer from the input stream. | |
Protected Types | |
typedef HashSet< const PersistentObject * > | ObjectSet |
typedef std::list< const PersistentObject * > | ObjectList |
typedef HashMap< LongSize, void * > | PointerMap |
typedef std::list< std::pair< void **, LongSize > > | PointerList |
Protected Member Functions | |
void | registerKernelClasses_ () throw () |
void | addPointerPair_ (LongSize old_ptr, void *new_ptr) throw () |
void | addNeededObjects_ () throw (Exception::GeneralException) |
bool | updatePointers_ () throw () |
Protected Attributes | |
StringHashMap< CreateMethod > | create_methods_ |
ObjectSet | object_out_ |
ObjectList | object_out_needed_ |
PointerMap | pointer_map_ |
PointerList | pointer_list_ |
ObjectList | object_in_ |
::std::ostream * | ostr_ |
::std::istream * | istr_ |
This class serializes and deserializes persistent objects and provides support for the implementation of the object-specific serialization methods persistentRead and persistentWrite . It defines three different layers:
|
Create method type.
This type describes a method to dynamically create a specific object. It should return a
|
|
Detailed constructor with an input stream. Creates a persistence manager object and assigns an input stream. |
|
Detailed constructor with an output stream. Creates a persistence manager object and assigns an output stream. |
|
Detailed constructor with an input stream and an output stream. Creates a persistence manager object and assigns an input stream and an output stream. |
|
Destructor. Destruct the persistence manager and and clear up all data structures. The associated streams or sockets ( setIStream / setOStream ) are not closed. |
|
Check an object header.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Check for variable/member name.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Check an object header by supplying its stream name.
|
|
Check an object header by determining its stream name by using.
|
|
Check for header for an array of pointers to PersistentObjects.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Check for trailer for an array of pointers to PersistentObjects.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Check for header for a pointer to a PersistentObject.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Check for header for a reference to a PersistentObject.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Check an object trailer by calling.
|
|
Check for a type header and name for a primitive type.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Check for the trailer of a primitive type.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Check for storable object header.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Check for the trailer of a storable object.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Check for the start marker in the input stream.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Check for the end marker in the output stream.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Check an object trailer. This method checks the trailer of an object.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Create an object of a registered class. If the persistence manager has registered a create method for the given class signature, the corresponding create method is called and its result is returned. If the class is not registered, 0 is returned.
|
|
Terminate the output to a persistent stream. This method finishes the writing of a persistent object to a stream. In fact, it does most of the work. It checks for the list of "missing" objects, i.e. objects that have been referenced via a pointer or a reference by the objects written before and calls their persistent write methods. It then writes an end marker to the file (via writeStreamTrailer) and clears the pending output list.
|
|
Prepare the input stream for closing.
Reimplemented in XDRPersistenceManager. |
|
Prepare the output stream for closing.
Reimplemented in XDRPersistenceManager. |
|
Read a 64-bit pointer from the input stream.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Read a string from the output stream.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Read a double precision floating point number from the input stream.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Read a single precision floating point number from the input stream.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Read a boolean value from the input stream.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Read a Size or a Position from the input stream.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Read an Index from the input stream.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Read a single Byte from the input stream.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Read a signed char from the input stream.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Return the number of registerd classes.
|
|
Get an (unknown) object header.
The name (if set) is ignored. The type name is returned in Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Prepare the input stream for reading.
Reimplemented in XDRPersistenceManager. |
|
Prepare the output stream for output.
Reimplemented in XDRPersistenceManager. |
|
Write a persistent object to the stream. This method writes a persistent object to a stream. |
|
Read a persistent object from a stream. This method calls readObject . |
|
Write a pointer to the output.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Write a string to the output.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Write a double precision floating point number to the output stream.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Write a single precision floating point number to the output stream.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Write a boolean value to the output stream.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Write a Position or a Size to the output stream.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Write an Index to the output stream.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Write a single byte to the output stream.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Write a signed char to the output stream.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Read a persistent object from the stream. This method tries to read a persistent object from the stream, creates the object and all dependend objects, finally demangles all pointers and references.
|
|
Read an array of persistent objects.
This method reads
|
|
Read a pointer to a PersistentObject. This method also checks header and trailer.
|
|
Read an array of persistent object pointers.
This method reads
|
|
Read a reference to a PersistentObject. This method also checks header and trailer of the object reference.
|
|
Read a primitive member variable. This method also checks header and trailer of the primitive.
|
|
Read a storable object. This method also checks header and trailer of the object.
|
|
Register a create method for a class. Each object read by the persistence manager has to be constructed somehow. The persistence manager first reads a class' signature (i.e. a unique identifier in the context of this stream). This is usually the stream name of the class (see getStreamName ), but can be an arbitrary string (without blanks). When reading an object header with a given class signature, the persistence manager tries to find a method to create an instance of this object. For this purpose it contains a StringHashMap object. Each of the classes to be read has to be contained in this hash map together with a method to create an instance of this object. This is done by calling registerClass. The create method is usually the getNew method for a class: PersistenceManager pm; pm.registerClass(RTTI::getStreamName<Atom>(), RTTI::getNew<Atom>); pm.registerClass(RTTI::getStreamName<Composite>(), RTTI::getNew<Composite>);
|
|
Set the input stream for persistent objects.
|
|
Set the output stream for persistent objects.
|
|
Start the output to a persistent stream. This method write a start marker to the output stream and prepares the stream and the persistence manager's internal data structures for the output of an object. The start marker is written via the method writeStreamHeader .
|
|
Write the header for an object.
This method writes the header information containing the class signature, the name and its
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Write a variable/member name.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Write an array of persistent objects.
This method writes
|
|
Write an object Header. Determine the stream name of the object via
|
|
Write a pointer to a PersistentObject. This method also writes the necessary header and trailer.
|
|
Write an array of pointers to persistent objects.
This method writes
|
|
Write header for an array of pointers to PersistentObjects.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Write trailer for an array of pointers to PersistentObjects.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Write header for a pointer to a PersistentObject.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Write a reference to a PersistentObject. This method also writes the necessary header and trailer.
|
|
Write header for a reference to a PersistentObject.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Write an object trailer by calling.
|
|
Write a primitive member variable. This method also writes the necessary header and trailer of the primitive.
|
|
Write type header and name for a primitive type.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Write the trailer for a primitive type.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Write storable object header.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Write a storable object. This method also writes header and trailer of the object.
|
|
Write the trailer for a storable object.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Write a start marker to the output stream.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Write an end marker to the output stream.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |
|
Write the trailer for an object.
Implemented in TextPersistenceManager, and XDRPersistenceManager. |