thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
DescribeClass.h
1 // -*- C++ -*-
2 //
3 // DescribeClass.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_DescribeClass_H
10 #define ThePEG_DescribeClass_H
11 
12 #include "ThePEG/Utilities/ClassDescription.h"
13 
14 namespace ThePEG {
15 
22 template <typename BaseT1, typename BaseT2 = int,
23  typename BaseT3 = int, typename BaseT4 = int>
24 struct BaseClasses {};
25 
30 template <typename T>
32 
34  typedef T Base1;
35 
37  typedef int Base2;
38 
40  typedef int Base3;
41 
43  typedef int Base4;
44 
45 };
46 
51 template <typename BaseT1, typename BaseT2, typename BaseT3, typename BaseT4>
52 struct BaseClassesTraits< BaseClasses<BaseT1,BaseT2,BaseT3,BaseT4> > {
53 
55  typedef BaseT1 Base1;
56 
58  typedef BaseT2 Base2;
59 
61  typedef BaseT3 Base3;
62 
64  typedef BaseT4 Base4;
65 
66 };
67 
72 template <typename T, bool NoPIO>
74 
78  static void output(const T & t, PersistentOStream & os) {
79  t.persistentOutput(os);
80  }
81 
85  static void input(T & t, PersistentIStream & is, int oldVersion) {
86  t.persistentInput(is, oldVersion);
87  }
88 
89 };
90 
95 template <typename T>
96 struct DescribeClassPIOHelper<T,true> {
97 
101  static void output(const T &, PersistentOStream &) {}
102 
106  static void input(T &, PersistentIStream &, int) {}
107 
108 };
109 
114 template <typename T, bool abstract>
116 
120  static typename ThePEG::Ptr<T>::pointer create() {
121  return new_ptr(T());
122  }
123 };
124 
129 template <typename T>
131 
135  static typename ThePEG::Ptr<T>::pointer create() {
136  throw std::logic_error("Tried to instantiate abstract class " +
138  }
139 
140 };
141 
142 
143 
144 
158 template <typename T, typename BaseT, bool Abstract = false, bool NoPIO = false>
160 
161 public:
162 
165 
170  DescribeClassT(string cname, string lib, int vers = 0)
171  : ClassDescriptionBase(cname, typeid(T), vers, lib, Abstract) {
173  T::Init();
174  }
175 
179  virtual ~DescribeClassT() {}
180 
184  virtual void setup() {
185  DescriptionVector bases;
186  const ClassDescriptionBase * b =
188  if ( b ) bases.push_back(b);
190  if ( b ) bases.push_back(b);
192  if ( b ) bases.push_back(b);
194  if ( b ) bases.push_back(b);
195  baseClasses(bases.begin(), bases.end());
196  }
197 
201  virtual BPtr create() const {
203  }
204 
208  virtual void output(tcBPtr o, PersistentOStream & os) const {
211  }
212 
216  virtual void input(tBPtr o, PersistentIStream & is, int oldVersion) const {
217  tTPtr t = dynamic_ptr_cast<tTPtr>(o);
218  DescribeClassPIOHelper<T,NoPIO>::input(*t, is, oldVersion);
219  }
220 
221 };
222 
243 template <typename T, typename BaseT = int,
244  bool Abstract = false, bool NoPIO = false>
245 class DescribeClass: public DescribeClassT<T,BaseT,Abstract,NoPIO> {
246 
247 public:
248 
253  DescribeClass(string cname, string lib, int vers = 0)
254  : DescribeClassT<T,BaseT,Abstract,NoPIO>(cname, lib, vers) {}
255 
256 };
257 
276 template <typename T, typename BaseT = int>
277 class DescribeNoPIOClass: public DescribeClassT<T,BaseT,false,true> {
278 
279 public:
280 
285  DescribeNoPIOClass(string cname, string lib, int vers = 0)
286  : DescribeClassT<T,BaseT,false,true>(cname, lib, vers) {}
287 
288 };
289 
308 template <typename T, typename BaseT = int>
309 class DescribeAbstractClass: public DescribeClassT<T,BaseT,true,false> {
310 
311 public:
312 
317  DescribeAbstractClass(string cname, string lib, int vers = 0)
318  :DescribeClassT<T,BaseT,true,false>(cname, lib, vers) {}
319 
320 };
321 
340 template <typename T, typename BaseT = int>
341 class DescribeAbstractNoPIOClass: public DescribeClassT<T,BaseT,true,true> {
342 
343 public:
344 
349  DescribeAbstractNoPIOClass(string cname, string lib, int vers = 0)
350  :DescribeClassT<T,BaseT,true,true>(cname, lib, vers) {}
351 
352 };
353 
354 }
355 
356 
357 #endif /* ThePEG_DescribeClass_H */
Ptr< T >::pointer new_ptr()
Simple interface to the PtrTraits<Ptr>::create()
Definition: PtrTraits.h:195
PersistentIStream is used to read persistent objects from a stream where they were previously written...
ClassDescriptionBase is the base class for all class description classes.
static void output(const T &, PersistentOStream &)
Do nothing as T has no persistent I/O functions.
static void input(T &t, PersistentIStream &is, int oldVersion)
Call standard input function.
Definition: DescribeClass.h:85
DescribeClass and its companion classes DescribeAbstractClass, DescribeNoPIOClass and DescribeAbstrac...
static const ClassDescriptionBase * find(const type_info &ti)
Get the description of a class giving its type_info object.
Define the base class from which all (polymorphic) classes in ThePEG are derived. ...
Definition: ThePEG.h:54
DescribeClass and its companion classes DescribeAbstractClass, DescribeNoPIOClass and DescribeAbstrac...
static void Register(ClassDescriptionBase &)
Insert a description in the list.
virtual void input(tBPtr o, PersistentIStream &is, int oldVersion) const
Call standard input function.
virtual void setup()
Set up the base class information for this object.
PersistentOStream is used to write objects persistently to a stream from which they can be read in ag...
TransientConstRCPtr is a simple wrapper around a bare const pointer which can be assigned to and from...
Definition: RCPtr.h:696
DescribeClass and its companion classes DescribeAbstractClass, DescribeNoPIOClass and DescribeAbstrac...
TransientRCPtr is a simple wrapper around a bare pointer which can be assigned to and from an RCPtr a...
Definition: RCPtr.h:519
T1 dynamic_ptr_cast(const T2 &t2)
Replacement for the standard dynamic_cast.
Definition: PtrTraits.h:168
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
Helper class used by DescribeClassT for transparent handling of classes with and without persistent I...
Definition: DescribeClass.h:73
#define ThePEG_DECLARE_TEMPLATE_POINTERS(full, abbrev)
This macro helps us to declare pointers and stuff to standard classes.
Definition: Pointers.h:36
virtual void output(tcBPtr o, PersistentOStream &os) const
Call standard output function.
Helper class used by DescribeClassT for transparent handling of abstract and concrete classes...
T Base1
The first base class.
Definition: DescribeClass.h:34
DescribeClass and its companion classes DescribeAbstractClass, DescribeNoPIOClass and DescribeAbstrac...
DescribeNoPIOClass(string cname, string lib, int vers=0)
Constructor taking the name of the class, the dynamic library where it is located and an optional ver...
Helper class for multiple base classes.
Definition: DescribeClass.h:24
DescribeAbstractClass(string cname, string lib, int vers=0)
Constructor taking the name of the class, the dynamic library where it is located and an optional ver...
static void input(T &, PersistentIStream &, int)
Do nothing as T has no persistent I/O functions.
DescribeClassT(string cname, string lib, int vers=0)
Constructor taking the name of the class, the dynamic library where it is located and an optional ver...
static void output(const T &t, PersistentOStream &os)
Call standard output function.
Definition: DescribeClass.h:78
Traits class used by DescribeCLassT for transparent handling of one base class or a several base clas...
Definition: DescribeClass.h:31
RCPtr is a reference counted (smart) pointer.
Definition: RCPtr.h:60
static ThePEG::Ptr< T >::pointer create()
Default-creat an object.
#define ThePEG_DECLARE_POINTERS(full, abbrev)
This macro helps us to declare pointers and stuff to standard classes.
Definition: Pointers.h:47
DescribeClass(string cname, string lib, int vers=0)
Constructor taking the name of the class, the dynamic library where it is located and an optional ver...
static ThePEG::Ptr< T >::pointer create()
Throw an exception as the class is bastract.
virtual ~DescribeClassT()
The descructor.
virtual BPtr create() const
Default-create an object.
int Base4
The fourth base class.
Definition: DescribeClass.h:43
The default concrete implementation of ClassTraitsBase.
Definition: ClassTraits.h:134
vector< const ClassDescriptionBase * > DescriptionVector
A vector of class descriptions.
int Base2
The second base class.
Definition: DescribeClass.h:37
int Base3
The third base class.
Definition: DescribeClass.h:40
DescribeAbstractNoPIOClass(string cname, string lib, int vers=0)
Constructor taking the name of the class, the dynamic library where it is located and an optional ver...
DescribeClassT and its derived companion classes DescribeClass DescribeAbstractClass, DescribeNoPIOClass and DescribeAbstractNoPIOClass, is a simplified interface to the type information system in ThePEG.