thepeg
is hosted by
Hepforge
,
IPPP Durham
ThePEG
2.3.0
Utilities
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>
31
struct
BaseClassesTraits
{
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>
73
struct
DescribeClassPIOHelper
{
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>
115
struct
DescribeClassAbstractHelper
{
116
120
static
typename
ThePEG::Ptr<T>::pointer
create
() {
121
return
new_ptr
(T());
122
}
123
};
124
129
template
<
typename
T>
130
struct
DescribeClassAbstractHelper
<T,true> {
131
135
static
typename
ThePEG::Ptr<T>::pointer
create
() {
136
throw
std::logic_error(
"Tried to instantiate abstract class "
+
137
ClassTraits<T>::className
());
138
}
139
140
};
141
142
143
144
158
template
<
typename
T,
typename
BaseT,
bool
Abstract = false,
bool
NoPIO = false>
159
class
DescribeClassT
:
public
ClassDescriptionBase
{
160
161
public
:
162
163
ThePEG_DECLARE_TEMPLATE_POINTERS
(T,
TPtr
);
164
ThePEG_DECLARE_POINTERS
(
Base
,
BPtr
);
165
170
DescribeClassT
(
string
cname,
string
lib,
int
vers = 0)
171
:
ClassDescriptionBase
(cname, typeid(T), vers, lib, Abstract) {
172
DescriptionList::Register
(*
this
);
173
T::Init();
174
}
175
179
virtual
~DescribeClassT
() {}
180
184
virtual
void
setup
() {
185
DescriptionVector
bases;
186
const
ClassDescriptionBase
* b =
187
DescriptionList::find
(
typeid
(
typename
BaseClassesTraits<BaseT>::Base1
));
188
if
( b ) bases.push_back(b);
189
b =
DescriptionList::find
(
typeid
(
typename
BaseClassesTraits<BaseT>::Base2
));
190
if
( b ) bases.push_back(b);
191
b =
DescriptionList::find
(
typeid
(
typename
BaseClassesTraits<BaseT>::Base3
));
192
if
( b ) bases.push_back(b);
193
b =
DescriptionList::find
(
typeid
(
typename
BaseClassesTraits<BaseT>::Base4
));
194
if
( b ) bases.push_back(b);
195
baseClasses
(bases.begin(), bases.end());
196
}
197
201
virtual
BPtr
create
()
const
{
202
return
DescribeClassAbstractHelper<T,Abstract>::create
();
203
}
204
208
virtual
void
output
(
tcBPtr
o,
PersistentOStream
& os)
const
{
209
tcTPtr
t = dynamic_ptr_cast<tcTPtr>(o);
210
DescribeClassPIOHelper<T,NoPIO>::output
(*t, os);
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 */
ThePEG_DECLARE_TEMPLATE_POINTERS
#define ThePEG_DECLARE_TEMPLATE_POINTERS(full, abbrev)
This macro helps us to declare pointers and stuff to standard classes.
Definition:
Pointers.h:36
ThePEG_DECLARE_POINTERS
#define ThePEG_DECLARE_POINTERS(full, abbrev)
This macro helps us to declare pointers and stuff to standard classes.
Definition:
Pointers.h:47
ThePEG::ClassDescriptionBase
ClassDescriptionBase is the base class for all class description classes.
Definition:
ClassDescription.h:63
ThePEG::ClassDescriptionBase::DescriptionVector
vector< const ClassDescriptionBase * > DescriptionVector
A vector of class descriptions.
Definition:
ClassDescription.h:68
ThePEG::ClassDescriptionBase::baseClasses
void baseClasses(DescriptionVector::iterator first, DescriptionVector::iterator last)
Set the base classes.
Definition:
ClassDescription.h:169
ThePEG::DescribeAbstractClass
DescribeClass and its companion classes DescribeAbstractClass, DescribeNoPIOClass and DescribeAbstrac...
Definition:
DescribeClass.h:309
ThePEG::DescribeAbstractClass::DescribeAbstractClass
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...
Definition:
DescribeClass.h:317
ThePEG::DescribeAbstractNoPIOClass
DescribeClass and its companion classes DescribeAbstractClass, DescribeNoPIOClass and DescribeAbstrac...
Definition:
DescribeClass.h:341
ThePEG::DescribeAbstractNoPIOClass::DescribeAbstractNoPIOClass
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...
Definition:
DescribeClass.h:349
ThePEG::DescribeClassT
DescribeClassT and its derived companion classes DescribeClass DescribeAbstractClass,...
Definition:
DescribeClass.h:159
ThePEG::DescribeClassT::input
virtual void input(tBPtr o, PersistentIStream &is, int oldVersion) const
Call standard input function.
Definition:
DescribeClass.h:216
ThePEG::DescribeClassT::setup
virtual void setup()
Set up the base class information for this object.
Definition:
DescribeClass.h:184
ThePEG::DescribeClassT::output
virtual void output(tcBPtr o, PersistentOStream &os) const
Call standard output function.
Definition:
DescribeClass.h:208
ThePEG::DescribeClassT::create
virtual BPtr create() const
Default-create an object.
Definition:
DescribeClass.h:201
ThePEG::DescribeClassT::DescribeClassT
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...
Definition:
DescribeClass.h:170
ThePEG::DescribeClassT::~DescribeClassT
virtual ~DescribeClassT()
The descructor.
Definition:
DescribeClass.h:179
ThePEG::DescribeClass
DescribeClass and its companion classes DescribeAbstractClass, DescribeNoPIOClass and DescribeAbstrac...
Definition:
DescribeClass.h:245
ThePEG::DescribeClass::DescribeClass
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...
Definition:
DescribeClass.h:253
ThePEG::DescribeNoPIOClass
DescribeClass and its companion classes DescribeAbstractClass, DescribeNoPIOClass and DescribeAbstrac...
Definition:
DescribeClass.h:277
ThePEG::DescribeNoPIOClass::DescribeNoPIOClass
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...
Definition:
DescribeClass.h:285
ThePEG::DescriptionList::find
static const ClassDescriptionBase * find(const type_info &ti)
Get the description of a class giving its type_info object.
Definition:
DescriptionList.h:48
ThePEG::DescriptionList::Register
static void Register(ClassDescriptionBase &)
Insert a description in the list.
ThePEG::PersistentIStream
PersistentIStream is used to read persistent objects from a stream where they were previously written...
Definition:
PersistentIStream.h:48
ThePEG::PersistentOStream
PersistentOStream is used to write objects persistently to a stream from which they can be read in ag...
Definition:
PersistentOStream.h:51
ThePEG::Pointer::RCPtr
RCPtr is a reference counted (smart) pointer.
Definition:
RCPtr.h:60
ThePEG::Pointer::TransientConstRCPtr
TransientConstRCPtr is a simple wrapper around a bare const pointer which can be assigned to and from...
Definition:
RCPtr.h:696
ThePEG::Pointer::TransientRCPtr
TransientRCPtr is a simple wrapper around a bare pointer which can be assigned to and from an RCPtr a...
Definition:
RCPtr.h:519
ThePEG::Pointer::new_ptr
Ptr< T >::pointer new_ptr()
Simple interface to the PtrTraits<Ptr>::create()
Definition:
PtrTraits.h:195
ThePEG
This is the main namespace within which all identifiers in ThePEG are declared.
Definition:
FactoryBase.h:28
ThePEG::BaseClassesTraits< BaseClasses< BaseT1, BaseT2, BaseT3, BaseT4 > >::Base2
BaseT2 Base2
The second base class.
Definition:
DescribeClass.h:58
ThePEG::BaseClassesTraits< BaseClasses< BaseT1, BaseT2, BaseT3, BaseT4 > >::Base4
BaseT4 Base4
The fourth base class.
Definition:
DescribeClass.h:64
ThePEG::BaseClassesTraits< BaseClasses< BaseT1, BaseT2, BaseT3, BaseT4 > >::Base3
BaseT3 Base3
The third base class.
Definition:
DescribeClass.h:61
ThePEG::BaseClassesTraits< BaseClasses< BaseT1, BaseT2, BaseT3, BaseT4 > >::Base1
BaseT1 Base1
The first base class.
Definition:
DescribeClass.h:55
ThePEG::BaseClassesTraits
Traits class used by DescribeCLassT for transparent handling of one base class or a several base clas...
Definition:
DescribeClass.h:31
ThePEG::BaseClassesTraits::Base4
int Base4
The fourth base class.
Definition:
DescribeClass.h:43
ThePEG::BaseClassesTraits::Base1
T Base1
The first base class.
Definition:
DescribeClass.h:34
ThePEG::BaseClassesTraits::Base2
int Base2
The second base class.
Definition:
DescribeClass.h:37
ThePEG::BaseClassesTraits::Base3
int Base3
The third base class.
Definition:
DescribeClass.h:40
ThePEG::BaseClasses
Helper class for multiple base classes.
Definition:
DescribeClass.h:24
ThePEG::Base
Define the base class from which all (polymorphic) classes in ThePEG are derived.
Definition:
ThePEG.h:54
ThePEG::ClassTraits
The default concrete implementation of ClassTraitsBase.
Definition:
ClassTraits.h:134
ThePEG::DescribeClassAbstractHelper< T, true >::create
static ThePEG::Ptr< T >::pointer create()
Throw an exception as the class is bastract.
Definition:
DescribeClass.h:135
ThePEG::DescribeClassAbstractHelper
Helper class used by DescribeClassT for transparent handling of abstract and concrete classes.
Definition:
DescribeClass.h:115
ThePEG::DescribeClassAbstractHelper::create
static ThePEG::Ptr< T >::pointer create()
Default-creat an object.
Definition:
DescribeClass.h:120
ThePEG::DescribeClassPIOHelper< T, true >::output
static void output(const T &, PersistentOStream &)
Do nothing as T has no persistent I/O functions.
Definition:
DescribeClass.h:101
ThePEG::DescribeClassPIOHelper< T, true >::input
static void input(T &, PersistentIStream &, int)
Do nothing as T has no persistent I/O functions.
Definition:
DescribeClass.h:106
ThePEG::DescribeClassPIOHelper
Helper class used by DescribeClassT for transparent handling of classes with and without persistent I...
Definition:
DescribeClass.h:73
ThePEG::DescribeClassPIOHelper::input
static void input(T &t, PersistentIStream &is, int oldVersion)
Call standard input function.
Definition:
DescribeClass.h:85
ThePEG::DescribeClassPIOHelper::output
static void output(const T &t, PersistentOStream &os)
Call standard output function.
Definition:
DescribeClass.h:78
Generated on Thu Jun 20 2024 14:47:02 for ThePEG by
1.9.6