ThePEG
1.8.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
Utilities
ClassTraits.h
1
// -*- C++ -*-
2
//
3
// ClassTraits.h is a part of ThePEG - Toolkit for HEP Event Generation
4
// Copyright (C) 1999-2011 Leif Lonnblad
5
//
6
// ThePEG is licenced under version 2 of the GPL, see COPYING for details.
7
// Please respect the MCnet academic guidelines, see GUIDELINES for details.
8
//
9
#ifndef ThePEG_ClassTraits_H
10
#define ThePEG_ClassTraits_H
11
// This is the declaration of the ClassTraitsBase, ClassTraits and
12
// BaseClassTraits classes.
13
14
15
#include "ThePEG/Config/ThePEG.h"
16
// #include "ClassTraits.fh"
17
// #include "ClassTraits.xh"
18
#include "ThePEG/Persistency/PersistentOStream.fh"
19
#include "ThePEG/Persistency/PersistentIStream.fh"
20
#include "DescriptionList.h"
21
22
namespace
ThePEG {
23
30
struct
ClassTraitsType
:
public
TraitsType
{};
31
51
template
<
typename
T>
52
struct
ClassTraitsBase
:
public
ClassTraitsType
{
53
54
ThePEG_DECLARE_TEMPLATE_POINTERS
(T,
TPtr
);
55
ThePEG_DECLARE_POINTERS
(
Base
,
BPtr
);
56
60
static
TPtr
create
() {
return
TPtr::Create
(); }
61
65
// static string className() { return T::className(); }
66
static
string
className
() {
67
return
DescriptionList::className
(
typeid
(T));
68
}
69
73
static
int
version
() {
74
return
DescriptionList::version
(
typeid
(T));
75
}
76
77
85
static
string
library
() {
86
return
DescriptionList::library
(
typeid
(T));
87
}
88
92
static
void
output
(
tcTPtr
t,
PersistentOStream
& os) {
93
t->persistentOutput(os);
94
}
95
99
static
void
input
(
tTPtr
t,
PersistentIStream
& is,
int
oldVersion) {
100
t->persistentInput(is, oldVersion);
101
}
102
106
static
TPtr
cast
(
BPtr
b) {
return
dynamic_ptr_cast
<
TPtr
>(b); }
107
112
static
cTPtr
cast
(
cBPtr
b) {
return
dynamic_ptr_cast
<
cTPtr
>(b); }
113
118
static
tTPtr
cast
(
tBPtr
b) {
return
dynamic_ptr_cast
<
tTPtr
>(b); }
119
124
static
tcTPtr
cast
(
tcBPtr
b) {
return
dynamic_ptr_cast
<
tcTPtr
>(b); }
125
126
};
127
133
template
<
typename
T>
134
struct
ClassTraits
:
public
ClassTraitsBase
<T> {};
135
139
template
<>
140
struct
ClassTraits
<double> :
public
ClassTraitsBase
<double> {
141
static
string
className
() {
return
"double"
; }
142
};
143
155
template
<
typename
Derived,
int
BaseN>
156
struct
BaseClassTrait
:
public
ClassTraitsType
{
161
typedef
int
NthBase
;
162
};
163
164
}
165
166
#define ThePEG_DECLARE_BASE_CLASS_TRAITS_1(Class,Base) \
167
\
169
template <> \
170
struct BaseClassTrait<Class,1>: public ClassTraitsType { \
171
\
172
typedef Base NthBase; \
173
}; \
174
175
#define ThePEG_DECLARE_BASE_CLASS_TRAITS_2(Class,Base1,Base2) \
176
\
178
template <> \
179
struct BaseClassTrait<Class,1>: public ClassTraitsType { \
180
\
181
typedef Base1 NthBase; \
182
}; \
183
\
185
template <> \
186
struct BaseClassTrait<Class,2>: public ClassTraitsType { \
187
\
188
typedef Base2 NthBase; \
189
}; \
190
191
#define ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,Name,Lib) \
192
\
194
template <> \
195
struct ClassTraits<Class>: \
196
public ClassTraitsBase<Class> { \
197
\
198
static string className() { return Name; } \
199
\
206
static string library() { return Lib; } \
207
} \
208
209
210
211
#define ThePEG_DECLARE_CLASS_TRAITS(Class,Base) \
212
ThePEG_DECLARE_BASE_CLASS_TRAITS_1(Class,Base) \
213
ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,"ThePEG::" #Class,"") \
214
215
#define ThePEG_DECLARE_DYNAMIC_CLASS_TRAITS(Class,Base,Lib) \
216
ThePEG_DECLARE_BASE_CLASS_TRAITS_1(Class,Base) \
217
ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,"ThePEG::" #Class,Lib) \
218
219
#define ThePEG_DECLARE_CLASS_TRAITS_2(Class,Base1,Base2) \
220
ThePEG_DECLARE_BASE_CLASS_TRAITS_2(Class,Base1,Base2) \
221
ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,"ThePEG/::" #Class,"") \
222
223
#define ThePEG_DECLARE_DYNAMIC_CLASS_TRAITS_2(Class,Base1,Base2,Lib) \
224
ThePEG_DECLARE_BASE_CLASS_TRAITS_2(Class,Base1,Base2) \
225
ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,"ThePEG::" #Class,Lib) \
226
227
#define ThePEG_DECLARE_NAMED_CLASS_TRAITS(Class,Base,Name) \
228
ThePEG_DECLARE_BASE_CLASS_TRAITS_1(Class,Base) \
229
ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,Name,"") \
230
231
#define ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS(Class,Base,Name,Lib) \
232
ThePEG_DECLARE_BASE_CLASS_TRAITS_1(Class,Base) \
233
ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,Name,Lib) \
234
235
#define ThePEG_DECLARE_NAMED_CLASS_TRAITS_2(Class,Base1,Base2,Name) \
236
ThePEG_DECLARE_BASE_CLASS_TRAITS_2(Class,Base1,Base2) \
237
ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,Name,"") \
238
239
#endif
/* ThePEG_ClassTraits_H */
Generated on Mon Jul 2 2012 16:06:46 for ThePEG by
1.8.1.1