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 
758 
763 
768 
773 
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 
1086 
1091 
1096 
1097 };
1098 
1099 }
1100 
1101 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
1102 #include "Parameter.tcc"
1103 #endif
1104 
1105 #endif /* ThePEG_Parameter_H */