00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef ThePEG_ParVector_H
00010 #define ThePEG_ParVector_H
00011
00012
00013
00014 #include "ThePEG/Config/ThePEG.h"
00015 #include "InterfaceBase.h"
00016 #include "ParVector.fh"
00017 #include <limits>
00018
00019 namespace ThePEG {
00020
00022 namespace {
00023 template <typename T>
00027 inline void putUnitImpl2(ostream & os, T v, T u, DimensionT) {
00028 os << v/u;
00029 }
00030
00031 template <typename T>
00035 inline void putUnitImpl2(ostream & os, T v, T u, StandardT) {
00036 if ( u > T() )
00037 os << v/u;
00038 else
00039 os << v;
00040 }
00041 }
00042
00063 class ParVectorBase: public InterfaceBase {
00064
00065 public:
00066
00068 typedef vector<string> StringVector;
00069
00070 public:
00071
00098 ParVectorBase(string newName, string newDescription,
00099 string newClassName,
00100 const type_info & newTypeInfo, int newSize,
00101 bool depSafe, bool readonly, int limits)
00102 : InterfaceBase(newName, newDescription, newClassName,
00103 newTypeInfo, depSafe,
00104 readonly), limit(limits), theSize(newSize) {}
00105
00109 virtual ~ParVectorBase() {}
00110
00119 virtual string exec(InterfacedBase &, string action,
00120 string arguments) const;
00121
00125 virtual string fullDescription(const InterfacedBase & ib) const;
00126
00133 virtual void set(InterfacedBase & ib, string val, int i)
00134 const = 0;
00135
00142 virtual void insert(InterfacedBase & ib, string val, int i)
00143 const = 0;
00144
00149 virtual void erase(InterfacedBase & ib, int i)
00150 const = 0;
00151
00155 virtual StringVector get(const InterfacedBase & ib) const
00156 = 0;
00157
00162 virtual string minimum(const InterfacedBase & ib, int i) const
00163 = 0;
00164
00169 virtual string maximum(const InterfacedBase & ib, int i) const
00170 = 0;
00171
00176 virtual string def(const InterfacedBase & ib, int i) const
00177 = 0;
00178
00182 virtual string def() const = 0;
00183
00188 virtual void setDef(InterfacedBase & ib, int i) const
00189 = 0;
00190
00194 bool limited() const { return limit != Interface::nolimits; }
00195
00199 bool upperLimit() const {
00200 return limit == Interface::limited || limit == Interface::upperlim;
00201 }
00202
00206 bool lowerLimit() const {
00207 return limit == Interface::limited || limit == Interface::lowerlim;
00208 }
00209
00214 void setLimited() { limit = Interface::limited; }
00215
00220 void setUnlimited() { limit = Interface::nolimits; }
00221
00226 int size() const { return theSize; }
00227
00232 void setSize(int sz) { theSize = sz; }
00233
00238 void setVariableSize() { theSize = 0; }
00239
00240 private:
00241
00246 int limit;
00247
00251 int theSize;
00252
00253 };
00254
00275 template <typename Type>
00276 class ParVectorTBase: public ParVectorBase {
00277
00278 public:
00279
00281 typedef vector<Type> TypeVector;
00282
00283 public:
00284
00314 ParVectorTBase(string newName, string newDescription,
00315 string newClassName, const type_info & newTypeInfo,
00316 Type newUnit, int newSize, bool depSafe,
00317 bool readonly, int limits)
00318 : ParVectorBase(newName, newDescription, newClassName,
00319 newTypeInfo, newSize,
00320 depSafe, readonly, limits), theUnit(newUnit) {}
00321
00322
00326 virtual ~ParVectorTBase() {}
00327
00331 virtual string type() const;
00332
00337 virtual string doxygenType() const;
00338
00342 virtual string fullDescription(const InterfacedBase & ib) const;
00343
00349 virtual void set(InterfacedBase & ib, string val, int i) const
00350 ;
00351
00356 virtual void tset(InterfacedBase & ib, Type val, int i)
00357 const = 0;
00358
00365 virtual void insert(InterfacedBase & ib, string val, int i) const
00366 ;
00367
00368 private:
00370 void setImpl(InterfacedBase & ib, string val, int i, StandardT)
00371 const;
00372
00374 void setImpl(InterfacedBase & ib, string val, int i, DimensionT)
00375 const;
00376
00378 void insertImpl(InterfacedBase & ib, string val, int i, StandardT)
00379 const;
00380
00382 void insertImpl(InterfacedBase & ib, string val, int i, DimensionT)
00383 const;
00384
00385 public:
00386
00391 virtual void tinsert(InterfacedBase & ib, Type val, int i)
00392 const = 0;
00393
00399 virtual StringVector get(const InterfacedBase & ib) const
00400 ;
00401
00406 virtual TypeVector tget(const InterfacedBase & ib) const
00407 = 0;
00408
00416 virtual string minimum(const InterfacedBase & ib, int i) const
00417 ;
00418
00423 virtual Type tminimum(const InterfacedBase & ib, int i) const
00424 = 0;
00425
00432 virtual string maximum(const InterfacedBase & ib, int i) const
00433 ;
00434
00439 virtual Type tmaximum(const InterfacedBase & ib, int i) const
00440 = 0;
00441
00447 virtual string def(const InterfacedBase & ib, int i) const
00448 ;
00449
00454 virtual Type tdef(const InterfacedBase & ib, int i) const
00455 = 0;
00456
00461 virtual string def() const;
00462
00466 virtual Type tdef() const = 0;
00467
00472 virtual void setDef(InterfacedBase & ib, int i) const
00473 ;
00474
00480 Type unit() const { return theUnit; }
00481
00487 void unit(Type u) { theUnit = u; }
00488
00489 protected:
00490
00494 void putUnit(ostream & os, Type val) const {
00495 putUnitImpl2(os, val, unit(), typename TypeTraits<Type>::DimType());
00496 }
00497
00498 private:
00499
00505 Type theUnit;
00506
00507 };
00508
00529 template <typename T, typename Type>
00530 class ParVector: public ParVectorTBase<Type> {
00531
00532 public:
00533
00538 typedef void (T::*SetFn)(Type, int);
00539
00544 typedef void (T::*InsFn)(Type, int);
00545
00550 typedef void (T::*DelFn)(int);
00551
00555 typedef vector<Type> TypeVector;
00556
00561 typedef TypeVector (T::*GetFn)() const;
00562
00566 typedef vector<string> StringVector;
00567
00572 typedef StringVector (T::*StringGetFn)() const;
00573
00578 typedef Type (T::*DefFn)(int) const;
00579
00584 typedef TypeVector T::* Member;
00585
00586 public:
00587
00642 ParVector(string newName, string newDescription,
00643 Member newMember, int newSize, Type newDef, Type newMin,
00644 Type newMax, bool depSafe = false, bool readonly = false,
00645 bool limits = true, SetFn newSetFn = 0,
00646 InsFn newInsFn = 0, DelFn newDelFn = 0, GetFn newGetFn = 0,
00647 DefFn newDefFn = 0, DefFn newMinFn = 0, DefFn newMaxFn = 0,
00648 StringGetFn newStringGetFn = 0)
00649 : ParVectorTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
00650 typeid(T), Type(), newSize, depSafe, readonly,
00651 limits),
00652 theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
00653 theSetFn(newSetFn), theInsFn(newInsFn), theDelFn(newDelFn),
00654 theGetFn(newGetFn), theDefFn(newDefFn), theMinFn(newMinFn),
00655 theMaxFn(newMaxFn), theStringGetFn(newStringGetFn) {}
00656
00657
00715 ParVector(string newName, string newDescription, Member newMember,
00716 Type newUnit, int newSize, Type newDef, Type newMin,
00717 Type newMax, bool depSafe = false, bool readonly = false,
00718 bool limits = true, SetFn newSetFn = 0,
00719 InsFn newInsFn = 0, DelFn newDelFn = 0, GetFn newGetFn = 0,
00720 DefFn newDefFn = 0, DefFn newMinFn = 0, DefFn newMaxFn = 0,
00721 StringGetFn newStringGetFn = 0)
00722 : ParVectorTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
00723 typeid(T), newUnit, newSize, depSafe, readonly,
00724 limits),
00725 theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
00726 theSetFn(newSetFn), theInsFn(newInsFn), theDelFn(newDelFn),
00727 theGetFn(newGetFn), theDefFn(newDefFn), theMinFn(newMinFn),
00728 theMaxFn(newMaxFn), theStringGetFn(newStringGetFn) {}
00729
00785 ParVector(string newName, string newDescription,
00786 Member newMember, int newSize, Type newDef, Type newMin,
00787 Type newMax, bool depSafe = false, bool readonly = false,
00788 int limits = Interface::limited, SetFn newSetFn = 0,
00789 InsFn newInsFn = 0, DelFn newDelFn = 0, GetFn newGetFn = 0,
00790 DefFn newDefFn = 0, DefFn newMinFn = 0, DefFn newMaxFn = 0,
00791 StringGetFn newStringGetFn = 0)
00792 : ParVectorTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
00793 typeid(T), Type(), newSize, depSafe, readonly,
00794 limits),
00795 theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
00796 theSetFn(newSetFn), theInsFn(newInsFn), theDelFn(newDelFn),
00797 theGetFn(newGetFn), theDefFn(newDefFn), theMinFn(newMinFn),
00798 theMaxFn(newMaxFn), theStringGetFn(newStringGetFn) {}
00799
00858 ParVector(string newName, string newDescription, Member newMember,
00859 Type newUnit, int newSize, Type newDef, Type newMin,
00860 Type newMax, bool depSafe = false, bool readonly = false,
00861 int limits = Interface::limited, SetFn newSetFn = 0,
00862 InsFn newInsFn = 0, DelFn newDelFn = 0, GetFn newGetFn = 0,
00863 DefFn newDefFn = 0, DefFn newMinFn = 0, DefFn newMaxFn = 0,
00864 StringGetFn newStringGetFn = 0)
00865 : ParVectorTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
00866 typeid(T), newUnit, newSize, depSafe, readonly,
00867 limits),
00868 theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
00869 theSetFn(newSetFn), theInsFn(newInsFn), theDelFn(newDelFn),
00870 theGetFn(newGetFn), theDefFn(newDefFn), theMinFn(newMinFn),
00871 theMaxFn(newMaxFn), theStringGetFn(newStringGetFn) {}
00872
00877 virtual void tset(InterfacedBase & ib, Type val, int i) const
00878 ;
00879
00884 virtual void tinsert(InterfacedBase & ib, Type val, int i) const
00885 ;
00886
00891 virtual void erase(InterfacedBase & ib, int i)
00892 const;
00893
00899 virtual StringVector get(const InterfacedBase & ib) const
00900 ;
00901
00906 virtual TypeVector tget(const InterfacedBase & ib) const
00907 ;
00908
00913 virtual Type tminimum(const InterfacedBase & ib, int i) const
00914 ;
00915
00920 virtual Type tmaximum(const InterfacedBase & ib, int i) const
00921 ;
00922
00927 virtual Type tdef(const InterfacedBase &, int) const
00928 ;
00929
00933 virtual Type tdef() const;
00934
00938 void setSetFunction(SetFn sf) { theSetFn = sf; }
00939
00943 void setInsertFunction(InsFn ifn) { theInsFn = ifn; }
00944
00948 void setGetFunction(GetFn gf) { theGetFn = gf; }
00949
00953 void setEraseFunction(DelFn df) { theDelFn = df; }
00954
00958 void setDefaultFunction(GetFn df) { theDefFn = df; }
00959
00963 void setMinFunction(GetFn mf) { theMinFn = mf; }
00964
00968 void setMaxFunction(GetFn mf) { theMaxFn = mf; }
00969
00973 void setStringGetFunction(StringGetFn gf) { theStringGetFn = gf; }
00974
00979 virtual void doxygenDescription(ostream & stream) const;
00980
00981 private:
00982
00986 Member theMember;
00987
00992 Type theDef;
00993
00998 Type theMin;
00999
01004 Type theMax;
01005
01009 SetFn theSetFn;
01010
01014 InsFn theInsFn;
01015
01019 DelFn theDelFn;
01020
01024 GetFn theGetFn;
01025
01029 DefFn theDefFn;
01030
01034 DefFn theMinFn;
01035
01039 DefFn theMaxFn;
01040
01044 StringGetFn theStringGetFn;
01045
01046 };
01047
01048 }
01049
01050 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
01051 #include "ParVector.tcc"
01052 #endif
01053
01054 #endif