ThePEG  1.8.0
Parameter.h
1 // -*- C++ -*-
2 //
3 // Parameter.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2011 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 2 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 "InterfaceBase.h"
17 #include "Parameter.xh"
18 #include "Parameter.fh"
19 #include "ThePEG/Utilities/StringUtils.h"
20 #include <limits>
21 
22 namespace ThePEG {
23 
25 namespace {
26  template <typename T>
30  inline void putUnitImpl(ostream & os, T v, T u, DimensionT) {
31  os << v/u;
32  }
33 
34  template <typename T>
38  inline void putUnitImpl(ostream & os, T v, T u, StandardT) {
39  if ( u > T() )
40  os << v/u;
41  else
42  os << v;
43  }
44 }
45 
65 
66 public:
67 
92  ParameterBase(string newName, string newDescription,
93  string newClassName,
94  const type_info & newTypeInfo, bool depSafe,
95  bool readonly, int limits)
96  : InterfaceBase(newName, newDescription,
97  newClassName, newTypeInfo, depSafe,
98  readonly), limit(limits) {}
99 
103  virtual ~ParameterBase();
104 
112  virtual string exec(InterfacedBase & ib, string action,
113  string arguments) const;
114 
118  virtual string fullDescription(const InterfacedBase & ib) const;
119 
123  virtual void set(InterfacedBase & ib, string) const
124  = 0;
125 
129  virtual string minimum(const InterfacedBase & ib) const
130  = 0;
131 
135  virtual string maximum(const InterfacedBase & ib) const
136  = 0;
137 
141  virtual string get(const InterfacedBase & ib) const
142  = 0;
143 
147  virtual string def(const InterfacedBase & ib) const
148  = 0;
149 
153  virtual void setDef(InterfacedBase & ib) const
154  = 0;
155 
159  bool limited() const { return limit != Interface::nolimits; }
160 
164  bool upperLimit() const {
166  }
167 
171  bool lowerLimit() const {
173  }
174 
180 
186 
187 private:
188 
194  int limit;
195 
196 };
197 
216 template <typename Type>
218 
219 public:
220 
248  ParameterTBase(string newName, string newDescription,
249  string newClassName,
250  const type_info & newTypeInfo, Type newUnit,
251  bool depSafe, bool readonly, int limits)
252  : ParameterBase(newName, newDescription,
253  newClassName, newTypeInfo, depSafe,
254  readonly, limits), theUnit(newUnit) {}
255 
259  virtual ~ParameterTBase() {}
260 
264  virtual string type() const;
265 
266 private:
267 
269  void setImpl (InterfacedBase & i,
270  string newValue, StandardT)
271  const;
272 
274  void setImpl (InterfacedBase & i,
275  string newValue, DimensionT)
276  const;
277 
278 public:
279 
285  virtual void set(InterfacedBase & ib, string newValue)
286  const;
287 
291  virtual void tset(InterfacedBase & ib, Type) const
292  = 0;
293 
299  virtual string get(const InterfacedBase & ib) const
300  ;
301 
305  virtual Type tget(const InterfacedBase & ib) const
306  = 0;
307 
313  virtual string minimum(const InterfacedBase & ib) const
314  ;
315 
320  virtual Type tminimum(const InterfacedBase & ib) const
321  = 0;
322 
328  virtual string maximum(const InterfacedBase & ib) const
329  ;
330 
335  virtual Type tmaximum(const InterfacedBase & ib) const
336  = 0;
337 
343  virtual string def(const InterfacedBase & ib) const
344  ;
345 
349  virtual Type tdef(const InterfacedBase &ib) const
350  = 0;
351 
355  virtual void setDef(InterfacedBase & ib) const {
356  tset(ib, tdef(ib));
357  }
358 
364  Type unit() const { return theUnit; }
365 
371  void unit(Type u) { theUnit = u; }
372 
377  virtual string doxygenType() const;
378 
379 protected:
380 
384  void putUnit(ostream & os, Type val) const {
385  putUnitImpl(os, val, unit(), typename TypeTraits<Type>::DimType());
386  }
387 
388 private:
389 
395  Type theUnit;
396 
397 };
398 
417 template <typename T, typename Type>
418 class Parameter: public ParameterTBase<Type> {
419 
420 public:
421 
426  typedef void (T::*SetFn)(Type);
431  typedef Type (T::*GetFn)() const;
432 
436  typedef Type T::* Member;
437 
438 public:
439 
482  Parameter(string newName, string newDescription,
483  Member newMember, Type newDef, Type newMin,
484  Type newMax, bool depSafe = false, bool readonly = false,
485  bool limits = true, SetFn newSetFn = 0,
486  GetFn newGetFn = 0, GetFn newMinFn = 0,
487  GetFn newMaxFn = 0, GetFn newDefFn = 0)
488  : ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
489  typeid(T), Type(), depSafe, readonly, limits),
490  theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
491  theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
492  theMinFn(newMinFn), theMaxFn(newMaxFn) {}
493 
539  Parameter(string newName, string newDescription,
540  Member newMember, Type newUnit, Type newDef, Type newMin,
541  Type newMax, bool depSafe = false, bool readonly = false,
542  bool limits = true, SetFn newSetFn = 0,
543  GetFn newGetFn = 0, GetFn newMinFn = 0,
544  GetFn newMaxFn = 0, GetFn newDefFn = 0)
545  : ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
546  typeid(T), newUnit, depSafe, readonly, limits),
547  theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
548  theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
549  theMinFn(newMinFn), theMaxFn(newMaxFn) {}
550 
594  Parameter(string newName, string newDescription,
595  Member newMember, Type newDef, Type newMin,
596  Type newMax, bool depSafe = false, bool readonly = false,
597  int limits = Interface::limited, SetFn newSetFn = 0,
598  GetFn newGetFn = 0, GetFn newMinFn = 0,
599  GetFn newMaxFn = 0, GetFn newDefFn = 0)
600  : ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
601  typeid(T), Type(), depSafe, readonly, limits),
602  theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
603  theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
604  theMinFn(newMinFn), theMaxFn(newMaxFn) {}
605 
652  Parameter(string newName, string newDescription,
653  Member newMember, Type newUnit, Type newDef, Type newMin,
654  Type newMax, bool depSafe = false, bool readonly = false,
655  int limits = Interface::limited, SetFn newSetFn = 0,
656  GetFn newGetFn = 0, GetFn newMinFn = 0,
657  GetFn newMaxFn = 0, GetFn newDefFn = 0)
658  : ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
659  typeid(T), newUnit, depSafe, readonly, limits),
660  theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
661  theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
662  theMinFn(newMinFn), theMaxFn(newMaxFn) {}
663 
667  virtual ~Parameter() {}
668 
672  virtual void tset(InterfacedBase & ib, Type val)
673  const;
674 
678  virtual Type tget(const InterfacedBase & ib) const;
679 
683  virtual Type tminimum(const InterfacedBase & ib) const
684  ;
685 
689  virtual Type tmaximum(const InterfacedBase & ib) const
690  ;
691 
695  virtual Type tdef(const InterfacedBase & ib) const
696  ;
697 
701  void setSetFunction(SetFn sf) { theSetFn = sf; }
702 
706  void setGetFunction(GetFn gf) { theGetFn = gf; }
707 
711  void setDefaultFunction(GetFn df) { theDefFn = df; }
712 
716  void setMinFunction(GetFn mf) { theMinFn = mf; }
717 
721  void setMaxFunction(GetFn mf) { theMaxFn = mf; }
722 
727  virtual void doxygenDescription(ostream & stream) const;
728 
729 private:
730 
735 
740  Type theDef;
741 
746  Type theMin;
747 
752  Type theMax;
753 
757  SetFn theSetFn;
758 
762  GetFn theGetFn;
763 
767  GetFn theDefFn;
768 
772  GetFn theMinFn;
773 
777  GetFn theMaxFn;
778 
779 };
780 
787 template <>
788 class ParameterTBase<string>: public ParameterBase {
789 
790 public:
791 
796  enum FileType {
799  Directory
800  };
801 
802 public:
803 
824  ParameterTBase(string newName, string newDescription,
825  string newClassName,
826  const type_info & newTypeInfo,
827  bool depSafe, bool readonly)
828  : ParameterBase(newName, newDescription,
829  newClassName, newTypeInfo, depSafe,
830  readonly, false), isFileType(NoFile) {
831  hasDefault = false;
832  }
833 
837  virtual ~ParameterTBase() {}
838 
842  virtual string type() const {
843  switch ( file() ) {
844  case File: return "PF";
845  case Directory: return "PD";
846  default: return "Ps";
847  }
848  }
849 
853  void fileType() { file(File); }
854 
858  void directoryType() { file(Directory); }
859 
863  void file(FileType t) { isFileType = t; }
864 
868  FileType file() const { return isFileType; }
869 
875  virtual void set(InterfacedBase & ib, string newValue)
876  const {
877  tset(ib, StringUtils::stripws(newValue));
878  }
879 
883  virtual void tset(InterfacedBase & ib, string) const
884  = 0;
885 
891  virtual string get(const InterfacedBase & ib) const
892  {
893  return tget(ib);
894  }
895 
899  virtual string tget(const InterfacedBase & ib) const
900  = 0;
901 
906  virtual string minimum(const InterfacedBase &) const {
907  return "";
908  }
909 
914  virtual string maximum(const InterfacedBase &) const {
915  return "";
916  }
917 
923  virtual string def(const InterfacedBase & ib) const
924  {
925  return tdef(ib);
926  }
927 
931  virtual string tdef(const InterfacedBase &ib) const
932  = 0;
933 
937  virtual void setDef(InterfacedBase & i) const {
938  tset(i, tdef(i));
939  }
940 
945  virtual string doxygenType() const { return "Character string parameter"; }
946 
947 private:
948 
953 
954 };
955 
962 template <typename T>
963 class Parameter<T,string>: public ParameterTBase<string> {
964 
965 public:
966 
971  typedef void (T::*SetFn)(string);
976  typedef string (T::*GetFn)() const;
977 
981  typedef string T::* Member;
982 
983 public:
984 
1014  Parameter(string newName, string newDescription,
1015  Member newMember, string newDef,
1016  bool depSafe = false, bool readonly = false,
1017  SetFn newSetFn = 0, GetFn newGetFn = 0, GetFn newDefFn = 0)
1018  : ParameterTBase<string>(newName, newDescription,
1019  ClassTraits<T>::className(),
1020  typeid(T), depSafe, readonly),
1021  theMember(newMember), theDef(newDef),
1022  theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn) {}
1023 
1024 
1028  virtual ~Parameter() {}
1029 
1033  virtual void tset(InterfacedBase & ib, string val)
1034  const;
1035 
1039  virtual string tget(const InterfacedBase & ib) const
1040  ;
1041 
1045  virtual string tdef(const InterfacedBase & ib) const
1046  ;
1047 
1051  void setSetFunction(SetFn sf) { theSetFn = sf; }
1052 
1056  void setGetFunction(GetFn gf) { theGetFn = gf; }
1057 
1061  void setDefaultFunction(GetFn df) { theDefFn = df; }
1062 
1067  virtual void doxygenDescription(ostream & stream) const;
1068 
1069 private:
1070 
1075 
1080  string theDef;
1081 
1085  SetFn theSetFn;
1086 
1090  GetFn theGetFn;
1091 
1095  GetFn theDefFn;
1096 
1097 };
1098 
1099 }
1100 
1101 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
1102 #include "Parameter.tcc"
1103 #endif
1104 
1105 #endif /* ThePEG_Parameter_H */
Member theMember
The pointer to the member variable.
Definition: Parameter.h:734
GetFn theMinFn
Pointer to member function to be used by tminimum().
Definition: Parameter.h:772
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:594
The Parameter and its base classes ParameterTBase and ParameterBase defines an interface to a class d...
Definition: Parameter.h:217
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:858
void setGetFunction(GetFn gf)
Give a pointer to a member function to be used by tget().
Definition: Parameter.h:706
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:259
virtual string exec(InterfacedBase &ib, string action, string arguments) const
The general interface method overriding the one in InterfaceBase.
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:652
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:1061
virtual ~Parameter()
Default dtor.
Definition: Parameter.h:667
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:1095
void setDefaultFunction(GetFn df)
Give a pointer to a member function to be used by tdef().
Definition: Parameter.h:711
ParameterBase(string newName, string newDescription, string newClassName, const type_info &newTypeInfo, bool depSafe, bool readonly, int limits)
Standard constructor.
Definition: Parameter.h:92
FileType isFileType
Indicates if this parameter corresponds to a file or directory.
Definition: Parameter.h:952
Conversion between integers and types.
Definition: TemplateTools.h:21
virtual ~Parameter()
Default dtor.
Definition: Parameter.h:1028
Type theMin
Minimum value to be used if no corresponding member function pointer is given.
Definition: Parameter.h:746
int limit
Determines if the values of the parameters are limited from above and/or below.
Definition: Parameter.h:194
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:1085
void setUnlimited()
Set flag indicating that there are no limits associated with the variable.
Definition: Parameter.h:185
virtual void setDef(InterfacedBase &i) const
set the member variable of ib to its default value.
Definition: Parameter.h:937
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
Neither file nor directory.
Definition: Parameter.h:797
Type theMax
Maximum value to be used if no corresponding member function pointer is given.
Definition: Parameter.h:752
void file(FileType t)
Indicate if this parameter corresponds to a file or directory.
Definition: Parameter.h:863
Type T::* Member
Declaration of a direct pointer to the member variable.
Definition: Parameter.h:436
string theDef
Default, minimum and maximum values to be used if no corresponding member function pointers are given...
Definition: Parameter.h:1080
static string stripws(string str)
Return the string str stripped from leading and trailing white space.
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:539
string T::* Member
Declaration of a direct pointer to the member variable.
Definition: Parameter.h:981
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:767
Type theDef
Default value to be used if no corresponding member function pointer is given.
Definition: Parameter.h:740
virtual string maximum(const InterfacedBase &) const
Return the maximum value allowed for the member variable of ib.
Definition: Parameter.h:914
Int2Type< Dimensioned > DimensionT
Typedef for dimensioned types.
Definition: TemplateTools.h:68
ParameterTBase(string newName, string newDescription, string newClassName, const type_info &newTypeInfo, Type newUnit, bool depSafe, bool readonly, int limits)
Standard constructor.
Definition: Parameter.h:248
bool limited() const
True if there the variable is limited from above and below.
Definition: Parameter.h:159
FileType
Enumerated variables to determine of a string parameter corresponds to a file or a directory...
Definition: Parameter.h:796
void setMinFunction(GetFn mf)
Give a pointer to a member function to be used by tminimum().
Definition: Parameter.h:716
The Parameter and its base classes ParameterTBase and ParameterBase defines an interface to a class d...
Definition: Parameter.h:64
string className() const
Return the class name for the class this interface is defined for.
GetFn theGetFn
Pointer to member function to be used by tget().
Definition: Parameter.h:762
virtual void setDef(InterfacedBase &ib) const
set the member variable of ib to its default value.
Definition: Parameter.h:355
void putUnit(ostream &os, Type val) const
Write a number to a stream with the unit specified with unit().
Definition: Parameter.h:384
GetFn theMaxFn
Pointer to member function to be used by tmaximum().
Definition: Parameter.h:777
The parameter is not limited.
Definition: Interface.h:46
virtual void doxygenDescription(ostream &stream) const
Print a description to be included in the Doxygen documentation to the given stream.
virtual string fullDescription(const InterfacedBase &ib) const
Return a complete description of this parameter.
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:371
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:1056
virtual void setDef(InterfacedBase &ib) const =0
Set the member variable of ib to its default value.
virtual string type() const
Return a code for the type of this parameter.
Definition: Parameter.h:842
virtual ~ParameterTBase()
Destructor.
Definition: Parameter.h:837
virtual string doxygenType() const
Return a string describing the type of interface to be included in the Doxygen documentation.
Definition: Parameter.h:945
GetFn theGetFn
Pointer to member function to be used by tget().
Definition: Parameter.h:1090
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:482
Member theMember
The pointer to the member variable.
Definition: Parameter.h:1074
The parameter has only an lower limit.
Definition: Interface.h:49
The parameter corresponds to a file.
Definition: Parameter.h:798
SetFn theSetFn
A pointer to a member function to be used by tset().
Definition: Parameter.h:757
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:701
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:179
void fileType()
Indicate that this parameter corresponds to a file.
Definition: Parameter.h:853
void setMaxFunction(GetFn mf)
Give a pointer to a member function to be used by tmaximum().
Definition: Parameter.h:721
bool lowerLimit() const
True if there the variable is limited from below.
Definition: Parameter.h:171
Int2Type< Standard > StandardT
Typedef for non-dimensioned types.
Definition: TemplateTools.h:71
virtual string def(const InterfacedBase &ib) const
Return the default value for the member variables of ib.
Definition: Parameter.h:923
virtual string minimum(const InterfacedBase &) const
Return the minimum value allowed for the member variable of ib.
Definition: Parameter.h:906
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:364
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:1014
The Parameter and its base classes ParameterTBase and ParameterBase defines an interface to a class d...
Definition: Parameter.h:418
FileType file() const
See if this parameter corresponds to a file or directory.
Definition: Parameter.h:868
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:395
ParameterTBase(string newName, string newDescription, string newClassName, const type_info &newTypeInfo, bool depSafe, bool readonly)
Standard constructor.
Definition: Parameter.h:824
void setSetFunction(SetFn sf)
Give a pointer to a member function to be used by tset().
Definition: Parameter.h:1051
bool upperLimit() const
True if there the variable is limited from abovew.
Definition: Parameter.h:164