thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
ClassDescription.h
1// -*- C++ -*-
2//
3// ClassDescription.h is a part of ThePEG - Toolkit for HEP Event Generation
4// Copyright (C) 1999-2019 Leif Lonnblad
5//
6// ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7// Please respect the MCnet academic guidelines, see GUIDELINES for details.
8//
9#ifndef ThePEG_ClassDescription_H
10#define ThePEG_ClassDescription_H
11
13#include "ClassDescription.fh"
14#include "ThePEG/Utilities/Named.h"
15#include "ThePEG/Persistency/PersistentOStream.fh"
16#include "ThePEG/Persistency/PersistentIStream.fh"
17#include "ClassTraits.h"
18#include "DescriptionList.h"
19
20namespace ThePEG {
21
64
65public:
66
68 typedef vector<const ClassDescriptionBase *> DescriptionVector;
69
70protected:
71
81 ClassDescriptionBase(string newName,
82 const type_info & newInfo,
83 int newVersion,
84 string newLibrary,
85 bool abst)
86 : Named(newName), theVersion(newVersion), theLibrary(newLibrary),
87 theInfo(newInfo), isAbstract(abst), done(false) {}
88
89public:
90
95
99 const type_info & info() const { return theInfo; }
100
104 int version() const { return theVersion; }
105
110 string library() const { return theLibrary; }
111
115 bool check() const { return done; }
116
122
126 virtual void setup() = 0;
127
131 virtual BPtr create() const = 0;
132
139 virtual void output(tcBPtr b, PersistentOStream & os) const = 0;
140
148 virtual void input(tBPtr b, PersistentIStream & is, int oldVersion) const = 0;
149
154 bool isA(const ClassDescriptionBase & base) const;
155
159 bool abstract() const { return isAbstract; }
160
161protected:
162
169 void baseClasses(DescriptionVector::iterator first,
170 DescriptionVector::iterator last)
171 {
172 theBaseClasses = DescriptionVector(first, last);
173 done = true;
174 }
175
176private:
177
182
187
191 const type_info & theInfo;
192
197
202
206 bool done;
207
208};
209
214template <typename T, int IBase,
215 typename B = typename BaseClassTrait<T,IBase>::NthBase>
218 static void addBases(vector<const ClassDescriptionBase *> & c){
219 const ClassDescriptionBase * b = DescriptionList::find(typeid(B));
220 if ( !b ) return;
221 c.push_back(b);
223 }
224};
225
232template <typename T, int IBase>
233struct ClassDescriptionHelper<T, IBase, int> {
235 static void addBases(vector<const ClassDescriptionBase *> & ) {}
236};
237
244template <typename T>
246
247public:
248
251
252public:
253
259 : ClassDescriptionBase(Traits::className(), typeid(T), Traits::version(),
260 Traits::library(), abst)
261 {
263 T::Init();
264 }
265
269 virtual void setup() {
270 DescriptionVector bases;
272 baseClasses(bases.begin(), bases.end());
273 }
274
275};
276
281template <typename T>
283
284public:
285
288
289public:
290
295
300 virtual BPtr create() const {
301 throw std::logic_error("Tried to instantiate virtual class " + Named::name());
302 }
303
310 virtual void output(tcBPtr b, PersistentOStream & os) const {
312 }
313
321 virtual void input(tBPtr b, PersistentIStream & is,
322 int oldVersion) const {
323 Traits::input(Traits::cast(b), is, oldVersion);
324 }
325
326};
327
332template <typename T>
334
335public:
336
339
340public:
341
346
350 virtual BPtr create() const { return Traits::create(); }
351
358 virtual void output(tcBPtr b, PersistentOStream & os) const {
360 }
361
369 virtual void input(tBPtr b, PersistentIStream & is,
370 int oldVersion) const {
371 Traits::input(Traits::cast(b), is, oldVersion);
372 }
373
374};
375
380template <typename T>
382
383public:
384
387
388public:
389
394
398 virtual BPtr create() const { return Traits::create(); }
399
403 virtual void output(tcBPtr, PersistentOStream &) const {}
404
408 virtual void input(tBPtr, PersistentIStream &, int) const {}
409
410};
411
416template <typename T>
418
419public:
420
423
424public:
425
430
435 virtual BPtr create() const {
436 throw std::logic_error("Tried to instantiate virtual class " + Named::name());
437 }
438
442 virtual void output(tcBPtr, PersistentOStream & ) const {}
443
447 virtual void input(tBPtr, PersistentIStream &, int) const {}
448
449};
450
451}
452
453#define ThePEG_DECLARE_CLASS_DESCRIPTION(Class) \
454 \
455static ClassDescription<Class> init ## Class \
456
457#define ThePEG_DECLARE_ABSTRACT_CLASS_DESCRIPTION(Class) \
458 \
459static AbstractClassDescription<Class> init ## Class \
460
461#define ThePEG_DECLARE_NOPIO_CLASS_DESCRIPTION(Class) \
462 \
463static NoPIOClassDescription<Class> init ## Class \
464
465#define ThePEG_DECLARE_ABSTRACT_NOPIO_CLASS_DESCRIPTION(Class) \
466 \
467static AbstractNoPIOClassDescription<Class> init ## Class \
468
469#define ThePEG_IMPLEMENT_CLASS_DESCRIPTION(Class) \
470ClassDescription<Class> Class::init ## Class \
471
472#define ThePEG_IMPLEMENT_ABSTRACT_CLASS_DESCRIPTION(Class) \
473AbstractClassDescription<Class> Class::init ## Class \
474
475#define ThePEG_IMPLEMENT_NOPIO_CLASS_DESCRIPTION(Class) \
476NoPIOClassDescription<Class> Class::init ## Class \
477
478#define ThePEG_IMPLEMENT_ABSTRACT_NOPIO_CLASS_DESCRIPTION(Class) \
479AbstractNoPIOClassDescription<Class> Class::init ## Class \
480
481#endif /* ThePEG_ClassDescription_H */
This is the main config header file for ThePEG.
A concreate implementation of ClassDescriptionBase describing an abstract class with persistent data.
virtual void output(tcBPtr b, PersistentOStream &os) const
Output the members of an object of the described class to a persistent stream.
virtual BPtr create() const
Do not create an object of the described class (which is abstract).
ClassTraits< T > Traits
The traits class for the template argument class.
virtual void input(tBPtr b, PersistentIStream &is, int oldVersion) const
Read the members of an object of the described class from a persistent stream.
AbstractClassDescription()
Default constructor.
A concreate implementation of ClassDescriptionBase describing an abstract class without persistent da...
virtual void output(tcBPtr, PersistentOStream &) const
Do nothing since the described class has no persistent data.
virtual BPtr create() const
Do not create an object of the described class (which is abstract).
ClassTraits< T > Traits
The traits class for the template argument class.
virtual void input(tBPtr, PersistentIStream &, int) const
Do nothing since the described class has no persistent data.
AbstractNoPIOClassDescription()
Default constructor.
ClassDescriptionBase is the base class for all class description classes.
ClassDescriptionBase(string newName, const type_info &newInfo, int newVersion, string newLibrary, bool abst)
The constructor used by sub-classes.
const type_info & theInfo
The type_info object for the described class.
string theLibrary
The library file where this class may be found.
bool done
True if this object was set up properly.
bool abstract() const
Return true if the corresponding class is abstract.
string library() const
The name of a file containing the dynamic library where the class is implemented.
virtual void setup()=0
Set up the base class information for this object.
DescriptionVector theBaseClasses
The vector of base classes.
int theVersion
The version of the described class.
vector< const ClassDescriptionBase * > DescriptionVector
A vector of class descriptions.
const DescriptionVector & descriptions() const
Return the descriptions of the base classes of the described class.
bool isA(const ClassDescriptionBase &base) const
Return true if the class described by the argument is a base class of the class described by this.
bool isAbstract
True if this class is abstract.
int version() const
The version of the described class.
void baseClasses(DescriptionVector::iterator first, DescriptionVector::iterator last)
Set the base classes.
virtual void input(tBPtr b, PersistentIStream &is, int oldVersion) const =0
Read the members of an object of the described class from a persistent stream.
virtual void output(tcBPtr b, PersistentOStream &os) const =0
Output the members of an object of the described class to a persistent stream.
const type_info & info() const
The standart RTTI type_info object for the described class.
bool check() const
Return true if this object was set up properly.
virtual ~ClassDescriptionBase()
Empty destructor.
virtual BPtr create() const =0
Create an object of the described class.
An intermediate templated base class derived from ClassDescriptionBase.
virtual void setup()
Set up the base class information for this object.
ClassDescriptionTBase(bool abst)
Default constructor.
ClassTraits< T > Traits
The traits class for the template argument class.
A concreate implementation of ClassDescriptionBase describing a concrete class with persistent data.
virtual void output(tcBPtr b, PersistentOStream &os) const
Output the members of an object of the described class to a persistent stream.
virtual BPtr create() const
Create an object of the described class.
ClassDescription()
Default constructor.
virtual void input(tBPtr b, PersistentIStream &is, int oldVersion) const
Read the members of an object of the described class from a persistent stream.
ClassTraits< T > Traits
The traits class for the template argument class.
static const ClassDescriptionBase * find(const type_info &ti)
Get the description of a class giving its type_info object.
static void Register(ClassDescriptionBase &)
Insert a description in the list.
The Named class is a simple concrete base class to used by classes of objects with a name.
Definition: Named.h:24
const string & name() const
Return name.
Definition: Named.h:42
A concreate implementation of ClassDescriptionBase describing a concrete class without persistent dat...
ClassTraits< T > Traits
The traits class for the template argument class.
NoPIOClassDescription()
Default constructor.
virtual void input(tBPtr, PersistentIStream &, int) const
Do nothing since the described class has no persistent data.
virtual BPtr create() const
Create an object of the described class.
virtual void output(tcBPtr, PersistentOStream &) const
Do nothing since the described class has no persistent data.
PersistentIStream is used to read persistent objects from a stream where they were previously written...
PersistentOStream is used to write objects persistently to a stream from which they can be read in ag...
RCPtr is a reference counted (smart) pointer.
Definition: RCPtr.h:60
TransientConstRCPtr is a simple wrapper around a bare const pointer which can be assigned to and from...
Definition: RCPtr.h:696
TransientRCPtr is a simple wrapper around a bare pointer which can be assigned to and from an RCPtr a...
Definition: RCPtr.h:519
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
int NthBase
The type of the BaseN'th base class (int means there are no further base classes).
Definition: ClassTraits.h:161
A helper class for tracing the base classes of a class to be described.
static void addBases(vector< const ClassDescriptionBase * > &c)
Add base classes.
static TPtr cast(BPtr b)
Perform a dynamic cast from the given pointer to a pointer to T.
Definition: ClassTraits.h:106
static TPtr create()
Create a T object and return a smart pointer to it.
Definition: ClassTraits.h:60
static void input(tTPtr t, PersistentIStream &is, int oldVersion)
Read the T part of an object from a persistent stream.
Definition: ClassTraits.h:99
static void output(tcTPtr t, PersistentOStream &os)
Write the T part of an object to a persistent stream.
Definition: ClassTraits.h:92
The default concrete implementation of ClassTraitsBase.
Definition: ClassTraits.h:134