thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
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
14namespace ThePEG {
15
22template <typename BaseT1, typename BaseT2 = int,
23 typename BaseT3 = int, typename BaseT4 = int>
24struct BaseClasses {};
25
30template <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
51template <typename BaseT1, typename BaseT2, typename BaseT3, typename BaseT4>
52struct 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
72template <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
95template <typename T>
96struct DescribeClassPIOHelper<T,true> {
97
101 static void output(const T &, PersistentOStream &) {}
102
106 static void input(T &, PersistentIStream &, int) {}
107
108};
109
114template <typename T, bool abstract>
116
120 static typename ThePEG::Ptr<T>::pointer create() {
121 return new_ptr(T());
122 }
123};
124
129template <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
158template <typename T, typename BaseT, bool Abstract = false, bool NoPIO = false>
160
161public:
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 {
209 tcTPtr t = dynamic_ptr_cast<tcTPtr>(o);
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
243template <typename T, typename BaseT = int,
244 bool Abstract = false, bool NoPIO = false>
245class DescribeClass: public DescribeClassT<T,BaseT,Abstract,NoPIO> {
246
247public:
248
253 DescribeClass(string cname, string lib, int vers = 0)
254 : DescribeClassT<T,BaseT,Abstract,NoPIO>(cname, lib, vers) {}
255
256};
257
276template <typename T, typename BaseT = int>
277class DescribeNoPIOClass: public DescribeClassT<T,BaseT,false,true> {
278
279public:
280
285 DescribeNoPIOClass(string cname, string lib, int vers = 0)
286 : DescribeClassT<T,BaseT,false,true>(cname, lib, vers) {}
287
288};
289
308template <typename T, typename BaseT = int>
309class DescribeAbstractClass: public DescribeClassT<T,BaseT,true,false> {
310
311public:
312
317 DescribeAbstractClass(string cname, string lib, int vers = 0)
318 :DescribeClassT<T,BaseT,true,false>(cname, lib, vers) {}
319
320};
321
340template <typename T, typename BaseT = int>
341class DescribeAbstractNoPIOClass: public DescribeClassT<T,BaseT,true,true> {
342
343public:
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 */
#define ThePEG_DECLARE_TEMPLATE_POINTERS(full, abbrev)
This macro helps us to declare pointers and stuff to standard classes.
Definition: Pointers.h:36
#define ThePEG_DECLARE_POINTERS(full, abbrev)
This macro helps us to declare pointers and stuff to standard classes.
Definition: Pointers.h:47
ClassDescriptionBase is the base class for all class description classes.
vector< const ClassDescriptionBase * > DescriptionVector
A vector of class descriptions.
void baseClasses(DescriptionVector::iterator first, DescriptionVector::iterator last)
Set the base classes.
DescribeClass and its companion classes DescribeAbstractClass, DescribeNoPIOClass and DescribeAbstrac...
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...
DescribeClass and its companion classes DescribeAbstractClass, DescribeNoPIOClass and DescribeAbstrac...
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,...
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.
virtual void output(tcBPtr o, PersistentOStream &os) const
Call standard output function.
virtual BPtr create() const
Default-create an object.
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...
virtual ~DescribeClassT()
The descructor.
DescribeClass and its companion classes DescribeAbstractClass, DescribeNoPIOClass and DescribeAbstrac...
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...
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...
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.
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
Ptr< T >::pointer new_ptr()
Simple interface to the PtrTraits<Ptr>::create()
Definition: PtrTraits.h:195
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
Traits class used by DescribeCLassT for transparent handling of one base class or a several base clas...
Definition: DescribeClass.h:31
int Base4
The fourth base class.
Definition: DescribeClass.h:43
T Base1
The first base class.
Definition: DescribeClass.h:34
int Base2
The second base class.
Definition: DescribeClass.h:37
int Base3
The third base class.
Definition: DescribeClass.h:40
Helper class for multiple base classes.
Definition: DescribeClass.h:24
Define the base class from which all (polymorphic) classes in ThePEG are derived.
Definition: ThePEG.h:54
The default concrete implementation of ClassTraitsBase.
Definition: ClassTraits.h:134
static ThePEG::Ptr< T >::pointer create()
Throw an exception as the class is bastract.
Helper class used by DescribeClassT for transparent handling of abstract and concrete classes.
static ThePEG::Ptr< T >::pointer create()
Default-creat an object.
static void output(const T &, PersistentOStream &)
Do nothing as T has no persistent I/O functions.
static void input(T &, PersistentIStream &, int)
Do nothing as T has no persistent I/O functions.
Helper class used by DescribeClassT for transparent handling of classes with and without persistent I...
Definition: DescribeClass.h:73
static void input(T &t, PersistentIStream &is, int oldVersion)
Call standard input function.
Definition: DescribeClass.h:85
static void output(const T &t, PersistentOStream &os)
Call standard output function.
Definition: DescribeClass.h:78