thepeg
is hosted by
Hepforge
,
IPPP Durham
ThePEG
2.3.0
Utilities
ClassTraits.h
1
// -*- C++ -*-
2
//
3
// ClassTraits.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_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 */
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.h
This is the main config header file for ThePEG.
ThePEG::DescriptionList::library
static string library(const type_info &ti)
Return the dynamic library of the class corresponding to the given type_info object.
ThePEG::DescriptionList::version
static int version(const type_info &ti)
Return the version of the class corresponding to the given type_info object.
ThePEG::DescriptionList::className
static string className(const type_info &ti)
Return the name of the class corresponding to the given type_info object.
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::ConstRCPtr
ConstRCPtr is a reference counted (smart) const pointer.
Definition:
RCPtr.h:320
ThePEG::Pointer::RCPtr
RCPtr is a reference counted (smart) pointer.
Definition:
RCPtr.h:60
ThePEG::Pointer::RCPtr::Create
static RCPtr Create()
Allocate and construct an object of class T and return a RCPtr to it.
Definition:
RCPtr.h:120
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
This is the main namespace within which all identifiers in ThePEG are declared.
Definition:
FactoryBase.h:28
ThePEG::BaseClassTrait
BaseClassTraits describes the base classes of the templated class.
Definition:
ClassTraits.h:156
ThePEG::BaseClassTrait::NthBase
int NthBase
The type of the BaseN'th base class (int means there are no further base classes).
Definition:
ClassTraits.h:161
ThePEG::Base
Define the base class from which all (polymorphic) classes in ThePEG are derived.
Definition:
ThePEG.h:54
ThePEG::ClassTraitsBase
The templated ClassTraitsBase class defines a set of default information about classes used by ThePEG...
Definition:
ClassTraits.h:52
ThePEG::ClassTraitsBase::cast
static TPtr cast(BPtr b)
Perform a dynamic cast from the given pointer to a pointer to T.
Definition:
ClassTraits.h:106
ThePEG::ClassTraitsBase::className
static string className()
Return the name of class T.
Definition:
ClassTraits.h:66
ThePEG::ClassTraitsBase::create
static TPtr create()
Create a T object and return a smart pointer to it.
Definition:
ClassTraits.h:60
ThePEG::ClassTraitsBase::library
static string library()
The name of a file containing the dynamic library where the class T is implemented.
Definition:
ClassTraits.h:85
ThePEG::ClassTraitsBase::input
static void input(tTPtr t, PersistentIStream &is, int oldVersion)
Read the T part of an object from a persistent stream.
Definition:
ClassTraits.h:99
ThePEG::ClassTraitsBase::cast
static tcTPtr cast(tcBPtr b)
Perform a dynamic cast from the given transient const pointer to a transient pointer to const T.
Definition:
ClassTraits.h:124
ThePEG::ClassTraitsBase::version
static int version()
Return the version of class T.
Definition:
ClassTraits.h:73
ThePEG::ClassTraitsBase::cast
static tTPtr cast(tBPtr b)
Perform a dynamic cast from the given transient pointer to a transient pointer to T.
Definition:
ClassTraits.h:118
ThePEG::ClassTraitsBase::cast
static cTPtr cast(cBPtr b)
Perform a dynamic cast from the given const pointer to a pointer to const T.
Definition:
ClassTraits.h:112
ThePEG::ClassTraitsBase::output
static void output(tcTPtr t, PersistentOStream &os)
Write the T part of an object to a persistent stream.
Definition:
ClassTraits.h:92
ThePEG::ClassTraitsType
ClassTraitsType is an empty, non-polymorphic, base class.
Definition:
ClassTraits.h:30
ThePEG::ClassTraits
The default concrete implementation of ClassTraitsBase.
Definition:
ClassTraits.h:134
ThePEG::TraitsType
TraitsType is an empty, non-polymorphic, base class.
Definition:
ThePEG.h:94
Generated on Thu Jun 20 2024 14:47:02 for ThePEG by
1.9.6