thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
ThePEG::PersistentOStream Class Reference

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 >
PersistentOStreamoperator<< (const RCPtr< T > &p)
 Operator for writing persistent objects to the stream.
 
template<typename T >
PersistentOStreamoperator<< (const ConstRCPtr< T > &p)
 Operator for writing persistent objects to the stream.
 
template<typename T >
PersistentOStreamoperator<< (const TransientRCPtr< T > &p)
 Operator for writing persistent objects to the stream.
 
template<typename T >
PersistentOStreamoperator<< (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.
 
PersistentOStreamoperator<< (string s)
 Write a character string.
 
PersistentOStreamoperator<< (char c)
 Write a character.
 
PersistentOStreamoperator<< (signed char c)
 Write a signed character.
 
PersistentOStreamoperator<< (unsigned char c)
 Write an unsigned character.
 
PersistentOStreamoperator<< (int i)
 Write an integer.
 
PersistentOStreamoperator<< (unsigned int i)
 Write an unsigned integer.
 
PersistentOStreamoperator<< (long i)
 Write a long integer.
 
PersistentOStreamoperator<< (unsigned long i)
 Write an unsigned long integer.
 
PersistentOStreamoperator<< (short i)
 Write a short integer.
 
PersistentOStreamoperator<< (unsigned short i)
 Write an unsigned short integer.
 
PersistentOStreamoperator<< (double d)
 Write a double.
 
PersistentOStreamoperator<< (float f)
 Write a float.
 
PersistentOStreamoperator<< (bool t)
 Write a boolean.
 
PersistentOStreamoperator<< (const char *s)
 Write a c-style character string (to be read in as a std::string).
 
PersistentOStreamoperator<< (Complex z)
 Write a Complex.
 
template<typename Container >
void putContainer (const Container &c)
 Output of containers of streamable objects.
 
PersistentOStreamoutputPointer (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.
 
PersistentOStreamflush ()
 Remove all objects that have been written, except those which are to be saved, from the list of written objects.
 
PersistentOStreampush ()
 Instuct the stream to save the following objects (protecting them from being flushed).
 
PersistentOStreampop ()
 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 ClassDescriptionBasewriteClassId (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.
 
PersistentOStreamoperator= (const PersistentOStream &)=delete
 Standard ctors and assignment are private and not implemented.
 

Detailed Description

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.

See also
PersistentIStream
ClassDescription
ClassTraits

Definition at line 51 of file PersistentOStream.h.

Member Typedef Documentation

◆ BPtr

Alias for a reference counted pointer to PersistentBase .

Definition at line 55 of file PersistentOStream.h.

◆ cBPtr

Alias for a reference counted pointer to a const PersistentBase .

Definition at line 55 of file PersistentOStream.h.

◆ ClassMap

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.

◆ DescriptionVector

A vector of bare pointers to InputDescription objects.

Definition at line 64 of file PersistentOStream.h.

◆ ObjectMap

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.

◆ tBPtr

Alias for a transient pointer to PersistentBase .

Definition at line 55 of file PersistentOStream.h.

◆ tcBPtr

Alias for a transient pointer to a const PersistentBase .

Definition at line 55 of file PersistentOStream.h.

Constructor & Destructor Documentation

◆ PersistentOStream() [1/2]

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.

◆ PersistentOStream() [2/2]

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.

Member Function Documentation

◆ beginObject()

void ThePEG::PersistentOStream::beginObject ( )
inlineprivate

Put a "begin object" marker on the associated ostream.

Definition at line 443 of file PersistentOStream.h.

References put(), and tBegin.

◆ checkState()

void ThePEG::PersistentOStream::checkState ( )
inlineprivate

Check if the state is ok.

Definition at line 428 of file PersistentOStream.h.

References badState, and os().

◆ endBase()

void ThePEG::PersistentOStream::endBase ( )
inlineprivate

Put an "next base class" marker on the associated ostream.

Definition at line 453 of file PersistentOStream.h.

References put(), and tNext.

◆ endObject()

void ThePEG::PersistentOStream::endObject ( )
inlineprivate

Put a "end of object" marker on the associated ostream.

Definition at line 448 of file PersistentOStream.h.

References put(), and tEnd.

◆ escape()

void ThePEG::PersistentOStream::escape ( char  c)
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<<().

◆ good()

bool ThePEG::PersistentOStream::good ( ) const
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().

◆ isToken()

bool ThePEG::PersistentOStream::isToken ( char  c) const
inlineprivate

Return true if the given character is aspecial marker character.

Definition at line 413 of file PersistentOStream.h.

References tBegin, tEnd, tNext, tNull, and tSep.

Referenced by escape().

◆ operator bool()

ThePEG::PersistentOStream::operator bool ( ) const
inline

Check the state of the stream.

Definition at line 332 of file PersistentOStream.h.

References good().

◆ operator!()

bool ThePEG::PersistentOStream::operator! ( ) const
inline

Check the state of the stream.

Definition at line 337 of file PersistentOStream.h.

References good().

◆ operator<<() [1/19]

PersistentOStream & ThePEG::PersistentOStream::operator<< ( bool  t)
inline

Write a boolean.

Definition at line 248 of file PersistentOStream.h.

References put(), tNo, tSep, and tYes.

◆ operator<<() [2/19]

PersistentOStream & ThePEG::PersistentOStream::operator<< ( char  c)
inline

Write a character.

Definition at line 145 of file PersistentOStream.h.

References escape(), put(), and tSep.

◆ operator<<() [3/19]

PersistentOStream & ThePEG::PersistentOStream::operator<< ( Complex  z)
inline

Write a Complex.

Definition at line 270 of file PersistentOStream.h.

◆ operator<<() [4/19]

PersistentOStream & ThePEG::PersistentOStream::operator<< ( const char *  s)
inline

Write a c-style character string (to be read in as a std::string).

Definition at line 262 of file PersistentOStream.h.

◆ operator<<() [5/19]

template<typename T >
PersistentOStream & ThePEG::PersistentOStream::operator<< ( const ConstRCPtr< T > &  p)
inline

Operator for writing persistent objects to the stream.

Parameters
pa pointer to the object to be written.
Returns
a reference to the stream.

Definition at line 106 of file PersistentOStream.h.

References outputPointer().

◆ operator<<() [6/19]

template<typename T >
PersistentOStream & ThePEG::PersistentOStream::operator<< ( const RCPtr< T > &  p)
inline

Operator for writing persistent objects to the stream.

Parameters
pa pointer to the object to be written.
Returns
a reference to the stream.

Definition at line 96 of file PersistentOStream.h.

References outputPointer().

◆ operator<<() [7/19]

template<typename T >
PersistentOStream & ThePEG::PersistentOStream::operator<< ( const TransientConstRCPtr< T > &  p)
inline

Operator for writing persistent objects to the stream.

Parameters
pa pointer to the object to be written.
Returns
a reference to the stream.

Definition at line 126 of file PersistentOStream.h.

References outputPointer().

◆ operator<<() [8/19]

template<typename T >
PersistentOStream & ThePEG::PersistentOStream::operator<< ( const TransientRCPtr< T > &  p)
inline

Operator for writing persistent objects to the stream.

Parameters
pa pointer to the object to be written.
Returns
a reference to the stream.

Definition at line 116 of file PersistentOStream.h.

References outputPointer().

◆ operator<<() [9/19]

PersistentOStream & ThePEG::PersistentOStream::operator<< ( double  d)
inline

Write a double.

Definition at line 222 of file PersistentOStream.h.

References os(), put(), ThePEG::Exception::runerror, and tSep.

◆ operator<<() [10/19]

PersistentOStream & ThePEG::PersistentOStream::operator<< ( float  f)
inline

Write a float.

Definition at line 235 of file PersistentOStream.h.

References os(), put(), ThePEG::Exception::runerror, and tSep.

◆ operator<<() [11/19]

PersistentOStream & ThePEG::PersistentOStream::operator<< ( int  i)
inline

Write an integer.

Definition at line 168 of file PersistentOStream.h.

References os(), put(), and tSep.

◆ operator<<() [12/19]

PersistentOStream & ThePEG::PersistentOStream::operator<< ( long  i)
inline

Write a long integer.

Definition at line 186 of file PersistentOStream.h.

References os(), put(), and tSep.

◆ operator<<() [13/19]

PersistentOStream & ThePEG::PersistentOStream::operator<< ( short  i)
inline

Write a short integer.

Definition at line 204 of file PersistentOStream.h.

References os(), put(), and tSep.

◆ operator<<() [14/19]

PersistentOStream & ThePEG::PersistentOStream::operator<< ( signed char  c)
inline

Write a signed character.

Definition at line 154 of file PersistentOStream.h.

◆ operator<<() [15/19]

PersistentOStream & ThePEG::PersistentOStream::operator<< ( string  s)
inline

Write a character string.

Definition at line 136 of file PersistentOStream.h.

References escape(), put(), and tSep.

◆ operator<<() [16/19]

PersistentOStream & ThePEG::PersistentOStream::operator<< ( unsigned char  c)
inline

Write an unsigned character.

Definition at line 161 of file PersistentOStream.h.

◆ operator<<() [17/19]

PersistentOStream & ThePEG::PersistentOStream::operator<< ( unsigned int  i)
inline

Write an unsigned integer.

Definition at line 177 of file PersistentOStream.h.

References os(), put(), and tSep.

◆ operator<<() [18/19]

PersistentOStream & ThePEG::PersistentOStream::operator<< ( unsigned long  i)
inline

Write an unsigned long integer.

Definition at line 195 of file PersistentOStream.h.

References os(), put(), and tSep.

◆ operator<<() [19/19]

PersistentOStream & ThePEG::PersistentOStream::operator<< ( unsigned short  i)
inline

Write an unsigned short integer.

Definition at line 213 of file PersistentOStream.h.

References os(), put(), and tSep.

◆ os() [1/2]

ostream & ThePEG::PersistentOStream::os ( )
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().

◆ os() [2/2]

const ostream & ThePEG::PersistentOStream::os ( ) const
inlineprivate

Return a const reference to the associated ostream.

Definition at line 480 of file PersistentOStream.h.

References theOStream.

◆ pop()

PersistentOStream & ThePEG::PersistentOStream::pop ( )
inline

Instuct the stream not to save the following objects.

Definition at line 319 of file PersistentOStream.h.

References lastSavedObject.

Referenced by ThePEG::pop().

◆ push()

PersistentOStream & ThePEG::PersistentOStream::push ( )
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().

◆ put()

void ThePEG::PersistentOStream::put ( char  c)
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<<().

◆ putContainer()

template<typename Container >
void ThePEG::PersistentOStream::putContainer ( const Container &  c)
inline

Output of containers of streamable objects.

Definition at line 280 of file PersistentOStream.h.

References good().

Referenced by ThePEG::operator<<().

◆ putObjectPart()

void ThePEG::PersistentOStream::putObjectPart ( tcBPtr  obj,
const ClassDescriptionBase cd 
)

For a given object, write the member variables corresponding to a given ClassDescriptionBase object.

Parameters
objthe object to be written.
cda pointer to a ClassDescriptionBase describing the (sub)class to written.

◆ setBadState()

void ThePEG::PersistentOStream::setBadState ( )
inlineprivate

Set the stream in a bad state.

Definition at line 420 of file PersistentOStream.h.

References badState.

Member Data Documentation

◆ allocStream

bool ThePEG::PersistentOStream::allocStream
private

True if the associated ostream should be deleted in the destructor.

Definition at line 515 of file PersistentOStream.h.

◆ badState

bool ThePEG::PersistentOStream::badState
private

True if no errors has occurred.

Definition at line 510 of file PersistentOStream.h.

Referenced by checkState(), good(), and setBadState().

◆ lastSavedObject

stack<int> ThePEG::PersistentOStream::lastSavedObject
private

List of written objects that are to be saved.

Definition at line 495 of file PersistentOStream.h.

Referenced by pop(), and push().

◆ subVersion

const int ThePEG::PersistentOStream::subVersion = 3
staticprivate

The subversion of this PersistentOStream implementation.

Definition at line 360 of file PersistentOStream.h.

◆ tBegin

const char ThePEG::PersistentOStream::tBegin = '{'
staticprivate

The special marker character indicating the beginning of an object.

Definition at line 367 of file PersistentOStream.h.

Referenced by beginObject(), and isToken().

◆ tEnd

const char ThePEG::PersistentOStream::tEnd = '}'
staticprivate

The special marker character indicating the end of an object.

Definition at line 372 of file PersistentOStream.h.

Referenced by endObject(), and isToken().

◆ theOStream

ostream* ThePEG::PersistentOStream::theOStream
private

A pointer to the associated ostream.

Definition at line 505 of file PersistentOStream.h.

Referenced by os().

◆ tNext

const char ThePEG::PersistentOStream::tNext = '|'
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.

Referenced by endBase(), and isToken().

◆ tNo

const char ThePEG::PersistentOStream::tNo = 'n'
staticprivate

The special marker character indicating a false boolean value.

Definition at line 407 of file PersistentOStream.h.

Referenced by operator<<().

◆ tNoSep

const char ThePEG::PersistentOStream::tNoSep = 'n'
staticprivate

The special marker character used to avoid confusion with escaped tSep markers.

Definition at line 397 of file PersistentOStream.h.

Referenced by escape().

◆ tNull

const char ThePEG::PersistentOStream::tNull = '\\'
staticprivate

The special marker character indicating an escaped marker character.

Definition at line 386 of file PersistentOStream.h.

Referenced by escape(), and isToken().

◆ tSep

const char ThePEG::PersistentOStream::tSep = '\n'
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<<().

◆ tYes

const char ThePEG::PersistentOStream::tYes = 'y'
staticprivate

The special marker character indicating a true boolean value.

Definition at line 402 of file PersistentOStream.h.

Referenced by operator<<().

◆ version

const int ThePEG::PersistentOStream::version = 0
staticprivate

The version of this PersistentOStream implementation.

Definition at line 355 of file PersistentOStream.h.

◆ writtenClasses

ClassMap ThePEG::PersistentOStream::writtenClasses
private

List of written classes.

Definition at line 500 of file PersistentOStream.h.

◆ writtenObjects

ObjectMap ThePEG::PersistentOStream::writtenObjects
private

List of written objects.

Definition at line 490 of file PersistentOStream.h.

Referenced by push().


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