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

PersistentIStream is used to read persistent objects from a stream where they were previously written using PersistentOStream. More...

#include <PersistentIStream.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 vector< BPtrObjectVector
 A vector of pointers to persistent objects.
 
typedef InputDescription::DescriptionVector DescriptionVector
 A vector of bare pointers to InputDescription objects.
 

Public Member Functions

 PersistentIStream (istream &is)
 Constuctor giving an input stream to be used as an underlying istream.
 
 PersistentIStream (string)
 Constuctor giving a file name to read from.
 
 ~PersistentIStream ()
 The destructor.
 
template<typename T >
PersistentIStreamoperator>> (RCPtr< T > &ptr)
 Operator for extracting persistent objects from the stream.
 
template<typename T >
PersistentIStreamoperator>> (ConstRCPtr< T > &ptr)
 Operator for extracting persistent objects from the stream.
 
template<typename T >
PersistentIStreamoperator>> (TransientRCPtr< T > &ptr)
 Operator for extracting persistent objects from the stream.
 
template<typename T >
PersistentIStreamoperator>> (TransientConstRCPtr< T > &ptr)
 Operator for extracting persistent objects from the stream.
 

Operators for extracting built-in types from the stream.

ObjectVector readObjects
 Lists of objects that have been read.
 
DescriptionVector readClasses
 Lists of classes and corresponding version strings that have been read.
 
istream * theIStream
 A pointer to the associated istream.
 
bool isPedantic
 Pedantic or tolerant.
 
bool allocStream
 True if the associated istream should be deleted when the PersistentIStream is destroyed.
 
bool badState
 False if no errors has occurred.
 
int version
 Version number of the PersistentOStream which has written the file being read.
 
int subVersion
 Subversion number of the PersistentOStream which has written the file being read.
 
vector< string > theGlobalLibraries
 Global libraries loaded in the initialization.
 
PersistentIStreamoperator>> (string &)
 Read a character string.
 
PersistentIStreamoperator>> (char &)
 Read a character.
 
PersistentIStreamoperator>> (signed char &)
 Read a signed character.
 
PersistentIStreamoperator>> (unsigned char &)
 Read an unsigned character.
 
PersistentIStreamoperator>> (int &i)
 Read an integer.
 
PersistentIStreamoperator>> (unsigned int &i)
 Read an unsigned integer.
 
PersistentIStreamoperator>> (long &i)
 Read a long integer.
 
PersistentIStreamoperator>> (unsigned long &i)
 Read an unsigned long integer.
 
PersistentIStreamoperator>> (short &i)
 Read a short integer.
 
PersistentIStreamoperator>> (unsigned short &i)
 Read an unsigned short integer.
 
PersistentIStreamoperator>> (double &d)
 Read a double.
 
PersistentIStreamoperator>> (float &f)
 Read a float.
 
PersistentIStreamoperator>> (bool &)
 Read a bool.
 
PersistentIStreamoperator>> (Complex &)
 Read a Complex.
 
template<typename Container >
void getContainer (Container &c)
 Intput of containers streamable objects.
 
BPtr getObject ()
 Read in an object.
 
void getObjectPart (tBPtr obj, const InputDescription *pid)
 For a given object, read the member variables corresponding to a given InputDescription object.
 
const InputDescriptiongetClass ()
 Read a class description from the underlying stream and return a corresponding InputDescription object.
 
PersistentIStreamsetPedantic ()
 Set pedantic mode.
 
PersistentIStreamsetTolerant ()
 Set tolerant mode.
 
bool good () const
 Check the state of the stream.
 
bool operator! () const
 Check the state of the stream.
 
 operator bool () const
 Check the state of the stream.
 
bool pedantic () const
 Check the tolerance.
 
const vector< string > & globalLibraries () const
 The global libraries loaded on initialization.
 
void init ()
 Internal initialization.
 
char get ()
 Get the next character from the associated istream.
 
char escaped ()
 Get the next character from the associated istream and decode it if it is escaped.
 
void setBadState ()
 Set the stream in a bad state.
 
void getSep ()
 Read a field separator from the stream.
 
void skipField ()
 Scan the stream for the next field separator.
 
bool beginObject ()
 Check if the next char to be read is a tBegin marker.
 
void endObject ()
 Scan the stream to the end of the current object.
 
void endBase (string classname)
 Scan stream for "end base class" marker.
 
istream & is ()
 Return a reference to the associated stream.
 
const istream & is () const
 Return a const reference to the associated 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.
 
 PersistentIStream ()
 Standard ctors and assignment are private and not implemented.
 
 PersistentIStream (const PersistentIStream &)
 Standard ctors and assignment are private and not implemented.
 
