thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
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 . More...
 
typedef ThePEG::Ptr< PersistentBase >::const_pointer cBPtr
 Alias for a reference counted pointer to a const PersistentBase . More...
 
typedef ThePEG::Ptr< PersistentBase >::transient_pointer tBPtr
 Alias for a transient pointer to PersistentBase . More...
 
typedef ThePEG::Ptr< PersistentBase >::transient_const_pointer tcBPtr
 Alias for a transient pointer to a const PersistentBase . More...
 
typedef map< cBPtr, int, less< cBPtr > > ObjectMap
 A map of objects indexed by integers. More...
 
typedef map< const ClassDescriptionBase *, int, less< const ClassDescriptionBase *> > ClassMap
 A map relating class descriptions to integers. More...
 
typedef ClassDescriptionBase::DescriptionVector DescriptionVector
 A vector of bare pointers to InputDescription objects. More...
 

Public Member Functions

 PersistentOStream (ostream &, const vector< string > &libs=vector< string >())
 Constuctor giving an output stream. More...
 
 PersistentOStream (string, const vector< string > &libs=vector< string >())
 Constuctor giving a file name to read. More...
 
 ~PersistentOStream ()
 The destructor.
 
template<typename T >
PersistentOStreamoperator<< (const RCPtr< T > &p)
 Operator for writing persistent objects to the stream. More...
 
template<typename T >
PersistentOStreamoperator<< (const ConstRCPtr< T > &p)
 Operator for writing persistent objects to the stream. More...
 
template<typename T >
PersistentOStreamoperator<< (const TransientRCPtr< T > &p)
 Operator for writing persistent objects to the stream. More...
 
template<typename T >
PersistentOStreamoperator<< (const TransientConstRCPtr< T > &p)
 Operator for writing persistent objects to the stream. More...
 
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. More...
 
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.
 
Operators for extracting built-in types from the stream.
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.
 

Private Member Functions

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.
 

Private Attributes

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.
 

Static Private Attributes

static const int version = 0
 The version of this PersistentOStream implementation.
 
static const int subVersion = 3
 The subversion of this PersistentOStream implementation.
 
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. More...
 
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.
 

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

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.

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

◆ operator<<() [1/4]

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<<() [2/4]

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<<() [3/4]

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<<() [4/4]

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().

◆ 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.

Referenced by putContainer().

Member Data Documentation

◆ 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.


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