00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef ThePEG_Parameter_H
00010 #define ThePEG_Parameter_H
00011
00012
00013
00014
00015 #include "ThePEG/Config/ThePEG.h"
00016 #include "InterfaceBase.h"
00017 #include "Parameter.xh"
00018 #include "Parameter.fh"
00019 #include "ThePEG/Utilities/StringUtils.h"
00020 #include <limits>
00021
00022 namespace ThePEG {
00023
00025 namespace {
00026 template <typename T>
00030 inline void putUnitImpl(ostream & os, T v, T u, DimensionT) {
00031 os << v/u;
00032 }
00033
00034 template <typename T>
00038 inline void putUnitImpl(ostream & os, T v, T u, StandardT) {
00039 if ( u > T() )
00040 os << v/u;
00041 else
00042 os << v;
00043 }
00044 }
00045
00064 class ParameterBase: public InterfaceBase {
00065
00066 public:
00067
00092 ParameterBase(string newName, string newDescription,
00093 string newClassName,
00094 const type_info & newTypeInfo, bool depSafe,
00095 bool readonly, int limits)
00096 : InterfaceBase(newName, newDescription,
00097 newClassName, newTypeInfo, depSafe,
00098 readonly), limit(limits) {}
00099
00103 virtual ~ParameterBase();
00104
00112 virtual string exec(InterfacedBase & ib, string action,
00113 string arguments) const;
00114
00118 virtual string fullDescription(const InterfacedBase & ib) const;
00119
00123 virtual void set(InterfacedBase & ib, string) const
00124 = 0;
00125
00129 virtual string minimum(const InterfacedBase & ib) const
00130 = 0;
00131
00135 virtual string maximum(const InterfacedBase & ib) const
00136 = 0;
00137
00141 virtual string get(const InterfacedBase & ib) const
00142 = 0;
00143
00147 virtual string def(const InterfacedBase & ib) const
00148 = 0;
00149
00153 virtual void setDef(InterfacedBase & ib) const
00154 = 0;
00155
00159 bool limited() const { return limit != Interface::nolimits; }
00160
00164 bool upperLimit() const {
00165 return limit == Interface::limited || limit == Interface::upperlim;
00166 }
00167
00171 bool lowerLimit() const {
00172 return limit == Interface::limited || limit == Interface::lowerlim;
00173 }
00174
00179 void setLimited() { limit = Interface::limited; }
00180
00185 void setUnlimited() { limit = Interface::nolimits; }
00186
00187 private:
00188
00194 int limit;
00195
00196 };
00197
00216 template <typename Type>
00217 class ParameterTBase: public ParameterBase {
00218
00219 public:
00220
00248 ParameterTBase(string newName, string newDescription,
00249 string newClassName,
00250 const type_info & newTypeInfo, Type newUnit,
00251 bool depSafe, bool readonly, int limits)
00252 : ParameterBase(newName, newDescription,
00253 newClassName, newTypeInfo, depSafe,
00254 readonly, limits), theUnit(newUnit) {}
00255
00259 virtual ~ParameterTBase() {}
00260
00264 virtual string type() const;
00265
00266 private:
00267
00269 void setImpl (InterfacedBase & i,
00270 string newValue, StandardT)
00271 const;
00272
00274 void setImpl (InterfacedBase & i,
00275 string newValue, DimensionT)
00276 const;
00277
00278 public:
00279
00285 virtual void set(InterfacedBase & ib, string newValue)
00286 const;
00287
00291 virtual void tset(InterfacedBase & ib, Type) const
00292 = 0;
00293
00299 virtual string get(const InterfacedBase & ib) const
00300 ;
00301
00305 virtual Type tget(const InterfacedBase & ib) const
00306 = 0;
00307
00313 virtual string minimum(const InterfacedBase & ib) const
00314 ;
00315
00320 virtual Type tminimum(const InterfacedBase & ib) const
00321 = 0;
00322
00328 virtual string maximum(const InterfacedBase & ib) const
00329 ;
00330
00335 virtual Type tmaximum(const InterfacedBase & ib) const
00336 = 0;
00337
00343 virtual string def(const InterfacedBase & ib) const
00344 ;
00345
00349 virtual Type tdef(const InterfacedBase &ib) const
00350 = 0;
00351
00355 virtual void setDef(InterfacedBase & ib) const {
00356 tset(ib, tdef(ib));
00357 }
00358
00364 Type unit() const { return theUnit; }
00365
00371 void unit(Type u) { theUnit = u; }
00372
00377 virtual string doxygenType() const;
00378
00379 protected:
00380
00384 void putUnit(ostream & os, Type val) const {
00385 putUnitImpl(os, val, unit(), typename TypeTraits<Type>::DimType());
00386 }
00387
00388 private:
00389
00395 Type theUnit;
00396
00397 };
00398
00417 template <typename T, typename Type>
00418 class Parameter: public ParameterTBase<Type> {
00419
00420 public:
00421
00426 typedef void (T::*SetFn)(Type);
00431 typedef Type (T::*GetFn)() const;
00432
00436 typedef Type T::* Member;
00437
00438 public:
00439
00482 Parameter(string newName, string newDescription,
00483 Member newMember, Type newDef, Type newMin,
00484 Type newMax, bool depSafe = false, bool readonly = false,
00485 bool limits = true, SetFn newSetFn = 0,
00486 GetFn newGetFn = 0, GetFn newMinFn = 0,
00487 GetFn newMaxFn = 0, GetFn newDefFn = 0)
00488 : ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
00489 typeid(T), Type(), depSafe, readonly, limits),
00490 theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
00491 theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
00492 theMinFn(newMinFn), theMaxFn(newMaxFn) {}
00493
00539 Parameter(string newName, string newDescription,
00540 Member newMember, Type newUnit, Type newDef, Type newMin,
00541 Type newMax, bool depSafe = false, bool readonly = false,
00542 bool limits = true, SetFn newSetFn = 0,
00543 GetFn newGetFn = 0, GetFn newMinFn = 0,
00544 GetFn newMaxFn = 0, GetFn newDefFn = 0)
00545 : ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
00546 typeid(T), newUnit, depSafe, readonly, limits),
00547 theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
00548 theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
00549 theMinFn(newMinFn), theMaxFn(newMaxFn) {}
00550
00594 Parameter(string newName, string newDescription,
00595 Member newMember, Type newDef, Type newMin,
00596 Type newMax, bool depSafe = false, bool readonly = false,
00597 int limits = Interface::limited, SetFn newSetFn = 0,
00598 GetFn newGetFn = 0, GetFn newMinFn = 0,
00599 GetFn newMaxFn = 0, GetFn newDefFn = 0)
00600 : ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
00601 typeid(T), Type(), depSafe, readonly, limits),
00602 theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
00603 theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
00604 theMinFn(newMinFn), theMaxFn(newMaxFn) {}
00605
00652 Parameter(string newName, string newDescription,
00653 Member newMember, Type newUnit, Type newDef, Type newMin,
00654 Type newMax, bool depSafe = false, bool readonly = false,
00655 int limits = Interface::limited, SetFn newSetFn = 0,
00656 GetFn newGetFn = 0, GetFn newMinFn = 0,
00657 GetFn newMaxFn = 0, GetFn newDefFn = 0)
00658 : ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
00659 typeid(T), newUnit, depSafe, readonly, limits),
00660 theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
00661 theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
00662 theMinFn(newMinFn), theMaxFn(newMaxFn) {}
00663
00667 virtual ~Parameter() {}
00668
00672 virtual void tset(InterfacedBase & ib, Type val)
00673 const;
00674
00678 virtual Type tget(const InterfacedBase & ib) const;
00679
00683 virtual Type tminimum(const InterfacedBase & ib) const
00684 ;
00685
00689 virtual Type tmaximum(const InterfacedBase & ib) const
00690 ;
00691
00695 virtual Type tdef(const InterfacedBase & ib) const
00696 ;
00697
00701 void setSetFunction(SetFn sf) { theSetFn = sf; }
00702
00706 void setGetFunction(GetFn gf) { theGetFn = gf; }
00707
00711 void setDefaultFunction(GetFn df) { theDefFn = df; }
00712
00716 void setMinFunction(GetFn mf) { theMinFn = mf; }
00717
00721 void setMaxFunction(GetFn mf) { theMaxFn = mf; }
00722
00727 virtual void doxygenDescription(ostream & stream) const;
00728
00729 private:
00730
00734 Member theMember;
00735
00740 Type theDef;
00741
00746 Type theMin;
00747
00752 Type theMax;
00753
00757 SetFn theSetFn;
00758
00762 GetFn theGetFn;
00763
00767 GetFn theDefFn;
00768
00772 GetFn theMinFn;
00773
00777 GetFn theMaxFn;
00778
00779 };
00780
00787 template <>
00788 class ParameterTBase<string>: public ParameterBase {
00789
00790 public:
00791
00796 enum FileType {
00797 NoFile,
00798 File,
00799 Directory
00800 };
00801
00802 public:
00803
00824 ParameterTBase(string newName, string newDescription,
00825 string newClassName,
00826 const type_info & newTypeInfo,
00827 bool depSafe, bool readonly)
00828 : ParameterBase(newName, newDescription,
00829 newClassName, newTypeInfo, depSafe,
00830 readonly, false), isFileType(NoFile) {}
00831
00835 virtual ~ParameterTBase() {}
00836
00840 virtual string type() const {
00841 switch ( file() ) {
00842 case File: return "PF";
00843 case Directory: return "PD";
00844 default: return "Ps";
00845 }
00846 }
00847
00851 void fileType() { file(File); }
00852
00856 void directoryType() { file(Directory); }
00857
00861 void file(FileType t) { isFileType = t; }
00862
00866 FileType file() const { return isFileType; }
00867
00873 virtual void set(InterfacedBase & ib, string newValue)
00874 const {
00875 tset(ib, StringUtils::stripws(newValue));
00876 }
00877
00881 virtual void tset(InterfacedBase & ib, string) const
00882 = 0;
00883
00889 virtual string get(const InterfacedBase & ib) const
00890 {
00891 return tget(ib);
00892 }
00893
00897 virtual string tget(const InterfacedBase & ib) const
00898 = 0;
00899
00904 virtual string minimum(const InterfacedBase &) const {
00905 return "";
00906 }
00907
00912 virtual string maximum(const InterfacedBase &) const {
00913 return "";
00914 }
00915
00921 virtual string def(const InterfacedBase & ib) const
00922 {
00923 return tdef(ib);
00924 }
00925
00929 virtual string tdef(const InterfacedBase &ib) const
00930 = 0;
00931
00935 virtual void setDef(InterfacedBase & i) const {
00936 tset(i, tdef(i));
00937 }
00938
00943 virtual string doxygenType() const { return "Character string parameter"; }
00944
00945 private:
00946
00950 FileType isFileType;
00951
00952 };
00953
00960 template <typename T>
00961 class Parameter<T,string>: public ParameterTBase<string> {
00962
00963 public:
00964
00969 typedef void (T::*SetFn)(string);
00974 typedef string (T::*GetFn)() const;
00975
00979 typedef string T::* Member;
00980
00981 public:
00982
01012 Parameter(string newName, string newDescription,
01013 Member newMember, string newDef,
01014 bool depSafe = false, bool readonly = false,
01015 SetFn newSetFn = 0, GetFn newGetFn = 0, GetFn newDefFn = 0)
01016 : ParameterTBase<string>(newName, newDescription,
01017 ClassTraits<T>::className(),
01018 typeid(T), depSafe, readonly),
01019 theMember(newMember), theDef(newDef),
01020 theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn) {}
01021
01022
01026 virtual ~Parameter() {}
01027
01031 virtual void tset(InterfacedBase & ib, string val)
01032 const;
01033
01037 virtual string tget(const InterfacedBase & ib) const
01038 ;
01039
01043 virtual string tdef(const InterfacedBase & ib) const
01044 ;
01045
01049 void setSetFunction(SetFn sf) { theSetFn = sf; }
01050
01054 void setGetFunction(GetFn gf) { theGetFn = gf; }
01055
01059 void setDefaultFunction(GetFn df) { theDefFn = df; }
01060
01065 virtual void doxygenDescription(ostream & stream) const;
01066
01067 private:
01068
01072 Member theMember;
01073
01078 string theDef;
01079
01083 SetFn theSetFn;
01084
01088 GetFn theGetFn;
01089
01093 GetFn theDefFn;
01094
01095 };
01096
01097 }
01098
01099 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
01100 #include "Parameter.tcc"
01101 #endif
01102
01103 #endif