PersistentIStreamoperator= (const PersistentIStream &)=delete
 Standard ctors and assignment are private and not implemented.
 

Detailed Description

PersistentIStream is used to read persistent objects from a stream where they were previously written using PersistentOStream.

Basic types and pointers to objects derived from PersistentBase should be read in the same order they were written out. If pedantic() is true the same classes that were written out must be present in the current program. If pedantic() is false and if an object is read for which only a base class is present in the current program, only the parts corresponding to the base class will be read, and the rest will be gracefully skipped.

Each base class of a given object will be asked to read its members from 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>::input method, which otherwise will call the non-virtual persistentInput 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
PersistentOStream
ClassTraits

Definition at line 48 of file PersistentIStream.h.

Member Typedef Documentation

◆ BPtr

Alias for a reference counted pointer to PersistentBase .

Definition at line 52 of file PersistentIStream.h.

◆ cBPtr

Alias for a reference counted pointer to a const PersistentBase .

Definition at line 52 of file PersistentIStream.h.

◆ DescriptionVector

A vector of bare pointers to InputDescription objects.

Definition at line 58 of file PersistentIStream.h.

◆ ObjectVector

A vector of pointers to persistent objects.

Definition at line 55 of file PersistentIStream.h.

◆ tBPtr

Alias for a transient pointer to PersistentBase .

Definition at line 52 of file PersistentIStream.h.

◆ tcBPtr

Alias for a transient pointer to a const PersistentBase .

Definition at line 52 of file PersistentIStream.h.

Constructor & Destructor Documentation

◆ PersistentIStream() [1/2]

ThePEG::PersistentIStream::PersistentIStream ( istream &  is)
inline

Constuctor giving an input stream to be used as an underlying istream.

Definition at line 66 of file PersistentIStream.h.

References init().

◆ PersistentIStream() [2/2]

ThePEG::PersistentIStream::PersistentIStream ( string  )

Constuctor giving a file name to read from.

If the first character in the string is a '|', the corresponding program is run and its standard output is used instead. If the filename ends in ".gz" the file is uncompressed with gzip.

Member Function Documentation

◆ beginObject()

bool ThePEG::PersistentIStream::beginObject ( )
inlineprivate

Check if the next char to be read is a tBegin marker.

Definition at line 400 of file PersistentIStream.h.

References is(), and tBegin.

◆ endBase()

void ThePEG::PersistentIStream::endBase ( string  classname)
private

Scan stream for "end base class" marker.

The classname is the name of the class currently being read and is only used for documenting exceptions.

◆ endObject()

void ThePEG::PersistentIStream::endObject ( )
private

Scan the stream to the end of the current object.

If any new object are found these are read prom the stream to ensure that the pointer structure is preserved.

◆ escaped()

char ThePEG::PersistentIStream::escaped ( )
inlineprivate

Get the next character from the associated istream and decode it if it is escaped.

Definition at line 367 of file PersistentIStream.h.

References get(), tNoSep, and tSep.

◆ get()

char ThePEG::PersistentIStream::get ( )
inlineprivate

Get the next character from the associated istream.

Definition at line 361 of file PersistentIStream.h.

References is().

Referenced by escaped(), and getSep().

◆ getContainer()

template<typename Container >
void ThePEG::PersistentIStream::getContainer ( Container &  c)
inline

Intput of containers streamable objects.

Parameters
cthe container into which objects are added.

Definition at line 250 of file PersistentIStream.h.

References good().

Referenced by ThePEG::operator>>().

◆ getObject()

BPtr ThePEG::PersistentIStream::getObject ( )

Read in an object.

Create an object and read its data from the stream.

Returns
a pointer to the read object.

Referenced by operator>>().

◆ getObjectPart()

void ThePEG::PersistentIStream::getObjectPart ( tBPtr  obj,
const InputDescription pid 
)

For a given object, read the member variables corresponding to a given InputDescription object.

Parameters
objthe object to be read into.
pida pointer to an InputDescription describing the (sub)class to be read.

◆ getSep()

void ThePEG::PersistentIStream::getSep ( )
inlineprivate

Read a field separator from the stream.

Definition at line 383 of file PersistentIStream.h.

References get(), pedantic(), setBadState(), skipField(), and tSep.

Referenced by operator>>().

◆ globalLibraries()

const vector< string > & ThePEG::PersistentIStream::globalLibraries ( ) const
inline

The global libraries loaded on initialization.

Definition at line 333 of file PersistentIStream.h.

References theGlobalLibraries.

◆ good()

