00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef ThePEG_ClassTraits_H
00010 #define ThePEG_ClassTraits_H
00011
00012
00013
00014
00015 #include "ThePEG/Config/ThePEG.h"
00016
00017
00018 #include "ThePEG/Persistency/PersistentOStream.fh"
00019 #include "ThePEG/Persistency/PersistentIStream.fh"
00020
00021
00022 namespace ThePEG {
00023
00030 struct ClassTraitsType: public TraitsType {};
00031
00051 template <typename T>
00052 struct ClassTraitsBase: public ClassTraitsType {
00053
00054 ThePEG_DECLARE_TEMPLATE_POINTERS(T,TPtr);
00055 ThePEG_DECLARE_POINTERS(Base,BPtr);
00056
00060 static TPtr create() { return TPtr::Create(); }
00061
00065 static string className() { return T::className(); }
00066
00070 static int version() { return 0; }
00071
00072
00080 static string library() { return ""; }
00081
00085 static void output(tcTPtr t, PersistentOStream & os) {
00086 t->persistentOutput(os);
00087 }
00088
00092 static void input(tTPtr t, PersistentIStream & is, int oldVersion) {
00093 t->persistentInput(is, oldVersion);
00094 }
00095
00099 static TPtr cast(BPtr b) { return dynamic_ptr_cast<TPtr>(b); }
00100
00105 static cTPtr cast(cBPtr b) { return dynamic_ptr_cast<cTPtr>(b); }
00106
00111 static tTPtr cast(tBPtr b) { return dynamic_ptr_cast<tTPtr>(b); }
00112
00117 static tcTPtr cast(tcBPtr b) { return dynamic_ptr_cast<tcTPtr>(b); }
00118
00119 };
00120
00126 template <typename T>
00127 struct ClassTraits: public ClassTraitsBase<T> {};
00128
00140 template <typename Derived, int BaseN>
00141 struct BaseClassTrait: public ClassTraitsType {
00146 typedef int NthBase;
00147 };
00148
00149 }
00150
00151
00152 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
00153
00154 #endif
00155
00156 #define ThePEG_DECLARE_BASE_CLASS_TRAITS_1(Class,Base) \
00157 \
00159 template <> \
00160 struct BaseClassTrait<Class,1>: public ClassTraitsType { \
00161 \
00162 typedef Base NthBase; \
00163 }; \
00164
00165 #define ThePEG_DECLARE_BASE_CLASS_TRAITS_2(Class,Base1,Base2) \
00166 \
00168 template <> \
00169 struct BaseClassTrait<Class,1>: public ClassTraitsType { \
00170 \
00171 typedef Base1 NthBase; \
00172 }; \
00173 \
00175 template <> \
00176 struct BaseClassTrait<Class,2>: public ClassTraitsType { \
00177 \
00178 typedef Base2 NthBase; \
00179 }; \
00180
00181 #define ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,Name,Lib) \
00182 \
00184 template <> \
00185 struct ClassTraits<Class>: \
00186 public ClassTraitsBase<Class> { \
00187 \
00188 static string className() { return Name; } \
00189 \
00196 static string library() { return Lib; } \
00197 } \
00198
00199
00200
00201 #define ThePEG_DECLARE_CLASS_TRAITS(Class,Base) \
00202 ThePEG_DECLARE_BASE_CLASS_TRAITS_1(Class,Base) \
00203 ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,"ThePEG::" #Class,"") \
00204
00205 #define ThePEG_DECLARE_DYNAMIC_CLASS_TRAITS(Class,Base,Lib) \
00206 ThePEG_DECLARE_BASE_CLASS_TRAITS_1(Class,Base) \
00207 ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,"ThePEG::" #Class,Lib) \
00208
00209 #define ThePEG_DECLARE_CLASS_TRAITS_2(Class,Base1,Base2) \
00210 ThePEG_DECLARE_BASE_CLASS_TRAITS_2(Class,Base1,Base2) \
00211 ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,"ThePEG/::" #Class,"") \
00212
00213 #define ThePEG_DECLARE_DYNAMIC_CLASS_TRAITS_2(Class,Base1,Base2,Lib) \
00214 ThePEG_DECLARE_BASE_CLASS_TRAITS_2(Class,Base1,Base2) \
00215 ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,"ThePEG::" #Class,Lib) \
00216
00217 #define ThePEG_DECLARE_NAMED_CLASS_TRAITS(Class,Base,Name) \
00218 ThePEG_DECLARE_BASE_CLASS_TRAITS_1(Class,Base) \
00219 ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,Name,"") \
00220
00221 #define ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS(Class,Base,Name,Lib) \
00222 ThePEG_DECLARE_BASE_CLASS_TRAITS_1(Class,Base) \
00223 ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,Name,Lib) \
00224
00225 #define ThePEG_DECLARE_NAMED_CLASS_TRAITS_2(Class,Base1,Base2,Name) \
00226 ThePEG_DECLARE_BASE_CLASS_TRAITS_2(Class,Base1,Base2) \
00227 ThePEG_DECLARE_NAMED_DYNAMIC_CLASS_TRAITS_(Class,Name,"") \
00228
00229 #endif