9 #ifndef ThePEG_PersistentOStream_H 10 #define ThePEG_PersistentOStream_H 13 #include "ThePEG/Config/ThePEG.h" 14 #include "ThePEG/Utilities/ClassDescription.h" 15 #include "ThePEG/Utilities/Exception.h" 16 #include "ThePEG/Utilities/Debug.h" 17 #include "PersistentOStream.fh" 18 #include "PersistentOStream.xh" 104 template <
typename T>
114 template <
typename T>
124 template <
typename T>
136 for ( string::const_iterator i = s.begin(); i < s.end(); ++i )
escape(*i);
154 return (*
this) <<
static_cast<char>(c);
161 return (*
this) <<
static_cast<char>(c);
222 if ( isnan(d) || isinf(d) )
224 <<
"Tried to write a NaN or Inf double to a persistent stream." 226 os() << setprecision(18) << d;
235 if ( isnan(f) || isinf(f) )
237 <<
"Tried to write a NaN or Inf float to a persistent stream." 239 os() << setprecision(9) << f;
270 *
this << z.real() << z.imag();
278 template <
typename Container>
281 for (
typename Container::const_iterator it = c.begin();
282 it != c.end() &&
good() ; ++it )
331 operator bool()
const {
return good(); }
344 struct MissingClass:
public Exception {};
406 static const char tNo =
'n';
413 return c == tBegin || c == tEnd || c == tNext || c == tSep || c ==
tNull;
466 put( c == tSep? tNoSep: c );
484 void init(
const vector<string> & libs);
566 template <
typename T1,
typename T2>
568 const pair<T1,T2> & p) {
569 return os << p.first << p.second;
575 template <
typename Key,
typename T,
typename Cmp,
typename A>
577 const multimap<Key,T,Cmp,A> & m) {
585 template <
typename Key,
typename T,
typename Cmp,
typename A>
587 const map<Key,T,Cmp,A> & m) {
595 template <
typename Key,
typename Cmp,
typename A>
597 const set<Key,Cmp,A> & s) {
606 template <
typename Key,
typename Cmp,
typename A>
608 const multiset<Key,Cmp,A> & s) {
617 template <
typename T,
typename A>
619 const list<T,A> & l) {
628 template <
typename T,
typename A>
630 const vector<T,A> & v) {
638 template <
typename T,
typename A>
640 const deque<T,A> & d) {
PersistentOStream & operator<<(bool t)
Write a boolean.
PersistentOStream & operator<<(unsigned long i)
Write an unsigned long integer.
void writeClassDescription(const ClassDescriptionBase *)
write out class information to the associated ostream.
PersistentOStream & operator<<(int i)
Write an integer.
PersistentOStream & operator=(const PersistentOStream &)
Standard ctors and assignment are private and not implemented.
PersistentOStream & operator<<(float f)
Write a float.
ClassDescriptionBase is the base class for all class description classes.
void checkState()
Check if the state is ok.
void endBase()
Put an "next base class" marker on the associated ostream.
static const int subVersion
The subversion of this PersistentOStream implementation.
Define the base class from which all (polymorphic) classes in ThePEG are derived. ...
PersistentOStream & operator<<(const RCPtr< T > &p)
Operator for writing persistent objects to the stream.
std::complex< double > Complex
ThePEG code should use Complex for all complex scalars.
PersistentOStream is used to write objects persistently to a stream from which they can be read in ag...
PersistentOStream & operator<<(unsigned int i)
Write an unsigned integer.
TransientConstRCPtr is a simple wrapper around a bare const pointer which can be assigned to and from...
PersistentOStream & operator<<(char c)
Write a character.
ConstRCPtr is a reference counted (smart) const pointer.
void setBadState()
Set the stream in a bad state.
PersistentOStream & flush()
Remove all objects that have been written, except those which are to be saved, from the list of writt...
ostream * theOStream
A pointer to the associated ostream.
This is the main namespace within which all identifiers in ThePEG are declared.
void beginObject()
Put a "begin object" marker on the associated ostream.
PersistentOStream & operator<<(signed char c)
Write a signed character.
static const char tNull
The special marker character indicating an escaped marker character.
map< cBPtr, int, less< cBPtr > > ObjectMap
A map of objects indexed by integers.
static const char tNoSep
The special marker character used to avoid confusion with escaped tSep markers.
PersistentOStream & operator<<(unsigned char c)
Write an unsigned character.
PersistentOStream & operator<<(Complex z)
Write a Complex.
ClassMap writtenClasses
List of written classes.
PersistentOStream & operator<<(const char *s)
Write a c-style character string (to be read in as a std::string).
ThePEG_DECLARE_MAP(long, PDPtr, ParticleMap)
A map relating integers to ParticleData objects.
void put(char c)
Put a character on the associated ostream.
void putContainer(const Container &c)
Output of containers of streamable objects.
~PersistentOStream()
The destructor.
void escape(char c)
Put a character on the associated ostream but escape it if it is a token.
bool badState
True if no errors has occurred.
Severe error, (the run should be terminated).
ostream & os()
Return a reference to the associated ostream.
const ostream & os() const
Return a const reference to the associated ostream.
static const char tNext
The marker character indicating the beginning of the next base class in case of multiple inheritance...
void init(const vector< string > &libs)
Write out initial metainfo on the stream.
static const char tYes
The special marker character indicating a true boolean value.
PersistentOStream & outputPointer(tcBPtr)
Write out a persistent object given a pointer to it.
bool allocStream
True if the associated ostream should be deleted in the destructor.
RCPtr is a reference counted (smart) pointer.
static const char tNo
The special marker character indicating a false boolean value.
static const char tEnd
The special marker character indicating the end of an object.
#define ThePEG_DECLARE_POINTERS(full, abbrev)
This macro helps us to declare pointers and stuff to standard classes.
static const char tBegin
The special marker character indicating the beginning of an object.
const ClassDescriptionBase * writeClassId(tcBPtr)
Write out class information to the associated ostream.
ClassDescriptionBase::DescriptionVector DescriptionVector
A vector of bare pointers to InputDescription objects.
Exception is the base class for all exceptions to be used in ThePEG.
static const int version
The version of this PersistentOStream implementation.
PersistentOStream & push()
Instuct the stream to save the following objects (protecting them from being flushed).
void endObject()
Put a "end of object" marker on the associated ostream.
PersistentOStream & operator<<(short i)
Write a short integer.
PersistentOStream & operator<<(unsigned short i)
Write an unsigned short integer.
vector< const ClassDescriptionBase * > DescriptionVector
A vector of class descriptions.
bool operator!() const
Check the state of the stream.
PersistentOStream & operator<<(long i)
Write a long integer.
PersistentOStream()
Standard ctors and assignment are private and not implemented.
map< const ClassDescriptionBase *, int, less< const ClassDescriptionBase * > > ClassMap
A map relating class descriptions to integers.
bool isToken(char c) const
Return true if the given character is aspecial marker character.
bool good() const
Check the state of the stream.
void putObjectPart(tcBPtr obj, const ClassDescriptionBase *cd)
For a given object, write the member variables corresponding to a given ClassDescriptionBase object...
stack< int > lastSavedObject
List of written objects that are to be saved.
static const char tSep
The special marker character indicating the end of a value.
PersistentOStream & pop()
Instuct the stream not to save the following objects.
PersistentOStream & operator<<(double d)
Write a double.
ObjectMap writtenObjects
List of written objects.
PersistentOStream & operator<<(string s)
Write a character string.