bool ThePEG::PersistentIStream::good ( ) const
inline

Check the state of the stream.

Definition at line 312 of file PersistentIStream.h.

References badState, and is().

Referenced by getContainer(), operator bool(), operator!(), and ThePEG::operator>>().

◆ is() [1/2]

istream & ThePEG::PersistentIStream::is ( )
inlineprivate

Return a reference to the associated stream.

Definition at line 419 of file PersistentIStream.h.

References theIStream.

Referenced by beginObject(), get(), good(), operator>>(), and skipField().

◆ is() [2/2]

const istream & ThePEG::PersistentIStream::is ( ) const
inlineprivate

Return a const reference to the associated stream.

Definition at line 424 of file PersistentIStream.h.

References theIStream.

◆ operator bool()

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

Check the state of the stream.

Definition at line 322 of file PersistentIStream.h.

References good().

◆ operator!()

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

Check the state of the stream.

Definition at line 317 of file PersistentIStream.h.

References good().

◆ operator>>() [1/12]

template<typename T >
PersistentIStream & ThePEG::PersistentIStream::operator>> ( ConstRCPtr< T > &  ptr)
inline

Operator for extracting persistent objects from the stream.

Parameters
ptrthis pointer will refer to the extracted object.
Returns
a reference to the stream.

Definition at line 107 of file PersistentIStream.h.

References getObject(), and setBadState().

◆ operator>>() [2/12]

PersistentIStream & ThePEG::PersistentIStream::operator>> ( double &  d)
inline

Read a double.

Definition at line 220 of file PersistentIStream.h.

References getSep(), and is().

◆ operator>>() [3/12]

PersistentIStream & ThePEG::PersistentIStream::operator>> ( float &  f)
inline

Read a float.

Definition at line 229 of file PersistentIStream.h.

References getSep(), and is().

◆ operator>>() [4/12]

PersistentIStream & ThePEG::PersistentIStream::operator>> ( int &  i)
inline

Read an integer.

Definition at line 166 of file PersistentIStream.h.

References getSep(), and is().

◆ operator>>() [5/12]

PersistentIStream & ThePEG::PersistentIStream::operator>> ( long &  i)
inline

Read a long integer.

Definition at line 184 of file PersistentIStream.h.

References getSep(), and is().

◆ operator>>() [6/12]

template<typename T >
PersistentIStream & ThePEG::PersistentIStream::operator>> ( RCPtr< T > &  ptr)
inline

Operator for extracting persistent objects from the stream.

Parameters
ptrthis pointer will refer to the extracted object.
Returns
a reference to the stream.

Definition at line 94 of file PersistentIStream.h.

References getObject(), and setBadState().

◆ operator>>() [7/12]

PersistentIStream & ThePEG::PersistentIStream::operator>> ( short &  i)
inline

Read a short integer.

Definition at line 202 of file PersistentIStream.h.

References getSep(), and is().

◆ operator>>() [8/12]

template<typename T >
PersistentIStream & ThePEG::PersistentIStream::operator>> ( TransientConstRCPtr< T > &  ptr)
inline

Operator for extracting persistent objects from the stream.

Parameters
ptrthis pointer will refer to the extracted object.
Returns
a reference to the stream.

Definition at line 133 of file PersistentIStream.h.

References getObject(), and setBadState().

◆ operator>>() [9/12]

template<typename T >
PersistentIStream & ThePEG::PersistentIStream::operator>> ( TransientRCPtr< T > &  ptr)
inline

Operator for extracting persistent objects from the stream.

Parameters
ptrthis pointer will refer to the extracted object.
Returns
a reference to the stream.

Definition at line 120 of file PersistentIStream.h.

References getObject(), and setBadState().

◆ operator>>() [10/12]

PersistentIStream & ThePEG::PersistentIStream::operator>> ( unsigned int &  i)
inline

Read an unsigned integer.

Definition at line 175 of file PersistentIStream.h.

References getSep(), and is().

◆ operator>>() [11/12]

PersistentIStream & ThePEG::PersistentIStream::operator>> ( unsigned long &  i)
inline

Read an unsigned long integer.

Definition at line 193 of file PersistentIStream.h.

References getSep(), and is().

◆ operator>>() [12/12]

PersistentIStream & ThePEG::PersistentIStream::operator>> ( unsigned short &  i)
inline

Read an unsigned short integer.

Definition at line 211 of file PersistentIStream.h.

References getSep(), and is().

◆ pedantic()

bool ThePEG::PersistentIStream::pedantic ( ) const
inline

Check the tolerance.

Returns true if setPedantic() has been called or if not setTolerant() has been called.

