thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
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>
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 
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>
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 */
PersistentIStream is used to read persistent objects from a stream where they were previously written...
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
Define the base class from which all (polymorphic) classes in ThePEG are derived. ...
Definition: ThePEG.h:54
ClassTraitsType is an empty, non-polymorphic, base class.
Definition: ClassTraits.h:30
TraitsType is an empty, non-polymorphic, base class.
Definition: ThePEG.h:94
PersistentOStream is used to write objects persistently to a stream from which they can be read in ag...
static void output(tcTPtr t, PersistentOStream &os)
Write the T part of an object to a persistent stream.
Definition: ClassTraits.h:92
TransientConstRCPtr is a simple wrapper around a bare const pointer which can be assigned to and from...
Definition: RCPtr.h:696
static string library(const type_info &ti)
Return the dynamic library of the class corresponding to the given type_info object.
TransientRCPtr is a simple wrapper around a bare pointer which can be assigned to and from an RCPtr a...
Definition: RCPtr.h:519
ConstRCPtr is a reference counted (smart) const pointer.
Definition: RCPtr.h:320
T1 dynamic_ptr_cast(const T2 &t2)
Replacement for the standard dynamic_cast.
Definition: PtrTraits.h:168
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
static int version()
Return the version of class T.
Definition: ClassTraits.h:73
This is the main config header file for ThePEG.
#define ThePEG_DECLARE_TEMPLATE_POINTERS(full, abbrev)
This macro helps us to declare pointers and stuff to standard classes.
Definition: Pointers.h:36
static TPtr cast(BPtr b)
Perform a dynamic cast from the given pointer to a pointer to T.
Definition: ClassTraits.h:106
static int version(const type_info &ti)
Return the version of the class corresponding to the given type_info object.
static string library()
The name of a file containing the dynamic library where the class T is implemented.
Definition: ClassTraits.h:85
RCPtr is a reference counted (smart) pointer.
Definition: RCPtr.h:60
#define ThePEG_DECLARE_POINTERS(full, abbrev)
This macro helps us to declare pointers and stuff to standard classes.
Definition: Pointers.h:47
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 TPtr create()
Create a T object and return a smart pointer to it.
Definition: ClassTraits.h:60
The default concrete implementation of ClassTraitsBase.
Definition: ClassTraits.h:134
static string className()
Return the name of class T.
Definition: ClassTraits.h:66
int NthBase
The type of the BaseN&#39;th base class (int means there are no further base classes).
Definition: ClassTraits.h:161
static cTPtr cast(cBPtr b)
Perform a dynamic cast from the given const pointer to a pointer to const T.
Definition: ClassTraits.h:112
BaseClassTraits describes the base classes of the templated class.
Definition: ClassTraits.h:156
static tTPtr cast(tBPtr b)
Perform a dynamic cast from the given transient pointer to a transient pointer to T...
Definition: ClassTraits.h:118
The templated ClassTraitsBase class defines a set of default information about classes used by ThePEG...
Definition: ClassTraits.h:52
static string className(const type_info &ti)
Return the name of the class corresponding to the given type_info object.