ThePEG 2.3.0
|
PersistentOStream is used to write objects persistently to a stream from which they can be read in again with a PersistentIStream. More...
#include <PersistentOStream.h>
Public Types | |
typedef ThePEG::Ptr< PersistentBase >::pointer | BPtr |
Alias for a reference counted pointer to PersistentBase . | |
typedef ThePEG::Ptr< PersistentBase >::const_pointer | cBPtr |
Alias for a reference counted pointer to a const PersistentBase . | |
typedef ThePEG::Ptr< PersistentBase >::transient_pointer | tBPtr |
Alias for a transient pointer to PersistentBase . | |
typedef ThePEG::Ptr< PersistentBase >::transient_const_pointer | tcBPtr |
Alias for a transient pointer to a const PersistentBase . | |
typedef map< cBPtr, int, less< cBPtr > > | ObjectMap |
A map of objects indexed by integers. | |
typedef map< const ClassDescriptionBase *, int, less< const ClassDescriptionBase * > > | ClassMap |
A map relating class descriptions to integers. | |
typedef ClassDescriptionBase::DescriptionVector | DescriptionVector |
A vector of bare pointers to InputDescription objects. | |
Public Member Functions | |
PersistentOStream (ostream &, const vector< string > &libs=vector< string >()) | |
Constuctor giving an output stream. | |
PersistentOStream (string, const vector< string > &libs=vector< string >()) | |
Constuctor giving a file name to read. | |
~PersistentOStream () | |
The destructor. | |
template<typename T > | |
PersistentOStream & | operator<< (const RCPtr< T > &p) |
Operator for writing persistent objects to the stream. | |
template<typename T > | |
PersistentOStream & | operator<< (const ConstRCPtr< T > &p) |
Operator for writing persistent objects to the stream. | |
template<typename T > | |
PersistentOStream & | operator<< (const TransientRCPtr< T > &p) |
Operator for writing persistent objects to the stream. | |
template<typename T > | |
PersistentOStream & | operator<< (const TransientConstRCPtr< T > &p) |
Operator for writing persistent objects to the stream. | |
Operators for extracting built-in types from the stream. | |
static const int | version = 0 |
The version of this PersistentOStream implementation. | |
static const int | subVersion = 3 |
The subversion of this PersistentOStream implementation. | |
PersistentOStream & | operator<< (string s) |
Write a character string. | |
PersistentOStream & | operator<< (char c) |
Write a character. | |
PersistentOStream & | operator<< (signed char c) |
Write a signed character. | |
PersistentOStream & | operator<< (unsigned char c) |
Write an unsigned character. | |
PersistentOStream & | operator<< (int i) |
Write an integer. | |
PersistentOStream & | operator<< (unsigned int i) |
Write an unsigned integer. | |
PersistentOStream & | operator<< (long i) |
Write a long integer. | |
PersistentOStream & | operator<< (unsigned long i) |
Write an unsigned long integer. | |
PersistentOStream & | operator<< (short i) |
Write a short integer. | |
PersistentOStream & | operator<< (unsigned short i) |
Write an unsigned short integer. | |
PersistentOStream & | operator<< (double d) |
Write a double. | |
PersistentOStream & | operator<< (float f) |
Write a float. | |
PersistentOStream & | operator<< (bool t) |
Write a boolean. | |
PersistentOStream & | operator<< (const char *s) |
Write a c-style character string (to be read in as a std::string). | |
PersistentOStream & | operator<< (Complex z) |
Write a Complex. | |
template<typename Container > | |
void | putContainer (const Container &c) |
Output of containers of streamable objects. | |
PersistentOStream & | outputPointer (tcBPtr) |
Write out a persistent object given a pointer to it. | |
void | putObjectPart (tcBPtr obj, const ClassDescriptionBase *cd) |
For a given object, write the member variables corresponding to a given ClassDescriptionBase object. | |
PersistentOStream & | flush () |
Remove all objects that have been written, except those which are to be saved, from the list of written objects. | |
PersistentOStream & | push () |
Instuct the stream to save the following objects (protecting them from being flushed). | |
PersistentOStream & | pop () |
Instuct the stream not to save the following objects. | |
bool | good () const |
Check the state of the stream. | |
operator bool () const | |
Check the state of the stream. | |
bool | operator! () const |
Check the state of the stream. | |
Special marker characters | |
static const char | tBegin = '{' |
The special marker character indicating the beginning of an object. | |
static const char | tEnd = '}' |
The special marker character indicating the end of an object. | |
static const char | tNext = '|' |
The marker character indicating the beginning of the next base class in case of multiple inheritance. | |
static const char | tNull = '\\' |
The special marker character indicating an escaped marker character. | |
static const char | tSep = '\n' |
The special marker character indicating the end of a value. | |
static const char | tNoSep = 'n' |
The special marker character used to avoid confusion with escaped tSep markers. | |
static const char | tYes = 'y' |
The special marker character indicating a true boolean value. | |
static const char | tNo = 'n' |
The special marker character indicating a false boolean value. | |
ObjectMap | writtenObjects |
List of written objects. | |
stack< int > | lastSavedObject |
List of written objects that are to be saved. | |
ClassMap | writtenClasses |
List of written classes. | |
ostream * | theOStream |
A pointer to the associated ostream. | |
bool | badState |
True if no errors has occurred. | |
bool | allocStream |
True if the associated ostream should be deleted in the destructor. | |
bool | isToken (char c) const |
Return true if the given character is aspecial marker character. | |
void | setBadState () |
Set the stream in a bad state. | |
void | checkState () |
Check if the state is ok. | |
const ClassDescriptionBase * | writeClassId (tcBPtr) |
Write out class information to the associated ostream. | |
void | writeClassDescription (const ClassDescriptionBase *) |
write out class information to the associated ostream. | |
void | beginObject () |
Put a "begin object" marker on the associated ostream. | |
void | endObject () |
Put a "end of object" marker on the associated ostream. | |
void | endBase () |
Put an "next base class" marker on the associated ostream. | |
void | put (char c) |
Put a character on the associated ostream. | |
void | escape (char c) |
Put a character on the associated ostream but escape it if it is a token. | |
ostream & | os () |
Return a reference to the associated ostream. | |
const ostream & | os () const |
Return a const reference to the associated ostream. | |
void | init (const vector< string > &libs) |
Write out initial metainfo on the stream. | |
PersistentOStream () | |
Standard ctors and assignment are private and not implemented. | |
PersistentOStream (const PersistentOStream &) | |
Standard ctors and assignment are private and not implemented. | |
PersistentOStream & | operator= (const PersistentOStream &)=delete |
Standard ctors and assignment are private and not implemented. | |
PersistentOStream is used to write objects persistently to a stream from which they can be read in again with a PersistentIStream.
Pointers to objects of classes derived from PersistentBase
may be written out if a static ClassDescription object is present for the class. Also basic types may be written to the stream, as well as containers of pointers to persistent objects and basic types.
The PersistentOStream
keeps a list of all pointers to written persistent objects, so that if several pointers to the smame object is written, the object will only be written once.
Each base class of a given object will be asked to write its members to the stream starting from the least derived class going to the most derived one. Members may be pointers to other persistent objects or basic types or containers of these. The output for each object part should be implemented by specializing the ClassTraits<T>::output method, which otherwise will call the non-virtual persistentOutput
function of the class. Note that for diamond-shaped multiple inheritance structures, the virtual base classes will be written out several times for the same object.
Definition at line 51 of file PersistentOStream.h.
typedef ThePEG::Ptr<PersistentBase>::pointer ThePEG::PersistentOStream::BPtr |
Alias for a reference counted pointer to PersistentBase .
Definition at line 55 of file PersistentOStream.h.
typedef ThePEG::Ptr<PersistentBase>::const_pointer ThePEG::PersistentOStream::cBPtr |
Alias for a reference counted pointer to a const PersistentBase .
Definition at line 55 of file PersistentOStream.h.
typedef map< const ClassDescriptionBase * , int , less< const ClassDescriptionBase * > > ThePEG::PersistentOStream::ClassMap |
A map relating class descriptions to integers.
A map of int indexed by const ClassDescriptionBase * .
Definition at line 61 of file PersistentOStream.h.
A vector of bare pointers to InputDescription objects.
Definition at line 64 of file PersistentOStream.h.
typedef map< cBPtr , int , less< cBPtr > > ThePEG::PersistentOStream::ObjectMap |
A map of objects indexed by integers.
A map of int indexed by cBPtr .
Definition at line 58 of file PersistentOStream.h.
typedef ThePEG::Ptr<PersistentBase>::transient_pointer ThePEG::PersistentOStream::tBPtr |
Alias for a transient pointer to PersistentBase .
Definition at line 55 of file PersistentOStream.h.
typedef ThePEG::Ptr<PersistentBase>::transient_const_pointer ThePEG::PersistentOStream::tcBPtr |
Alias for a transient pointer to a const PersistentBase .
Definition at line 55 of file PersistentOStream.h.
ThePEG::PersistentOStream::PersistentOStream | ( | ostream & | , |
const vector< string > & | libs = vector< string >() |
||
) |
Constuctor giving an output stream.
Optionally a vector of libraries to be loaded before the resulting file can be read in again can be given in libs.
ThePEG::PersistentOStream::PersistentOStream | ( | string | , |
const vector< string > & | libs = vector< string >() |
||
) |
Constuctor giving a file name to read.
If the first character in the string is a '|', the corresponding program is run and its standard input is used instead. If the filename ends in ".gz" the file is compressed with gzip. Optionally a vector of libraries to be loaded before the resulting file can be read in again can be given in libs.
|
inlineprivate |
Put a "begin object" marker on the associated ostream.
Definition at line 443 of file PersistentOStream.h.
|
inlineprivate |
Check if the state is ok.
Definition at line 428 of file PersistentOStream.h.
|
inlineprivate |
Put an "next base class" marker on the associated ostream.
Definition at line 453 of file PersistentOStream.h.
|
inlineprivate |
Put a "end of object" marker on the associated ostream.
Definition at line 448 of file PersistentOStream.h.
|
inlineprivate |
Put a character on the associated ostream but escape it if it is a token.
Definition at line 464 of file PersistentOStream.h.
References isToken(), put(), tNoSep, tNull, and tSep.
Referenced by operator<<().
|
inline |
Check the state of the stream.
Definition at line 327 of file PersistentOStream.h.
References badState, and os().
Referenced by operator bool(), operator!(), ThePEG::operator<<(), and putContainer().
|
inlineprivate |
|
inline |
Check the state of the stream.
Definition at line 332 of file PersistentOStream.h.
References good().
|
inline |
Check the state of the stream.
Definition at line 337 of file PersistentOStream.h.
References good().
|
inline |
|
inline |
Write a character.
Definition at line 145 of file PersistentOStream.h.
|
inline |
Write a Complex.
Definition at line 270 of file PersistentOStream.h.
|
inline |
Write a c-style character string (to be read in as a std::string).
Definition at line 262 of file PersistentOStream.h.
|
inline |
Operator for writing persistent objects to the stream.
p | a pointer to the object to be written. |
Definition at line 106 of file PersistentOStream.h.
References outputPointer().
|
inline |
Operator for writing persistent objects to the stream.
p | a pointer to the object to be written. |
Definition at line 96 of file PersistentOStream.h.
References outputPointer().
|
inline |
Operator for writing persistent objects to the stream.
p | a pointer to the object to be written. |
Definition at line 126 of file PersistentOStream.h.
References outputPointer().
|
inline |
Operator for writing persistent objects to the stream.
p | a pointer to the object to be written. |
Definition at line 116 of file PersistentOStream.h.
References outputPointer().
|
inline |
Write a double.
Definition at line 222 of file PersistentOStream.h.
References os(), put(), ThePEG::Exception::runerror, and tSep.
|
inline |
Write a float.
Definition at line 235 of file PersistentOStream.h.
References os(), put(), ThePEG::Exception::runerror, and tSep.
|
inline |
Write an integer.
Definition at line 168 of file PersistentOStream.h.
|
inline |
Write a long integer.
Definition at line 186 of file PersistentOStream.h.
|
inline |
Write a short integer.
Definition at line 204 of file PersistentOStream.h.
|
inline |
Write a signed character.
Definition at line 154 of file PersistentOStream.h.
|
inline |
Write a character string.
Definition at line 136 of file PersistentOStream.h.
|
inline |
Write an unsigned character.
Definition at line 161 of file PersistentOStream.h.
|
inline |
Write an unsigned integer.
Definition at line 177 of file PersistentOStream.h.
|
inline |
Write an unsigned long integer.
Definition at line 195 of file PersistentOStream.h.
|
inline |
Write an unsigned short integer.
Definition at line 213 of file PersistentOStream.h.
|
inlineprivate |
Return a reference to the associated ostream.
Definition at line 475 of file PersistentOStream.h.
References theOStream.
Referenced by checkState(), good(), operator<<(), and put().
|
inlineprivate |
Return a const reference to the associated ostream.
Definition at line 480 of file PersistentOStream.h.
References theOStream.
|
inline |
Instuct the stream not to save the following objects.
Definition at line 319 of file PersistentOStream.h.
References lastSavedObject.
Referenced by ThePEG::pop().
|
inline |
Instuct the stream to save the following objects (protecting them from being flushed).
Definition at line 311 of file PersistentOStream.h.
References lastSavedObject, and writtenObjects.
Referenced by ThePEG::push().
|
inlineprivate |
Put a character on the associated ostream.
Definition at line 458 of file PersistentOStream.h.
References os().
Referenced by beginObject(), endBase(), endObject(), escape(), and operator<<().
|
inline |
Output of containers of streamable objects.
Definition at line 280 of file PersistentOStream.h.
References good().
Referenced by ThePEG::operator<<().
void ThePEG::PersistentOStream::putObjectPart | ( | tcBPtr | obj, |
const ClassDescriptionBase * | cd | ||
) |
For a given object, write the member variables corresponding to a given ClassDescriptionBase object.
obj | the object to be written. |
cd | a pointer to a ClassDescriptionBase describing the (sub)class to written. |
|
inlineprivate |
Set the stream in a bad state.
Definition at line 420 of file PersistentOStream.h.
References badState.
|
private |
True if the associated ostream should be deleted in the destructor.
Definition at line 515 of file PersistentOStream.h.
|
private |
True if no errors has occurred.
Definition at line 510 of file PersistentOStream.h.
Referenced by checkState(), good(), and setBadState().
|
private |
List of written objects that are to be saved.
Definition at line 495 of file PersistentOStream.h.
|
staticprivate |
The subversion of this PersistentOStream implementation.
Definition at line 360 of file PersistentOStream.h.
|
staticprivate |
The special marker character indicating the beginning of an object.
Definition at line 367 of file PersistentOStream.h.
Referenced by beginObject(), and isToken().
|
staticprivate |
The special marker character indicating the end of an object.
Definition at line 372 of file PersistentOStream.h.
Referenced by endObject(), and isToken().
|
private |
A pointer to the associated ostream.
Definition at line 505 of file PersistentOStream.h.
Referenced by os().
|
staticprivate |
The marker character indicating the beginning of the next base class in case of multiple inheritance.
The special marker character indicating an escaped marker character.
Definition at line 381 of file PersistentOStream.h.
|
staticprivate |
The special marker character indicating a false boolean value.
Definition at line 407 of file PersistentOStream.h.
Referenced by operator<<().
|
staticprivate |
The special marker character used to avoid confusion with escaped tSep markers.
Definition at line 397 of file PersistentOStream.h.
Referenced by escape().
|
staticprivate |
The special marker character indicating an escaped marker character.
Definition at line 386 of file PersistentOStream.h.
|
staticprivate |
The special marker character indicating the end of a value.
Definition at line 391 of file PersistentOStream.h.
Referenced by escape(), isToken(), and operator<<().
|
staticprivate |
The special marker character indicating a true boolean value.
Definition at line 402 of file PersistentOStream.h.
Referenced by operator<<().
|
staticprivate |
The version of this PersistentOStream implementation.
Definition at line 355 of file PersistentOStream.h.
|
private |
List of written classes.
Definition at line 500 of file PersistentOStream.h.
|
private |