Definition at line 328 of file PersistentIStream.h.

References isPedantic.

Referenced by getSep().

◆ setBadState()

void ThePEG::PersistentIStream::setBadState ( )
inlineprivate

Set the stream in a bad state.

Definition at line 375 of file PersistentIStream.h.

References badState.

Referenced by getSep(), operator>>(), and skipField().

◆ setPedantic()

PersistentIStream & ThePEG::PersistentIStream::setPedantic ( )
inline

Set pedantic mode.

If the stream is set to be tolerant it is allowed to read an object from the stream even if the corresponding class is not known to the running executable, under the condition that a public base class of the unknown class is known. If the stream is set to be pedantic this is not allowed. By default, the stream is pedantic.

Definition at line 291 of file PersistentIStream.h.

References isPedantic.

Referenced by ThePEG::pedantic().

◆ setTolerant()

PersistentIStream & ThePEG::PersistentIStream::setTolerant ( )
inline

Set tolerant mode.

If the stream is set to be tolerant it is allowed to read an object from the stream even if the corresponding class is not known to the running executable, under the condition that a public base class of the unknown class is known. If the stream is set to be pedantic this is not allowed. By default, the stream is pedantic.

Definition at line 304 of file PersistentIStream.h.

References isPedantic.

Referenced by ThePEG::tolerant().

◆ skipField()

void ThePEG::PersistentIStream::skipField ( )
inlineprivate

Scan the stream for the next field separator.

Definition at line 391 of file PersistentIStream.h.

References is(), setBadState(), and tSep.

Referenced by getSep().

Member Data Documentation

◆ allocStream

bool ThePEG::PersistentIStream::allocStream
private

True if the associated istream should be deleted when the PersistentIStream is destroyed.

Definition at line 451 of file PersistentIStream.h.

◆ badState

bool ThePEG::PersistentIStream::badState
private

False if no errors has occurred.

Definition at line 456 of file PersistentIStream.h.

Referenced by good(), and setBadState().

◆ isPedantic

bool ThePEG::PersistentIStream::isPedantic
private

Pedantic or tolerant.

See description of the setPedantic() and setTolerant() methods.

Definition at line 445 of file PersistentIStream.h.

Referenced by pedantic(), setPedantic(), and setTolerant().

◆ readClasses

DescriptionVector ThePEG::PersistentIStream::readClasses
private

Lists of classes and corresponding version strings that have been read.

Definition at line 434 of file PersistentIStream.h.

◆ readObjects

ObjectVector ThePEG::PersistentIStream::readObjects
private

Lists of objects that have been read.

Definition at line 429 of file PersistentIStream.h.

◆ subVersion

int ThePEG::PersistentIStream::subVersion
private

Subversion number of the PersistentOStream which has written the file being read.

Definition at line 464 of file PersistentIStream.h.

◆ tBegin

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

The special marker character indicating the beginning of an object.

Definition at line 476 of file PersistentIStream.h.

Referenced by beginObject().

◆ tEnd

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

The special marker character indicating the end of an object.

Definition at line 481 of file PersistentIStream.h.

◆ theGlobalLibraries

vector<string> ThePEG::PersistentIStream::theGlobalLibraries
private

Global libraries loaded in the initialization.

Definition at line 469 of file PersistentIStream.h.

Referenced by globalLibraries().

◆ theIStream

istream* ThePEG::PersistentIStream::theIStream
private

A pointer to the associated istream.

Definition at line 439 of file PersistentIStream.h.

Referenced by is().

◆ tNext

const char ThePEG::PersistentIStream::tNext = '|'
staticprivate

The marker character indicating the beginning of the next base class in case of multiple inheritance.

Definition at line 487 of file PersistentIStream.h.

◆ tNo

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

The special marker character indicating a false boolean value.

Definition at line 513 of file PersistentIStream.h.

◆ tNoSep

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

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

Definition at line 503 of file PersistentIStream.h.

Referenced by escaped().

◆ tNull

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

The special marker character indicating an escaped marker character.

Definition at line 492 of file PersistentIStream.h.

◆ tSep

const char ThePEG::PersistentIStream::tSep = '\n'
staticprivate

The special marker character indicating the end of a value.

Definition at line 497 of file PersistentIStream.h.

Referenced by escaped(), getSep(), and skipField().

◆ tYes

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

The special marker character indicating a true boolean value.

Definition at line 508 of file PersistentIStream.h.

◆ version

int ThePEG::PersistentIStream::version
private

Version number of the PersistentOStream which has written the file being read.

Definition at line 460 of file PersistentIStream.h.


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