thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
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 
12 #include "ThePEG/Config/ThePEG.h"
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 
20 namespace ThePEG {
21 
63 class ClassDescriptionBase: public Named {
64 
65 public:
66 
68  typedef vector<const ClassDescriptionBase *> DescriptionVector;
69 
70 protected:
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 
89 public:
90 
94  virtual ~ClassDescriptionBase();
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 
121  const DescriptionVector & descriptions() const { return theBaseClasses; }
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 
161 protected:
162 
169  void baseClasses(DescriptionVector::iterator first,
170  DescriptionVector::iterator last)
171  {
172  theBaseClasses = DescriptionVector(first, last);
173  done = true;
174  }
175 
176 private:
177 
182 
186  string theLibrary;
187 
191  const type_info & theInfo;
192 
196  DescriptionVector theBaseClasses;
197 
202 
206  bool done;
207 
208 };
209 
214 template <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 
232 template <typename T, int IBase>
233 struct ClassDescriptionHelper<T, IBase, int> {
235  static void addBases(vector<const ClassDescriptionBase *> & ) {}
236 };
237 
244 template <typename T>
246 
247 public:
248 
251 
252 public:
253 
259  : ClassDescriptionBase(Traits::className(), typeid(T), Traits::version(),
260  Traits::library(), abst)
261  {
263  T::Init();
264  }
265 
266 
271 
275  virtual void setup() {
276  DescriptionVector bases;
278  baseClasses(bases.begin(), bases.end());
279  }
280 
281 };
282 
287 template <typename T>
289 
290 public:
291 
294 
295 public:
296 
301 
306  virtual BPtr create() const {
307  throw std::logic_error("Tried to instantiate virtual class " + Named::name());
308  }
309 
316  virtual void output(tcBPtr b, PersistentOStream & os) const {
317  Traits::output(Traits::cast(b), os);
318  }
319 
327  virtual void input(tBPtr b, PersistentIStream & is,
328  int oldVersion) const {
329  Traits::input(Traits::cast(b), is, oldVersion);
330  }
331 
332 };
333 
338 template <typename T>
340 
341 public:
342 
345 
346 public:
347 
352 
356  virtual BPtr create() const { return Traits::create(); }
357 
364  virtual void output(tcBPtr b, PersistentOStream & os) const {
365  Traits::output(Traits::cast(b), os);
366  }
367 
375  virtual void input(tBPtr b, PersistentIStream & is,
376  int oldVersion) const {
377  Traits::input(Traits::cast(b), is, oldVersion);
378  }
379 
380 };
381 
386 template <typename T>
388 
389 public:
390 
393 
394 public:
395 
400 
404  virtual BPtr create() const { return Traits::create(); }
405 
409  virtual void output(tcBPtr, PersistentOStream &) const {}
410 
414  virtual void input(tBPtr, PersistentIStream &, int) const {}
415 
416 };
417 
422 template <typename T>
424 
425 public:
426 
429 
430 public:
431 
436 
441  virtual BPtr create() const {
442  throw std::logic_error("Tried to instantiate virtual class " + Named::name());
443  }
444 
448  virtual void output(tcBPtr, PersistentOStream & ) const {}
449 
453  virtual void input(tBPtr, PersistentIStream &, int) const {}
454 
455 };
456 
457 }
458 
459 #define ThePEG_DECLARE_CLASS_DESCRIPTION(Class) \
460  \
461 static ClassDescription<Class> init ## Class \
462 
463 #define ThePEG_DECLARE_ABSTRACT_CLASS_DESCRIPTION(Class) \
464  \
465 static AbstractClassDescription<Class> init ## Class \
466 
467 #define ThePEG_DECLARE_NOPIO_CLASS_DESCRIPTION(Class) \
468  \
469 static NoPIOClassDescription<Class> init ## Class \
470 
471 #define ThePEG_DECLARE_ABSTRACT_NOPIO_CLASS_DESCRIPTION(Class) \
472  \
473 static AbstractNoPIOClassDescription<Class> init ## Class \
474 
475 #define ThePEG_IMPLEMENT_CLASS_DESCRIPTION(Class) \
476 ClassDescription<Class> Class::init ## Class \
477 
478 #define ThePEG_IMPLEMENT_ABSTRACT_CLASS_DESCRIPTION(Class) \
479 AbstractClassDescription<Class> Class::init ## Class \
480 
481 #define ThePEG_IMPLEMENT_NOPIO_CLASS_DESCRIPTION(Class) \
482 NoPIOClassDescription<Class> Class::init ## Class \
483 
484 #define ThePEG_IMPLEMENT_ABSTRACT_NOPIO_CLASS_DESCRIPTION(Class) \
485 AbstractNoPIOClassDescription<Class> Class::init ## Class \
486 
487 #endif /* ThePEG_ClassDescription_H */
NoPIOClassDescription()
Default constructor.
virtual BPtr create() const
Do not create an object of the described class (which is abstract).
PersistentIStream is used to read persistent objects from a stream where they were previously written...
ClassTraits< T > Traits
The traits class for the template argument class.
virtual BPtr create() const =0
Create an object of the described class.
virtual void output(tcBPtr, PersistentOStream &) const
Do nothing since the described class has no persistent data.
ClassDescriptionBase is the base class for all class description classes.
virtual BPtr create() const
Create an object of the described class.
static const ClassDescriptionBase * find(const type_info &ti)
Get the description of a class giving its type_info object.
A concreate implementation of ClassDescriptionBase describing a concrete class with persistent data...
static void Register(ClassDescriptionBase &)
Insert a description in the list.
const type_info & theInfo
The type_info object for the described class.
PersistentOStream is used to write objects persistently to a stream from which they can be read in ag...
A concreate implementation of ClassDescriptionBase describing an abstract class with persistent data...
ClassDescription()
Default constructor.
TransientConstRCPtr is a simple wrapper around a bare const pointer which can be assigned to and from...
Definition: RCPtr.h:696
virtual void input(tBPtr b, PersistentIStream &is, int oldVersion) const
Read the members of an object of the described class from a persistent stream.
TransientRCPtr is a simple wrapper around a bare pointer which can be assigned to and from an RCPtr a...
Definition: RCPtr.h:519
static void addBases(vector< const ClassDescriptionBase *> &c)
Add base classes.
virtual BPtr create() const
Do not create an object of the described class (which is abstract).
An intermediate templated base class derived from ClassDescriptionBase.
void baseClasses(DescriptionVector::iterator first, DescriptionVector::iterator last)
Set the base classes.
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
The Named class is a simple concrete base class to used by classes of objects with a name...
Definition: Named.h:24
ClassTraits< T > Traits
The traits class for the template argument class.
ClassDescriptionTBase(bool abst)
Default constructor.
This is the main config header file for ThePEG.
DescriptionVector theBaseClasses
The vector of base classes.
A concreate implementation of ClassDescriptionBase describing a concrete class without persistent dat...
virtual void setup()
Set up the base class information for this object.
int theVersion
The version of the described class.
virtual void setup()=0
Set up the base class information for this object.
string theLibrary
The library file where this class may be found.
ClassTraits< T > Traits
The traits class for the template argument class.
const type_info & info() const
The standart RTTI type_info object for the described class.
ClassTraits< T > Traits
The traits class for the template argument class.
virtual BPtr create() const
Create an object of the described class.
A concreate implementation of ClassDescriptionBase describing an abstract class without persistent da...
ClassDescriptionBase(string newName, const type_info &newInfo, int newVersion, string newLibrary, bool abst)
The constructor used by sub-classes.
bool isAbstract
True if this class is abstract.
virtual void input(tBPtr b, PersistentIStream &is, int oldVersion) const
Read the members of an object of the described class from a persistent stream.
AbstractNoPIOClassDescription()
Default constructor.
int version() const
The version of the described class.
AbstractClassDescription()
Default constructor.
RCPtr is a reference counted (smart) pointer.
Definition: RCPtr.h:60
const string & name() const
Return name.
Definition: Named.h:42
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...
virtual void input(tBPtr, PersistentIStream &, int) const
Do nothing since the described class has no persistent data.
virtual void output(tcBPtr b, PersistentOStream &os) const
Output the members of an object of the described class to a persistent stream.
string library() const
The name of a file containing the dynamic library where the class is implemented. ...
virtual void output(tcBPtr b, PersistentOStream &os) const
Output the members of an object of the described class to 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.
The default concrete implementation of ClassTraitsBase.
Definition: ClassTraits.h:134
vector< const ClassDescriptionBase * > DescriptionVector
A vector of class descriptions.
int NthBase
The type of the BaseN&#39;th base class (int means there are no further base classes).
Definition: ClassTraits.h:161
virtual ~ClassDescriptionTBase()
The descructor.
const DescriptionVector & descriptions() const
Return the descriptions of the base classes of the described class.
bool check() const
Return true if this object was set up properly.
bool done
True if this object was set up properly.
virtual void input(tBPtr, PersistentIStream &, int) const
Do nothing since the described class has no persistent data.
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.
A helper class for tracing the base classes of a class to be described.
virtual void output(tcBPtr, PersistentOStream &) const
Do nothing since the described class has no persistent data.
ClassTraits< T > Traits
The traits class for the template argument class.
virtual ~ClassDescriptionBase()
Empty destructor.