BALL
1.4.79
|
#include <BALL/CONCEPT/persistenceManager.h>
Public Types | |
Type Definitions | |
typedef void *(* | CreateMethod )() |
Public Member Functions | |
Constructors and Destructors | |
PersistenceManager () | |
PersistenceManager (const PersistenceManager &pm) | |
PersistenceManager (::std::istream &is) | |
PersistenceManager (::std::ostream &os) | |
PersistenceManager (::std::istream &is,::std::ostream &os) | |
virtual | ~PersistenceManager () |
Layer 2 commands | |
virtual void | registerClass (String signature, const CreateMethod m) |
virtual void * | createObject (String signature) const |
virtual Size | getNumberOfClasses () const |
virtual void | setOstream (::std::ostream &s) |
virtual void | setIstream (::std::istream &s) |
void | startOutput () |
void | endOutput () |
PersistentObject * | readObject () |
PersistenceManager & | operator<< (const PersistentObject &object) |
PersistenceManager & | operator>> (PersistentObject *&object_ptr) |
Layer 1 methods | |
template<typename T > | |
bool | checkObjectHeader (const T &, const char *name=0) |
bool | checkObjectHeader (const char *type_name) |
template<typename T > | |
void | writeObjectHeader (const T *object, const char *name=0) |
void | writeObjectTrailer (const char *name=0) |
bool | checkObjectTrailer (const char *name=0) |
template<typename T > | |
void | writePrimitive (const T &t, const char *name) |
template<typename T > | |
bool | readPrimitive (T &t, const char *name) |
template<typename T > | |
void | writeStorableObject (const T &t, const char *name) |
template<typename T > | |
bool | readStorableObject (T &t, const char *name) |
template<typename T > | |
void | writeObjectPointer (const T *object, const char *name) |
template<typename T > | |
bool | readObjectPointer (T *&object, const char *name) |
template<typename T > | |
bool | readObjectSmartPointer (boost::shared_ptr< T > &s_ptr, const char *name) |
template<typename T > | |
void | writeObjectReference (const T &object, const char *name) |
template<typename T > | |
bool | readObjectReference (T &object, const char *name) |
template<typename T > | |
void | writeObjectArray (const T *array, const char *name, Size size) |
template<typename T > | |
bool | readObjectArray (const T *array, const char *name, Size &size) |
template<typename T > | |
void | writeObjectPointerArray (T **arr, const char *name, const Size size) |
template<typename T > | |
bool | readObjectPointerArray (T **array, const char *name, Size &size) |
Layer 0 methods | |
virtual void | writeHeader (const char *type_name, const char *name, LongSize ptr)=0 |
virtual bool | checkHeader (const char *type_name, const char *name, LongSize &ptr)=0 |
virtual void | writeTrailer (const char *name=0)=0 |
virtual bool | checkTrailer (const char *name=0)=0 |
virtual void | writeStreamHeader ()=0 |
virtual void | writeStreamTrailer ()=0 |
virtual bool | checkStreamHeader ()=0 |
virtual bool | checkStreamTrailer ()=0 |
virtual bool | getObjectHeader (String &type_name, LongSize &ptr)=0 |
virtual void | writeName (const char *name)=0 |
virtual bool | checkName (const char *name)=0 |
virtual void | writeStorableHeader (const char *type_name, const char *name)=0 |
virtual bool | checkStorableHeader (const char *type_name, const char *name)=0 |
virtual void | writeStorableTrailer ()=0 |
virtual bool | checkStorableTrailer ()=0 |
virtual void | writePrimitiveHeader (const char *type_name, const char *name)=0 |
virtual bool | checkPrimitiveHeader (const char *type_name, const char *name)=0 |
virtual void | writePrimitiveTrailer ()=0 |
virtual bool | checkPrimitiveTrailer ()=0 |
virtual void | writeObjectPointerHeader (const char *type_name, const char *name)=0 |
virtual bool | checkObjectPointerHeader (const char *type_name, const char *name)=0 |
virtual void | writeObjectReferenceHeader (const char *type_name, const char *name)=0 |
virtual bool | checkObjectReferenceHeader (const char *type_name, const char *name)=0 |
virtual void | writeObjectPointerArrayHeader (const char *type_name, const char *name, Size size)=0 |
virtual bool | checkObjectPointerArrayHeader (const char *type_name, const char *name, Size &size)=0 |
virtual void | writeObjectPointerArrayTrailer ()=0 |
virtual bool | checkObjectPointerArrayTrailer ()=0 |
virtual void | initializeOutputStream () |
virtual void | finalizeOutputStream () |
virtual void | initializeInputStream () |
virtual void | finalizeInputStream () |
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 |
virtual void | put (const Byte c)=0 |
virtual void | put (const Index i)=0 |
virtual void | put (const Size p)=0 |
virtual void | put (const bool b)=0 |
virtual void | put (const Real f)=0 |
virtual void | put (const DoubleReal d)=0 |
virtual void | put (const string &s)=0 |
virtual void | put (const LongSize p)=0 |
Get methods for primitive data types. | |
virtual void | get (char &c)=0 |
virtual void | get (Byte &b)=0 |
virtual void | get (Index &s)=0 |
virtual void | get (Size &s)=0 |
virtual void | get (bool &b)=0 |
virtual void | get (Real &f)=0 |
virtual void | get (DoubleReal &d)=0 |
virtual void | get (string &s)=0 |
virtual void | get (LongSize &p)=0 |
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 |
typedef std::list< std::pair < boost::shared_ptr < PersistentObject > *, LongSize > > | SmartPointerList |
Protected Member Functions | |
void | registerKernelClasses_ () |
void | addPointerPair_ (LongSize old_ptr, void *new_ptr) |
void | addNeededObjects_ () |
bool | updatePointers_ () |
Protected Attributes | |
StringHashMap< CreateMethod > | create_methods_ |
ObjectSet | object_out_ |
ObjectList | object_out_needed_ |
PointerMap | pointer_map_ |
PointerList | pointer_list_ |
SmartPointerList | smart_pointer_list_ |
ObjectList | object_in_ |
::std::ostream * | ostr_ |
::std::istream * | istr_ |
Persistence manager class. 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:
Definition at line 72 of file persistenceManager.h.
typedef void*(* BALL::PersistenceManager::CreateMethod)() |
Create method type. This type describes a method to dynamically create a specific object. It should return a void
pointer for interface compatibility and doesn't take an argument. It creates a new object and returns the object's this
pointer (cast to void*
). The getNew function (in the RTTI namespace) is an example for such a method.
Definition at line 91 of file persistenceManager.h.
|
protected |
Definition at line 746 of file persistenceManager.h.
|
protected |
Definition at line 742 of file persistenceManager.h.
|
protected |
Definition at line 754 of file persistenceManager.h.
|
protected |
Definition at line 750 of file persistenceManager.h.
|
protected |
Definition at line 758 of file persistenceManager.h.
BALL::PersistenceManager::PersistenceManager | ( | ) |
Default constructor
BALL::PersistenceManager::PersistenceManager | ( | const PersistenceManager & | pm | ) |
Copy constructor
BALL::PersistenceManager::PersistenceManager | ( | ::std::istream & | is | ) |
Detailed constructor with an input stream. Creates a persistence manager object and assigns an input stream.
BALL::PersistenceManager::PersistenceManager | ( | ::std::ostream & | os | ) |
Detailed constructor with an output stream. Creates a persistence manager object and assigns an output stream.
BALL::PersistenceManager::PersistenceManager | ( | ::std::istream & | is, |
::std::ostream & | os | ||
) |
Detailed constructor with an input stream and an output stream. Creates a persistence manager object and assigns an input stream and an output stream.
|
virtual |
Destructor. Destruct the persistence manager and and clear up all data structures. The associated streams or sockets ( setIStream / setOStream ) are not closed.
|
protected |
|
protected |
|
pure virtual |
Check an object header.
type_name | the stream name of the class to be read |
name | the expected name of the object |
ptr | a reference to a PointerSizeUInt to store the this pointer of the object read from the stream |
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Check for variable/member name.
name | the name we want to check |
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
bool BALL::PersistenceManager::checkObjectHeader | ( | const T & | , |
const char * | name = 0 |
||
) |
Check an object header by determining its stream name by using
object | an Object of type T |
name | the expected name of the object |
Definition at line 800 of file persistenceManager.h.
bool BALL::PersistenceManager::checkObjectHeader | ( | const char * | type_name | ) |
Check an object header by supplying its stream name.
type_name | the stream name of the object type |
|
pure virtual |
Check for header for an array of pointers to PersistentObjects.
type_name | the stream name of the object type |
name | the name of the object array (?) |
size | the size of the array |
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Check for trailer for an array of pointers to PersistentObjects.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Check for header for a pointer to a PersistentObject.
type_name | the stream name of the object type |
name | the name of the object |
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Check for header for a reference to a PersistentObject.
type_name | the stream name of the object type |
name | the name of the object |
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
bool BALL::PersistenceManager::checkObjectTrailer | ( | const char * | name = 0 | ) |
|
pure virtual |
Check for a type header and name for a primitive type.
type_name | the stream name of the primitive |
name | the name of the primitive |
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Check for the trailer of a primitive type.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Check for storable object header.
type_name | the stream name of the storable object |
name | the name of the object |
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Check for the trailer of a storable object.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Check for the start marker in the input stream.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Check for the end marker in the output stream.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Check an object trailer. This method checks the trailer of an object.
name | the name of the object |
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
virtual |
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.
signature | the class signature of the object to be created |
void BALL::PersistenceManager::endOutput | ( | ) |
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.
operator >>
.
|
virtual |
Prepare the input stream for closing.
Reimplemented in BALL::XDRPersistenceManager.
|
virtual |
Prepare the output stream for closing.
Reimplemented in BALL::XDRPersistenceManager.
|
pure virtual |
Read a signed char from the input stream.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Read a single Byte from the input stream.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Read an Index from the input stream.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Read a Size or a Position from the input stream.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Read a boolean value from the input stream.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Read a single precision floating point number from the input stream.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Read a double precision floating point number from the input stream.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Read a string from the output stream.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Read a 64-bit pointer from the input stream.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
virtual |
Return the number of registerd classes.
|
pure virtual |
Get an (unknown) object header. The name (if set) is ignored. The type name is returned in type_name
and the address of the object is read but not inserted into the table.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
virtual |
Prepare the input stream for reading.
Reimplemented in BALL::XDRPersistenceManager.
|
virtual |
Prepare the output stream for output.
Reimplemented in BALL::XDRPersistenceManager.
PersistenceManager& BALL::PersistenceManager::operator<< | ( | const PersistentObject & | object | ) |
Write a persistent object to the stream. This method writes a persistent object to a stream.
PersistenceManager& BALL::PersistenceManager::operator>> | ( | PersistentObject *& | object_ptr | ) |
Read a persistent object from a stream. This method calls readObject .
|
pure virtual |
Write a signed char to the output stream.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Write a single byte to the output stream.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Write an Index to the output stream.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Write a Position or a Size to the output stream.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Write a boolean value to the output stream.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Write a single precision floating point number to the output stream.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Write a double precision floating point number to the output stream.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Write a string to the output.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Write a pointer to the output.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
PersistentObject* BALL::PersistenceManager::readObject | ( | ) |
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.
this
pointer otherwise Exception::GeneralException |
bool BALL::PersistenceManager::readObjectArray | ( | const T * | array, |
const char * | name, | ||
Size & | size | ||
) |
Read an array of persistent objects. This method reads size
persistent objects from the persistent stream. It also checks header and trailer of the array.
array | the array of persistent objects |
name | the name (usually the name of the member variable) |
size | the number of elements in the array |
Definition at line 967 of file persistenceManager.h.
bool BALL::PersistenceManager::readObjectPointer | ( | T *& | object, |
const char * | name | ||
) |
Read a pointer to a PersistentObject. This method also checks header and trailer.
object | a mutable pointer reference we want to read. |
name | the name of the object pointer (usually the name of the member variable) |
Definition at line 871 of file persistenceManager.h.
bool BALL::PersistenceManager::readObjectPointerArray | ( | T ** | array, |
const char * | name, | ||
Size & | size | ||
) |
Read an array of persistent object pointers. This method reads size
persistent object pointers from the persistent stream. It also checks header and trailer of the array.
array | the array of persistent object pointers |
name | the name (usually the name of the member variable) |
size | the number of elements in the array |
Definition at line 1006 of file persistenceManager.h.
bool BALL::PersistenceManager::readObjectReference | ( | T & | object, |
const char * | name | ||
) |
Read a reference to a PersistentObject. This method also checks header and trailer of the object reference.
object | a mutable reference |
name | the name of the object (usually the name of the member variable) |
Definition at line 926 of file persistenceManager.h.
bool BALL::PersistenceManager::readObjectSmartPointer | ( | boost::shared_ptr< T > & | s_ptr, |
const char * | name | ||
) |
Read a smart pointer to a PersistentObject. This method also checks header and trailer, and registers a shared pointer for later updating when an object with corresponding this pointer has been read.
s_ptr | a mutable shared_ptr reference for later update |
ptr | the pointer stub for the this pointer |
Definition at line 892 of file persistenceManager.h.
bool BALL::PersistenceManager::readPrimitive | ( | T & | t, |
const char * | name | ||
) |
Read a primitive member variable. This method also checks header and trailer of the primitive.
t | a mutable reference of the primitive variable |
name | the expected name of the variable |
Definition at line 827 of file persistenceManager.h.
bool BALL::PersistenceManager::readStorableObject | ( | T & | t, |
const char * | name | ||
) |
Read a storable object. This method also checks header and trailer of the object.
t | a mutable reference of the object |
name | the expected name of the object |
Definition at line 849 of file persistenceManager.h.
|
virtual |
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:
Remember to include the baseclasses of each class, too! To register all kernel classes, use the BALL_REGISTER_PERSISTENT_KERNEL_CLASSES macro.
signature | the class signatur |
m | a dynamic class create method |
|
protected |
|
virtual |
Set the input stream for persistent objects.
s | the input stream |
|
virtual |
Set the output stream for persistent objects.
s | the output stream |
void BALL::PersistenceManager::startOutput | ( | ) |
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 .
operator >>
.
|
protected |
|
pure virtual |
Write the header for an object. This method writes the header information containing the class signature, the name and its this pointer
. The name information is required to differentiate between base classes of an object and member objects or the object itself. If writeHeader is called for a base class, name should be set to 0. type_name
should refer to the stream name of an object (see getStreamName ).
name
should be set to ""
. For base classes, name has to be set to 0. The exact behaviour of this method is implementation dependend - it is abstract for PersistenceManager. Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Write a variable/member name.
name | the name we want to write |
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
void BALL::PersistenceManager::writeObjectArray | ( | const T * | array, |
const char * | name, | ||
Size | size | ||
) |
Write an array of persistent objects. This method writes size
persistent objects to the persistent stream. It also writes the necessary header and trailer.
array | the array of persistent objects |
name | the name (usually the name of the member variable) |
size | the number of elements in the array |
Definition at line 952 of file persistenceManager.h.
void BALL::PersistenceManager::writeObjectHeader | ( | const T * | object, |
const char * | name = 0 |
||
) |
Write an object Header. Determine the stream name of the object via
object | a const pointer to the object |
name | the name of the object |
Definition at line 809 of file persistenceManager.h.
void BALL::PersistenceManager::writeObjectPointer | ( | const T * | object, |
const char * | name | ||
) |
Write a pointer to a PersistentObject. This method also writes the necessary header and trailer.
object | a const pointer to the object we want to write |
name | the name of the object pointer (the name of the member variable written) |
Definition at line 857 of file persistenceManager.h.
void BALL::PersistenceManager::writeObjectPointerArray | ( | T ** | arr, |
const char * | name, | ||
const Size | size | ||
) |
Write an array of pointers to persistent objects. This method writes size
persistent objects to the persistent stream. It also writes the necessary header and trailer.
arr | the array of persistent object pointers |
name | the name (usually the name of the member variable) |
size | the number of elements in the array |
Definition at line 986 of file persistenceManager.h.
|
pure virtual |
Write header for an array of pointers to PersistentObjects.
type_name | the stream name of the object type |
name | the name of the object array (?) |
size | the size of the array |
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Write trailer for an array of pointers to PersistentObjects.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Write header for a pointer to a PersistentObject.
type_name | the stream name of the object type |
name | the name of the object |
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
void BALL::PersistenceManager::writeObjectReference | ( | const T & | object, |
const char * | name | ||
) |
Write a reference to a PersistentObject. This method also writes the necessary header and trailer.
object | a const reference to the object |
name | the name of the object (usually the name of the member variable) |
Definition at line 911 of file persistenceManager.h.
|
pure virtual |
Write header for a reference to a PersistentObject.
type_name | the stream name of the object type |
name | the name of the object |
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
void BALL::PersistenceManager::writeObjectTrailer | ( | const char * | name = 0 | ) |
void BALL::PersistenceManager::writePrimitive | ( | const T & | t, |
const char * | name | ||
) |
Write a primitive member variable. This method also writes the necessary header and trailer of the primitive.
t | the variable |
name | the name of the variable |
Definition at line 818 of file persistenceManager.h.
|
pure virtual |
Write type header and name for a primitive type.
type_name | the stream name of the primitive |
name | the name of the primitive |
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Write the trailer for a primitive type.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Write storable object header.
type_name | the stream name of the storable object |
name | the name of the object |
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
void BALL::PersistenceManager::writeStorableObject | ( | const T & | t, |
const char * | name | ||
) |
Write a storable object. This method also writes header and trailer of the object.
t | the storable object |
name | the name of the object |
Definition at line 840 of file persistenceManager.h.
|
pure virtual |
Write the trailer for a storable object.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Write a start marker to the output stream.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Write an end marker to the output stream.
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
pure virtual |
Write the trailer for an object.
name | the name of the object |
Implemented in BALL::XDRPersistenceManager, and BALL::TextPersistenceManager.
|
protected |
Definition at line 762 of file persistenceManager.h.
|
protected |
Definition at line 793 of file persistenceManager.h.
|
protected |
Definition at line 788 of file persistenceManager.h.
|
protected |
Definition at line 767 of file persistenceManager.h.
|
protected |
Definition at line 773 of file persistenceManager.h.
|
protected |
Definition at line 791 of file persistenceManager.h.
|
protected |
Definition at line 782 of file persistenceManager.h.
|
protected |
Definition at line 779 of file persistenceManager.h.
|
protected |
Definition at line 785 of file persistenceManager.h.