thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.1.5
Parameter.h
1 // -*- C++ -*-
2 //
3 // Parameter.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2017 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 
66 
67 public:
68 
93  ParameterBase(string newName, string newDescription,
94  string newClassName,
95  const type_info & newTypeInfo, bool depSafe,
96  bool readonly, int limits)
97  : InterfaceBase(newName, newDescription,
98  newClassName, newTypeInfo, depSafe,
99  readonly), limit(limits) {}
100 
104  virtual ~ParameterBase();
105 
113  virtual string exec(InterfacedBase & ib, string action,
114  string arguments) const;
115 
119  virtual string fullDescription(const InterfacedBase & ib) const;
120 
124  virtual void set(InterfacedBase & ib, string) const
125  = 0;
126 
130  virtual string minimum(const InterfacedBase & ib) const
131  = 0;
132 
136  virtual string maximum(const InterfacedBase & ib) const
137  = 0;
138 
142  virtual string get(const InterfacedBase & ib) const
143  = 0;
144 
148  virtual string def(const InterfacedBase & ib) const
149  = 0;
150 
154  virtual void setDef(InterfacedBase & ib) const
155  = 0;
156 
160  bool limited() const { return limit != Interface::nolimits; }
161 
165  bool upperLimit() const {
167  }
168 
172  bool lowerLimit() const {
174  }
175 
181 
187 
188 private:
189 
195  int limit;
196 
197 };
198 
217 template <typename Type>
219 
220 public:
221 
249  ParameterTBase(string newName, string newDescription,
250  string newClassName,
251  const type_info & newTypeInfo, Type newUnit,
252  bool depSafe, bool readonly, int limits)
253  : ParameterBase(newName, newDescription,
254  newClassName, newTypeInfo, depSafe,
255  readonly, limits), theUnit(newUnit) {}
256 
260  virtual ~ParameterTBase() {}
261 
265  virtual string type() const;
266 
267 private:
268 
270  void setImpl (InterfacedBase & i,
271  string newValue, StandardT)
272  const;
273 
275  void setImpl (InterfacedBase & i,
276  string newValue, DimensionT)
277  const;
278 
279 public:
280 
286  virtual void set(InterfacedBase & ib, string newValue)
287  const;
288 
292  virtual void tset(InterfacedBase & ib, Type) const
293  = 0;
294 
300  virtual string get(const InterfacedBase & ib) const
301  ;
302 
306  virtual Type tget(const InterfacedBase & ib) const
307  = 0;
308 
314  virtual string minimum(const InterfacedBase & ib) const
315  ;
316 
321  virtual Type tminimum(const InterfacedBase & ib) const
322  = 0;
323 
329  virtual string maximum(const InterfacedBase & ib) const
330  ;
331 
336  virtual Type tmaximum(const InterfacedBase & ib) const
337  = 0;
338 
344  virtual string def(const InterfacedBase & ib) const
345  ;
346 
350  virtual Type tdef(const InterfacedBase &ib) const
351  = 0;
352 
356  virtual void setDef(InterfacedBase & ib) const {
357  tset(ib, tdef(ib));
358  }
359 
365  Type unit() const { return theUnit; }
366 
372  void unit(Type u) { theUnit = u; }
373 
378  virtual string doxygenType() const;
379 
380 protected:
381 
385  void putUnit(ostream & os, Type val) const {
386  putUnitImpl(os, val, unit(), typename TypeTraits<Type>::DimType());
387  }
388 
389 private:
390 
396  Type theUnit;
397 
401  void checkUnitConsistency(string suffix) const;
402 
403 };
404 
423 template <typename T, typename Type>
424 class Parameter: public ParameterTBase<Type> {
425 
426 public:
427 
432  typedef void (T::*SetFn)(Type);
437  typedef Type (T::*GetFn)() const;
438 
442  typedef Type T::* Member;
443 
444 public:
445 
488  Parameter(string newName, string newDescription,
489  Member newMember, Type newDef, Type newMin,
490  Type newMax, bool depSafe = false, bool readonly = false,
491  bool limits = true, SetFn newSetFn = 0,
492  GetFn newGetFn = 0, GetFn newMinFn = 0,
493  GetFn newMaxFn = 0, GetFn newDefFn = 0)
494  : ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
495  typeid(T), Type(), depSafe, readonly, limits),
496  theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
497  theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
498  theMinFn(newMinFn), theMaxFn(newMaxFn) {}
499 
545  Parameter(string newName, string newDescription,
546  Member newMember, Type newUnit, Type newDef, Type newMin,
547  Type newMax, bool depSafe = false, bool readonly = false,
548  bool limits = true, SetFn newSetFn = 0,
549  GetFn newGetFn = 0, GetFn newMinFn = 0,
550  GetFn newMaxFn = 0, GetFn newDefFn = 0)
551  : ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
552  typeid(T), newUnit, depSafe, readonly, limits),
553  theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
554  theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
555  theMinFn(newMinFn), theMaxFn(newMaxFn) {}
556 
600  Parameter(string newName, string newDescription,
601  Member newMember, Type newDef, Type newMin,
602  Type newMax, bool depSafe = false, bool readonly = false,
603  int limits = Interface::limited, SetFn newSetFn = 0,
604  GetFn newGetFn = 0, GetFn newMinFn = 0,
605  GetFn newMaxFn = 0, GetFn newDefFn = 0)
606  : ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
607  typeid(T), Type(), depSafe, readonly, limits),
608  theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
609  theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
610  theMinFn(newMinFn), theMaxFn(newMaxFn) {}
611 
658  Parameter(string newName, string newDescription,
659  Member newMember, Type newUnit, Type newDef, Type newMin,
660  Type newMax, bool depSafe = false, bool readonly = false,
661  int limits = Interface::limited, SetFn newSetFn = 0,
662  GetFn newGetFn = 0, GetFn newMinFn = 0,
663  GetFn newMaxFn = 0, GetFn newDefFn = 0)
664  : ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
665  typeid(T), newUnit, depSafe, readonly, limits),
666  theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
667  theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
668  theMinFn(newMinFn), theMaxFn(newMaxFn) {}
669 
673  virtual ~Parameter() {}
674 
678  virtual void tset(InterfacedBase & ib, Type val)
679  const;
680 
684  virtual Type tget(const InterfacedBase & ib) const;
685 
689  virtual Type tminimum(const InterfacedBase & ib) const
690  ;
691 
695  virtual Type tmaximum(const InterfacedBase & ib) const
696  ;
697 
701  virtual Type tdef(const InterfacedBase & ib) const
702  ;
703 
707  void setSetFunction(SetFn sf) { theSetFn = sf; }
708 
712  void setGetFunction(GetFn gf) { theGetFn = gf; }
713 
717  void setDefaultFunction(GetFn df) { theDefFn = df; }
718 
722  void setMinFunction(GetFn mf) { theMinFn = mf; }
723 
727  void setMaxFunction(GetFn mf) { theMaxFn = mf; }
728 
733  virtual void doxygenDescription(ostream & stream) const;
734 
735 private:
736 
741 
746  Type theDef;
747 
752  Type theMin;
753 
758  Type theMax;
759 
763  SetFn theSetFn;
764 
768  GetFn theGetFn;
769 
773  GetFn theDefFn;
774 
778  GetFn theMinFn;
779 
783  GetFn theMaxFn;
784 
785 };
786 
793 template <>
794 class ParameterTBase<string>: public ParameterBase {
795 
796 public:
797 
802  enum FileType {
805  Directory
806  };
807 
808 public:
809 
830  ParameterTBase(string newName, string newDescription,
831  string newClassName,
832  const type_info & newTypeInfo,
833  bool depSafe, bool readonly)
834  : ParameterBase(newName, newDescription,
835  newClassName, newTypeInfo, depSafe,
836  readonly, false), isFileType(NoFile) {
837  hasDefault = false;
838  }
839 
843  virtual ~ParameterTBase() {}
844 
848  virtual string type() const {
849  switch ( file() ) {
850  case File: return "PF";
851  case Directory: return "PD";
852  default: return "Ps";
853  }
854  }
855 
859  void fileType() { file(File); }
860 
864  void directoryType() { file(Directory); }
865 
869  void file(FileType t) { isFileType = t; }
870 
874  FileType file() const { return isFileType; }
875 
881  virtual void set(InterfacedBase & ib, string newValue)
882  const {
883  tset(ib, StringUtils::stripws(newValue));
884  }
885 
889  virtual void tset(InterfacedBase & ib, string) const
890  = 0;
891 
897  virtual string get(const InterfacedBase & ib) const
898  {
899  return tget(ib);
900  }
901 
905  virtual string tget(const InterfacedBase & ib) const
906  = 0;
907 
912  virtual string minimum(const InterfacedBase &) const {
913  return "";
914  }
915 
920  virtual string maximum(const InterfacedBase &) const {
921  return "";
922  }
923 
929  virtual string def(const InterfacedBase & ib) const
930  {
931  return tdef(ib);
932  }
933 
937  virtual string tdef(const InterfacedBase &ib) const
938  = 0;
939 
943  virtual void setDef(InterfacedBase & i) const {
944  tset(i, tdef(i));
945  }
946 
951  virtual string doxygenType() const { return "Character string parameter"; }
952 
953 private:
954 
959 
960 };
961 
968 template <typename T>
969 class Parameter<T,string>: public ParameterTBase<string> {
970 
971 public:
972 
977  typedef void (T::*SetFn)(string);
982  typedef string (T::*GetFn)() const;
983 
987  typedef string T::* Member;
988 
989 public:
990 
1020  Parameter(string newName, string newDescription,
1021  Member newMember, string newDef,
1022  bool depSafe = false, bool readonly = false,
1023  SetFn newSetFn = 0, GetFn newGetFn = 0, GetFn newDefFn = 0)
1024  : ParameterTBase<string>(newName, newDescription,
1025  ClassTraits<T>::className(),
1026  typeid(T), depSafe, readonly),
1027  theMember(newMember), theDef(newDef),
1028  theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn) {}
1029 
1030 
1034  virtual ~Parameter() {}
1035 
1039  virtual void tset(InterfacedBase & ib, string val)
1040  const;
1041 
1045  virtual string tget(const InterfacedBase & ib) const
1046  ;
1047 
1051  virtual string tdef(const InterfacedBase & ib) const
1052  ;
1053 
1057  void setSetFunction(SetFn sf) { theSetFn = sf; }
1058 
1062  void setGetFunction(GetFn gf) { theGetFn = gf; }
1063 
1067  void setDefaultFunction(GetFn df) { theDefFn = df; }
1068 
1073  virtual void doxygenDescription(ostream & stream) const;
1074 
1075 private:
1076 
1081 
1086  string theDef;
1087 
1091  SetFn theSetFn;
1092 
1096  GetFn theGetFn;
1097 
1101  GetFn theDefFn;
1102 
1103 };
1104 
1105 }
1106 
1107 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
1108 #include "Parameter.tcc"
1109 #endif
1110 
1111 #endif /* ThePEG_Parameter_H */
virtual string maximum(const InterfacedBase &) const
Return the maximum value allowed for the member variable of ib.
Definition: Parameter.h:920
void putUnit(ostream &os, Type val) const
Write a number to a stream with the unit specified with unit().
Definition: Parameter.h:385
Member theMember
The pointer to the member variable.
Definition: Parameter.h:740
GetFn theMinFn
Pointer to member function to be used by tminimum().
Definition: Parameter.h:778
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:600
The Parameter and its base classes ParameterTBase and ParameterBase defines an interface to a class d...
Definition: Parameter.h:218
virtual string minimum(const InterfacedBase &) const
Return the minimum value allowed for the member variable of ib.
Definition: Parameter.h:912
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:864
void setGetFunction(GetFn gf)
Give a pointer to a member function to be used by tget().
Definition: Parameter.h:712
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:260
bool lowerLimit() const
True if there the variable is limited from below.
Definition: Parameter.h:172
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:658
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:1067
virtual ~Parameter()
Default dtor.
Definition: Parameter.h:673
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:1101
void setDefaultFunction(GetFn df)
Give a pointer to a member function to be used by tdef().
Definition: Parameter.h:717
ParameterBase(string newName, string newDescription, string newClassName, const type_info &newTypeInfo, bool depSafe, bool readonly, int limits)
Standard constructor.
Definition: Parameter.h:93
FileType isFileType
Indicates if this parameter corresponds to a file or directory.
Definition: Parameter.h:958
Conversion between integers and types.
Definition: TemplateTools.h:23
virtual ~Parameter()
Default dtor.
Definition: Parameter.h:1034
Type theMin
Minimum value to be used if no corresponding member function pointer is given.
Definition: Parameter.h:752
int limit
Determines if the values of the parameters are limited from above and/or below.
Definition: Parameter.h:195
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:1091
void setUnlimited()
Set flag indicating that there are no limits associated with the variable.
Definition: Parameter.h:186
bool limited() const
True if there the variable is limited from above and below.
Definition: Parameter.h:160
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
Neither file nor directory.
Definition: Parameter.h:803
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:758
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:869
Type T::* Member
Declaration of a direct pointer to the member variable.
Definition: Parameter.h:442
string theDef
Default, minimum and maximum values to be used if no corresponding member function pointers are given...
Definition: Parameter.h:1086
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:545
virtual string type() const
Return a code for the type of this parameter.
Definition: Parameter.h:848
virtual void setDef(InterfacedBase &i) const
set the member variable of ib to its default value.
Definition: Parameter.h:943
string T::* Member
Declaration of a direct pointer to the member variable.
Definition: Parameter.h:987
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:773
Type theDef
Default value to be used if no corresponding member function pointer is given.
Definition: Parameter.h:746
Int2Type< Dimensioned > DimensionT
Typedef for dimensioned types.
Definition: TemplateTools.h:70
ParameterTBase(string newName, string newDescription, string newClassName, const type_info &newTypeInfo, Type newUnit, bool depSafe, bool readonly, int limits)
Standard constructor.
Definition: Parameter.h:249
FileType file() const
See if this parameter corresponds to a file or directory.
Definition: Parameter.h:874
FileType
Enumerated variables to determine of a string parameter corresponds to a file or a directory...
Definition: Parameter.h:802
void setMinFunction(GetFn mf)
Give a pointer to a member function to be used by tminimum().
Definition: Parameter.h:722
The Parameter and its base classes ParameterTBase and ParameterBase defines an interface to a class d...
Definition: Parameter.h:65
GetFn theGetFn
Pointer to member function to be used by tget().
Definition: Parameter.h:768
GetFn theMaxFn
Pointer to member function to be used by tmaximum().
Definition: Parameter.h:783
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:372
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:1062
virtual void setDef(InterfacedBase &ib) const =0
Set the member variable of ib to its default value.
virtual ~ParameterTBase()
Destructor.
Definition: Parameter.h:843
GetFn theGetFn
Pointer to member function to be used by tget().
Definition: Parameter.h:1096
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:488
Member theMember
The pointer to the member variable.
Definition: Parameter.h:1080
The parameter has only an lower limit.
Definition: Interface.h:49
The parameter corresponds to a file.
Definition: Parameter.h:804
SetFn theSetFn
A pointer to a member function to be used by tset().
Definition: Parameter.h:763
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:707
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:180
void fileType()
Indicate that this parameter corresponds to a file.
Definition: Parameter.h:859
void setMaxFunction(GetFn mf)
Give a pointer to a member function to be used by tmaximum().
Definition: Parameter.h:727
bool upperLimit() const
True if there the variable is limited from abovew.
Definition: Parameter.h:165
Int2Type< Standard > StandardT
Typedef for non-dimensioned types.
Definition: TemplateTools.h:73
virtual void setDef(InterfacedBase &ib) const
set the member variable of ib to its default value.
Definition: Parameter.h:356
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:365
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:1020
The Parameter and its base classes ParameterTBase and ParameterBase defines an interface to a class d...
Definition: Parameter.h:424
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:396
virtual string def(const InterfacedBase &ib) const
Return the default value for the member variables of ib.
Definition: Parameter.h:929
ParameterTBase(string newName, string newDescription, string newClassName, const type_info &newTypeInfo, bool depSafe, bool readonly)
Standard constructor.
Definition: Parameter.h:830
void setSetFunction(SetFn sf)
Give a pointer to a member function to be used by tset().
Definition: Parameter.h:1057
virtual string doxygenType() const
Return a string describing the type of interface to be included in the Doxygen documentation.
Definition: Parameter.h:951