thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
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
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
22namespace ThePEG {
23
30struct ClassTraitsType: public TraitsType {};
31
51template <typename T>
53
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
133template <typename T>
134struct ClassTraits: public ClassTraitsBase<T> {};
135
139template<>
140struct ClassTraits<double> : public ClassTraitsBase<double> {
141 static string className() { return "double"; }
142};
143
155template <typename Derived, int BaseN>
161 typedef int NthBase;
162};
163
164}
165
166#define ThePEG_DECLARE_BASE_CLASS_TRAITS_1(Class,Base) \
167 \
169template <> \
170struct BaseClassTrait<Class,1>: public ClassTraitsType { \
171 \
172 typedef Base NthBase; \
173}; \
174
175#define ThePEG_DECLARE_BASE_CLASS_TRAITS_2(Class,Base1,Base2) \
176 \
178template <> \
179struct BaseClassTrait<Class,1>: public ClassTraitsType { \
180 \
181 typedef Base1 NthBase; \
182}; \
183 \
185template <> \
186struct BaseClassTrait<Class,2>: public ClassTraitsType { \
187 \
188 typedef Base2 NthBase; \
189}; \
190
191#define ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,Name,Lib) \
192 \
194template <> \
195struct 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) \
212ThePEG_DECLARE_BASE_CLASS_TRAITS_1(Class,Base) \
213ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,"ThePEG::" #Class,"") \
214
215#define ThePEG_DECLARE_DYNAMIC_CLASS_TRAITS(Class,Base,Lib) \
216ThePEG_DECLARE_BASE_CLASS_TRAITS_1(Class,Base) \
217ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,"ThePEG::" #Class,Lib) \
218
219#define ThePEG_DECLARE_CLASS_TRAITS_2(Class,Base1,Base2) \
220ThePEG_DECLARE_BASE_CLASS_TRAITS_2(Class,Base1,Base2) \
221ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,"ThePEG/::" #Class,"") \
222
223#define ThePEG_DECLARE_DYNAMIC_CLASS_TRAITS_2(Class,Base1,Base2,Lib) \
224ThePEG_DECLARE_BASE_CLASS_TRAITS_2(Class,Base1,Base2) \
225ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,"ThePEG::" #Class,Lib) \
226
227#define ThePEG_DECLARE_NAMED_CLASS_TRAITS(Class,Base,Name) \
228ThePEG_DECLARE_BASE_CLASS_TRAITS_1(Class,Base) \
229ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,Name,"") \
230
231#define ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS(Class,Base,Name,Lib) \
232ThePEG_DECLARE_BASE_CLASS_TRAITS_1(Class,Base) \
233ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,Name,Lib) \
234
235#define ThePEG_DECLARE_NAMED_CLASS_TRAITS_2(Class,Base1,Base2,Name) \
236ThePEG_DECLARE_BASE_CLASS_TRAITS_2(Class,Base1,Base2) \
237ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,Name,"") \
238
239#endif /* ThePEG_ClassTraits_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
This is the main config header file for ThePEG.
static string library(const type_info &ti)
Return the dynamic library of the class corresponding to the given type_info object.
static int version(const type_info &ti)
Return the version of the class corresponding to the given type_info object.
static string className(const type_info &ti)
Return the name of the class corresponding to the given type_info object.
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...
ConstRCPtr is a reference counted (smart) const pointer.
Definition: RCPtr.h:320
RCPtr is a reference counted (smart) pointer.
Definition: RCPtr.h:60
static RCPtr Create()
Allocate and construct an object of class T and return a RCPtr to it.
Definition: RCPtr.h:120
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
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
BaseClassTraits describes the base classes of the templated class.
Definition: ClassTraits.h:156
int NthBase
The type of the BaseN'th base class (int means there are no further base classes).
Definition: ClassTraits.h:161
Define the base class from which all (polymorphic) classes in ThePEG are derived.
Definition: ThePEG.h:54
The templated ClassTraitsBase class defines a set of default information about classes used by ThePEG...
Definition: ClassTraits.h:52
static TPtr cast(BPtr b)
Perform a dynamic cast from the given pointer to a pointer to T.
Definition: ClassTraits.h:106
static string className()
Return the name of class T.
Definition: ClassTraits.h:66
static TPtr create()
Create a T object and return a smart pointer to it.
Definition: ClassTraits.h:60
static string library()
The name of a file containing the dynamic library where the class T is implemented.
Definition: ClassTraits.h:85
static void input(tTPtr t, PersistentIStream &is, int oldVersion)
Read the T part of an object from a persistent stream.
Definition: ClassTraits.h:99
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
static int version()
Return the version of class T.
Definition: ClassTraits.h:73
static tTPtr cast(tBPtr b)
Perform a dynamic cast from the given transient pointer to a transient pointer to T.
Definition: ClassTraits.h:118
static cTPtr cast(cBPtr b)
Perform a dynamic cast from the given const pointer to a pointer to const T.
Definition: ClassTraits.h:112
static void output(tcTPtr t, PersistentOStream &os)
Write the T part of an object to a persistent stream.
Definition: ClassTraits.h:92
ClassTraitsType is an empty, non-polymorphic, base class.
Definition: ClassTraits.h:30
The default concrete implementation of ClassTraitsBase.
Definition: ClassTraits.h:134
TraitsType is an empty, non-polymorphic, base class.
Definition: ThePEG.h:94