thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
Parameter.h
1 // -*- C++ -*-
2 //
3 // Parameter.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_Parameter_H
10 #define ThePEG_Parameter_H
11 // This is the declaration of the Parameter, ParameterTBase and
12 // ParameterBase classes.
13 
14 
15 #include "ThePEG/Config/ThePEG.h"
16 #include "ThePEG/Utilities/Throw.h"
17 #include "InterfaceBase.h"
18 #include "Parameter.xh"
19 #include "Parameter.fh"
20 #include "ThePEG/Utilities/StringUtils.h"
21 #include <limits>
22 
23 namespace ThePEG {
24 
26 namespace {
27  template <typename T>
31  inline void putUnitImpl(ostream & os, T v, T u, DimensionT) {
32  os << v/u;
33  }
34 
35  template <typename T>
39  inline void putUnitImpl(ostream & os, T v, T u, StandardT) {
40  if ( u > T() )
41  os << v/u;
42  else
43  os << v;
44  }
45 
46  template <typename T>
50  inline void putUnitImpl(ostream & os, T v, T, EnumT) {
51  os << v;
52  }
53 }
54 
55 
57 namespace {
58 
59 template<typename T, typename U>
60 U umult(const T & t, const U & u) {
61  return t*u;
62 }
63 
64 template <typename U>
65 bool umult(bool b, U) {
66  return b;
67 }
68 }
69 
89 
90 public:
91 
116  ParameterBase(string newName, string newDescription,
117  string newClassName,
118  const type_info & newTypeInfo, bool depSafe,
119  bool readonly, int limits)
120  : InterfaceBase(newName, newDescription,
121  newClassName, newTypeInfo, depSafe,
122  readonly), limit(limits) {}
123 
127  virtual ~ParameterBase();
128 
136  virtual string exec(InterfacedBase & ib, string action,
137  string arguments) const;
138 
142  virtual string fullDescription(const InterfacedBase & ib) const;
143 
147  virtual void set(InterfacedBase & ib, string) const
148  = 0;
149 
153  virtual string minimum(const InterfacedBase & ib) const
154  = 0;
155 
159  virtual string maximum(const InterfacedBase & ib) const
160  = 0;
161 
165  virtual string get(const InterfacedBase & ib) const
166  = 0;
167 
171  virtual string def(const InterfacedBase & ib) const
172  = 0;
173 
177  virtual void setDef(InterfacedBase & ib) const
178  = 0;
179 
183  bool limited() const { return limit != Interface::nolimits; }
184 
188  bool upperLimit() const {
190  }
191 
195  bool lowerLimit() const {
197  }
198 
204 
210 
211 private:
212 
218  int limit;
219 
220 };
221 
240 template <typename Type>
242 
243 public:
244 
272  ParameterTBase(string newName, string newDescription,
273  string newClassName,
274  const type_info & newTypeInfo, Type newUnit,
275  bool depSafe, bool readonly, int limits)
276  : ParameterBase(newName, newDescription,
277  newClassName, newTypeInfo, depSafe,
278  readonly, limits), theUnit(newUnit) {}
279 
283  virtual ~ParameterTBase() {}
284 
288  virtual string type() const;
289 
290 private:
291 
293  void setImpl (InterfacedBase & i,
294  string newValue, StandardT)
295  const;
296 
298  void setImpl (InterfacedBase & i,
299  string newValue, DimensionT)
300  const;
301 
303  void setImpl (InterfacedBase & i,
304  string newValue, EnumT)
305  const;
306 
307 public:
308 
314  virtual void set(InterfacedBase & ib, string newValue)
315  const;
316 
320  virtual void tset(InterfacedBase & ib, Type) const
321  = 0;
322 
328  virtual string get(const InterfacedBase & ib) const
329  ;
330 
334  virtual Type tget(const InterfacedBase & ib) const
335  = 0;
336 
342  virtual string minimum(const InterfacedBase & ib) const
343  ;
344 
349  virtual Type tminimum(const InterfacedBase & ib) const
350  = 0;
351 
357  virtual string maximum(const InterfacedBase & ib) const
358  ;
359 
364  virtual Type tmaximum(const InterfacedBase & ib) const
365  = 0;
366 
372  virtual string def(const InterfacedBase & ib) const
373  ;
374 
378  virtual Type tdef(const InterfacedBase &ib) const
379  = 0;
380 
384  virtual void setDef(InterfacedBase & ib) const {
385  tset(ib, tdef(ib));
386  }
387 
393  Type unit() const { return theUnit; }
394 
400  void unit(Type u) { theUnit = u; }
401 
406  virtual string doxygenType() const;
407 
408 protected:
409 
413  void putUnit(ostream & os, Type val) const {
414  putUnitImpl(os, val, unit(), typename TypeTraits<Type>::DimType());
415  }
416 
417 private:
418 
424  Type theUnit;
425 
429  void checkUnitConsistency(string suffix) const;
430 
431 };
432 
451 template <typename T, typename Type>
452 class Parameter: public ParameterTBase<Type> {
453 
454 public:
455 
460  typedef void (T::*SetFn)(Type);
465  typedef Type (T::*GetFn)() const;
466 
470  typedef Type T::* Member;
471 
472 public:
473 
516  Parameter(string newName, string newDescription,
517  Member newMember, Type newDef, Type newMin,
518  Type newMax, bool depSafe = false, bool readonly = false,
519  bool limits = true, SetFn newSetFn = 0,
520  GetFn newGetFn = 0, GetFn newMinFn = 0,
521  GetFn newMaxFn = 0, GetFn newDefFn = 0)
522  : ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
523  typeid(T), Type(), depSafe, readonly, limits),
524  theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
525  theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
526  theMinFn(newMinFn), theMaxFn(newMaxFn) {}
527 
573  Parameter(string newName, string newDescription,
574  Member newMember, Type newUnit, Type newDef, Type newMin,
575  Type newMax, bool depSafe = false, bool readonly = false,
576  bool limits = true, SetFn newSetFn = 0,
577  GetFn newGetFn = 0, GetFn newMinFn = 0,
578  GetFn newMaxFn = 0, GetFn newDefFn = 0)
579  : ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
580  typeid(T), newUnit, depSafe, readonly, limits),
581  theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
582  theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
583  theMinFn(newMinFn), theMaxFn(newMaxFn) {}
584 
628  Parameter(string newName, string newDescription,
629  Member newMember, Type newDef, Type newMin,
630  Type newMax, bool depSafe = false, bool readonly = false,
631  int limits = Interface::limited, SetFn newSetFn = 0,
632  GetFn newGetFn = 0, GetFn newMinFn = 0,
633  GetFn newMaxFn = 0, GetFn newDefFn = 0)
634  : ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
635  typeid(T), Type(), depSafe, readonly, limits),
636  theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
637  theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
638  theMinFn(newMinFn), theMaxFn(newMaxFn) {}
639 
686  Parameter(string newName, string newDescription,
687  Member newMember, Type newUnit, Type newDef, Type newMin,
688  Type newMax, bool depSafe = false, bool readonly = false,
689  int limits = Interface::limited, SetFn newSetFn = 0,
690  GetFn newGetFn = 0, GetFn newMinFn = 0,
691  GetFn newMaxFn = 0, GetFn newDefFn = 0)
692  : ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
693  typeid(T), newUnit, depSafe, readonly, limits),
694  theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
695  theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
696  theMinFn(newMinFn), theMaxFn(newMaxFn) {}
697 
701  virtual ~Parameter() {}
702 
706  virtual void tset(InterfacedBase & ib, Type val)
707  const;
708 
712  virtual Type tget(const InterfacedBase & ib) const;
713 
717  virtual Type tminimum(const InterfacedBase & ib) const
718  ;
719 
723  virtual Type tmaximum(const InterfacedBase & ib) const
724  ;
725 
729  virtual Type tdef(const InterfacedBase & ib) const
730  ;
731 
735  void setSetFunction(SetFn sf) { theSetFn = sf; }
736 
740  void setGetFunction(GetFn gf) { theGetFn = gf; }
741 
745  void setDefaultFunction(GetFn df) { theDefFn = df; }
746 
750  void setMinFunction(GetFn mf) { theMinFn = mf; }
751 
755  void setMaxFunction(GetFn mf) { theMaxFn = mf; }
756 
761  virtual void doxygenDescription(ostream & stream) const;
762 
763 private:
764 
769 
774  Type theDef;
775 
780  Type theMin;
781 
786  Type theMax;
787 
791  SetFn theSetFn;
792 
796  GetFn theGetFn;
797 
801  GetFn theDefFn;
802 
806  GetFn theMinFn;
807 
811  GetFn theMaxFn;
812 
813 };
814 
821 template <>
822 class ParameterTBase<string>: public ParameterBase {
823 
824 public:
825 
830  enum FileType {
833  Directory
834  };
835 
836 public:
837 
858  ParameterTBase(string newName, string newDescription,
859  string newClassName,
860  const type_info & newTypeInfo,
861  bool depSafe, bool readonly)
862  : ParameterBase(newName, newDescription,
863  newClassName, newTypeInfo, depSafe,
864  readonly, false), isFileType(NoFile) {
865  hasDefault = false;
866  }
867 
871  virtual ~ParameterTBase() {}
872 
876  virtual string type() const {
877  switch ( file() ) {
878  case File: return "PF";
879  case Directory: return "PD";
880  default: return "Ps";
881  }
882  }
883 
887  void fileType() { file(File); }
888 
892  void directoryType() { file(Directory); }
893 
897  void file(FileType t) { isFileType = t; }
898 
902  FileType file() const { return isFileType; }
903 
909  virtual void set(InterfacedBase & ib, string newValue)
910  const {
911  tset(ib, StringUtils::stripws(newValue));
912  }
913 
917  virtual void tset(InterfacedBase & ib, string) const
918  = 0;
919 
925  virtual string get(const InterfacedBase & ib) const
926  {
927  return tget(ib);
928  }
929 
933  virtual string tget(const InterfacedBase & ib) const
934  = 0;
935 
940  virtual string minimum(const InterfacedBase &) const {
941  return "";
942  }
943 
948  virtual string maximum(const InterfacedBase &) const {
949  return "";
950  }
951 
957  virtual string def(const InterfacedBase & ib) const
958  {
959  return tdef(ib);
960  }
961 
965  virtual string tdef(const InterfacedBase &ib) const
966  = 0;
967 
971  virtual void setDef(InterfacedBase & i) const {
972  tset(i, tdef(i));
973  }
974 
979  virtual string doxygenType() const { return "Character string parameter"; }
980 
981 private:
982 
987 
988 };
989 
996 template <typename T>
997 class Parameter<T,string>: public ParameterTBase<string> {
998 
999 public:
1000 
1005  typedef void (T::*SetFn)(string);
1010  typedef string (T::*GetFn)() const;
1011 
1015  typedef string T::* Member;
1016 
1017 public:
1018 
1048  Parameter(string newName, string newDescription,
1049  Member newMember, string newDef,
1050  bool depSafe = false, bool readonly = false,
1051  SetFn newSetFn = 0, GetFn newGetFn = 0, GetFn newDefFn = 0)
1052  : ParameterTBase<string>(newName, newDescription,
1053  ClassTraits<T>::className(),
1054  typeid(T), depSafe, readonly),
1055  theMember(newMember), theDef(newDef),
1056  theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn) {}
1057 
1058 
1062  virtual ~Parameter() {}
1063 
1067  virtual void tset(InterfacedBase & ib, string val)
1068  const;
1069 
1073  virtual string tget(const InterfacedBase & ib) const
1074  ;
1075 
1079  virtual string tdef(const InterfacedBase & ib) const
1080  ;
1081 
1085  void setSetFunction(SetFn sf) { theSetFn = sf; }
1086 
1090  void setGetFunction(GetFn gf) { theGetFn = gf; }
1091 
1095  void setDefaultFunction(GetFn df) { theDefFn = df; }
1096 
1101  virtual void doxygenDescription(ostream & stream) const;
1102 
1103 private:
1104 
1109 
1114  string theDef;
1115 
1119  SetFn theSetFn;
1120 
1124  GetFn theGetFn;
1125 
1129  GetFn theDefFn;
1130 
1131 };
1132 
1133 }
1134 
1135 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
1136 #include "Parameter.tcc"
1137 #endif
1138 
1139 #endif /* ThePEG_Parameter_H */
virtual string maximum(const InterfacedBase &) const
Return the maximum value allowed for the member variable of ib.
Definition: Parameter.h:948
void putUnit(ostream &os, Type val) const
Write a number to a stream with the unit specified with unit().
Definition: Parameter.h:413
Member theMember
The pointer to the member variable.
Definition: Parameter.h:768
GetFn theMinFn
Pointer to member function to be used by tminimum().
Definition: Parameter.h:806
virtual string exec(InterfacedBase &ib, string action, string arguments) const
The general interface method overriding the one in InterfaceBase.
Parameter(string newName, string newDescription, Member newMember, Type newDef, Type newMin, Type newMax, bool depSafe=false, bool readonly=false, int limits=Interface::limited, SetFn newSetFn=0, GetFn newGetFn=0, GetFn newMinFn=0, GetFn newMaxFn=0, GetFn newDefFn=0)
Standard constructor.
Definition: Parameter.h:628
The Parameter and its base classes ParameterTBase and ParameterBase defines an interface to a class d...
Definition: Parameter.h:241
virtual string minimum(const InterfacedBase &) const
Return the minimum value allowed for the member variable of ib.
Definition: Parameter.h:940
virtual string doxygenType() const =0
Return a string describing the type of interface to be included in the Doxygen documentation.
void directoryType()
Indicate that this parameter corresponds to a directory.
Definition: Parameter.h:892
void setGetFunction(GetFn gf)
Give a pointer to a member function to be used by tget().
Definition: Parameter.h:740
virtual string maximum(const InterfacedBase &ib) const =0
Return the maximum value allowed for the member variable of ib.
virtual ~ParameterTBase()
Destructor.
Definition: Parameter.h:283
bool lowerLimit() const
True if there the variable is limited from below.
Definition: Parameter.h:195
virtual string type() const =0
Return a code for the type of this interface.
Parameter(string newName, string newDescription, Member newMember, Type newUnit, Type newDef, Type newMin, Type newMax, bool depSafe=false, bool readonly=false, int limits=Interface::limited, SetFn newSetFn=0, GetFn newGetFn=0, GetFn newMinFn=0, GetFn newMaxFn=0, GetFn newDefFn=0)
Standard constructor.
Definition: Parameter.h:686
The InterfaceBase class defines a generic interface to any class derived from the InterfacedBase clas...
Definition: InterfaceBase.h:59
void setDefaultFunction(GetFn df)
Give a pointer to a member function to be used by tdef().
Definition: Parameter.h:1095
virtual ~Parameter()
Default dtor.
Definition: Parameter.h:701
bool hasDefault
A flag indicating whether this interface has a default setting.
virtual ~ParameterBase()
The destructor.
GetFn theDefFn
Pointer to member function to be used by tdef().
Definition: Parameter.h:1129
void setDefaultFunction(GetFn df)
Give a pointer to a member function to be used by tdef().
Definition: Parameter.h:745
ParameterBase(string newName, string newDescription, string newClassName, const type_info &newTypeInfo, bool depSafe, bool readonly, int limits)
Standard constructor.
Definition: Parameter.h:116
FileType isFileType
Indicates if this parameter corresponds to a file or directory.
Definition: Parameter.h:986
Conversion between integers and types.
Definition: TemplateTools.h:23
virtual ~Parameter()
Default dtor.
Definition: Parameter.h:1062
Type theMin
Minimum value to be used if no corresponding member function pointer is given.
Definition: Parameter.h:780
int limit
Determines if the values of the parameters are limited from above and/or below.
Definition: Parameter.h:218
virtual string def(const InterfacedBase &ib) const =0
Return the default value for the member variable of ib.
SetFn theSetFn
A pointer to a member function to be used by tset().
Definition: Parameter.h:1119
void setUnlimited()
Set flag indicating that there are no limits associated with the variable.
Definition: Parameter.h:209
bool limited() const
True if there the variable is limited from above and below.
Definition: Parameter.h:183
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
Neither file nor directory.
Definition: Parameter.h:831
virtual string fullDescription(const InterfacedBase &ib) const
Return a complete description of this parameter.
Type theMax
Maximum value to be used if no corresponding member function pointer is given.
Definition: Parameter.h:786
This is the main config header file for ThePEG.
void file(FileType t)
Indicate if this parameter corresponds to a file or directory.
Definition: Parameter.h:897
Type T::* Member
Declaration of a direct pointer to the member variable.
Definition: Parameter.h:470
Int2Type< Enumerated > EnumT
Typedef for non-dimensioned types.
Definition: TemplateTools.h:43
string theDef
Default, minimum and maximum values to be used if no corresponding member function pointers are given...
Definition: Parameter.h:1114
static string stripws(string str)
Return the string str stripped from leading and trailing white space.
virtual void doxygenDescription(ostream &stream) const
Print a description to be included in the Doxygen documentation to the given stream.
Parameter(string newName, string newDescription, Member newMember, Type newUnit, Type newDef, Type newMin, Type newMax, bool depSafe=false, bool readonly=false, bool limits=true, SetFn newSetFn=0, GetFn newGetFn=0, GetFn newMinFn=0, GetFn newMaxFn=0, GetFn newDefFn=0)
Standard constructor.
Definition: Parameter.h:573
virtual string type() const
Return a code for the type of this parameter.
Definition: Parameter.h:876
virtual void setDef(InterfacedBase &i) const
set the member variable of ib to its default value.
Definition: Parameter.h:971
string T::* Member
Declaration of a direct pointer to the member variable.
Definition: Parameter.h:1015
virtual string minimum(const InterfacedBase &ib) const =0
Return the minimum value allowed for the member variable of ib.
GetFn theDefFn
Pointer to member function to be used by tdef().
Definition: Parameter.h:801
Type theDef
Default value to be used if no corresponding member function pointer is given.
Definition: Parameter.h:774
Int2Type< Dimensioned > DimensionT
Typedef for dimensioned types.
Definition: TemplateTools.h:37
ParameterTBase(string newName, string newDescription, string newClassName, const type_info &newTypeInfo, Type newUnit, bool depSafe, bool readonly, int limits)
Standard constructor.
Definition: Parameter.h:272
FileType file() const
See if this parameter corresponds to a file or directory.
Definition: Parameter.h:902
FileType
Enumerated variables to determine of a string parameter corresponds to a file or a directory...
Definition: Parameter.h:830
void setMinFunction(GetFn mf)
Give a pointer to a member function to be used by tminimum().
Definition: Parameter.h:750
The Parameter and its base classes ParameterTBase and ParameterBase defines an interface to a class d...
Definition: Parameter.h:88
GetFn theGetFn
Pointer to member function to be used by tget().
Definition: Parameter.h:796
GetFn theMaxFn
Pointer to member function to be used by tmaximum().
Definition: Parameter.h:811
The parameter is not limited.
Definition: Interface.h:46
void unit(Type u)
Set the unit which an Type object is divided (multiplied) by when written to (read from) a stream via...
Definition: Parameter.h:400
InterfacedBase is the base class of all Interfaced objects to be handled by the BaseRepository class...
void setGetFunction(GetFn gf)
Give a pointer to a member function to be used by tget().
Definition: Parameter.h:1090
virtual void setDef(InterfacedBase &ib) const =0
Set the member variable of ib to its default value.
virtual ~ParameterTBase()
Destructor.
Definition: Parameter.h:871
GetFn theGetFn
Pointer to member function to be used by tget().
Definition: Parameter.h:1124
string className() const
Return the class name for the class this interface is defined for.
The parameter has only an upper limit.
Definition: Interface.h:48
Parameter(string newName, string newDescription, Member newMember, Type newDef, Type newMin, Type newMax, bool depSafe=false, bool readonly=false, bool limits=true, SetFn newSetFn=0, GetFn newGetFn=0, GetFn newMinFn=0, GetFn newMaxFn=0, GetFn newDefFn=0)
Standard constructor.
Definition: Parameter.h:516
Member theMember
The pointer to the member variable.
Definition: Parameter.h:1108
The parameter has only an lower limit.
Definition: Interface.h:49
The parameter corresponds to a file.
Definition: Parameter.h:832
SetFn theSetFn
A pointer to a member function to be used by tset().
Definition: Parameter.h:791
The default concrete implementation of ClassTraitsBase.
Definition: ClassTraits.h:134
void setSetFunction(SetFn sf)
Give a pointer to a member function to be used by tset().
Definition: Parameter.h:735
The parameter is limited (both up- and downwards.
Definition: Interface.h:47
void setLimited()
Set flag indicating that there are limits associated with the variable.
Definition: Parameter.h:203
void fileType()
Indicate that this parameter corresponds to a file.
Definition: Parameter.h:887
void setMaxFunction(GetFn mf)
Give a pointer to a member function to be used by tmaximum().
Definition: Parameter.h:755
bool upperLimit() const
True if there the variable is limited from abovew.
Definition: Parameter.h:188
Int2Type< Standard > StandardT
Typedef for non-dimensioned types.
Definition: TemplateTools.h:40
virtual void setDef(InterfacedBase &ib) const
set the member variable of ib to its default value.
Definition: Parameter.h:384
Type unit() const
Get the unit which an Type object is divided (multiplied) by when written to (read from) a stream via...
Definition: Parameter.h:393
Parameter(string newName, string newDescription, Member newMember, string newDef, bool depSafe=false, bool readonly=false, SetFn newSetFn=0, GetFn newGetFn=0, GetFn newDefFn=0)
Standard constructor.
Definition: Parameter.h:1048
The Parameter and its base classes ParameterTBase and ParameterBase defines an interface to a class d...
Definition: Parameter.h:452
Type theUnit
The unit which an Type object is divided (multiplied) by when written to (read from) a stream via a d...
Definition: Parameter.h:424
virtual string def(const InterfacedBase &ib) const
Return the default value for the member variables of ib.
Definition: Parameter.h:957
ParameterTBase(string newName, string newDescription, string newClassName, const type_info &newTypeInfo, bool depSafe, bool readonly)
Standard constructor.
Definition: Parameter.h:858
void setSetFunction(SetFn sf)
Give a pointer to a member function to be used by tset().
Definition: Parameter.h:1085
virtual string doxygenType() const
Return a string describing the type of interface to be included in the Doxygen documentation.
Definition: Parameter.h:979