thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
ParVector.h
1 // -*- C++ -*-
2 //
3 // ParVector.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_ParVector_H
10 #define ThePEG_ParVector_H
11 // This is the declaration of the ParVector, ParVectorTBase and
12 // ParVectorBase classes.
13 
14 #include "ThePEG/Config/ThePEG.h"
15 #include "InterfaceBase.h"
16 #include "ParVector.fh"
17 #include <limits>
18 
19 namespace ThePEG {
20 
22 namespace {
23  template <typename T>
27  inline void putUnitImpl2(ostream & os, T v, T u, DimensionT) {
28  os << v/u;
29  }
30 
31  template <typename T>
35  inline void putUnitImpl2(ostream & os, T v, T u, StandardT) {
36  if ( u > T() )
37  os << v/u;
38  else
39  os << v;
40  }
41 }
42 
64 
65 public:
66 
68  typedef vector<string> StringVector;
69 
70 public:
71 
98  ParVectorBase(string newName, string newDescription,
99  string newClassName,
100  const type_info & newTypeInfo, int newSize,
101  bool depSafe, bool readonly, int limits)
102  : InterfaceBase(newName, newDescription, newClassName,
103  newTypeInfo, depSafe,
104  readonly), limit(limits), theSize(newSize) {
105  hasDefault = false;
106  }
107 
111  virtual ~ParVectorBase() {}
112 
121  virtual string exec(InterfacedBase &, string action,
122  string arguments) const;
123 
127  virtual string fullDescription(const InterfacedBase & ib) const;
128 
135  virtual void set(InterfacedBase & ib, string val, int i)
136  const = 0;
137 
144  virtual void insert(InterfacedBase & ib, string val, int i)
145  const = 0;
146 
151  virtual void erase(InterfacedBase & ib, int i)
152  const = 0;
153 
157  virtual void clear(InterfacedBase & ib)
158  const = 0;
159 
163  virtual StringVector get(const InterfacedBase & ib) const
164  = 0;
165 
170  virtual string minimum(const InterfacedBase & ib, int i) const
171  = 0;
172 
177  virtual string maximum(const InterfacedBase & ib, int i) const
178  = 0;
179 
184  virtual string def(const InterfacedBase & ib, int i) const
185  = 0;
186 
190  virtual string def() const = 0;
191 
196  virtual void setDef(InterfacedBase & ib, int i) const
197  = 0;
198 
202  bool limited() const { return limit != Interface::nolimits; }
203 
207  bool upperLimit() const {
209  }
210 
214  bool lowerLimit() const {
216  }
217 
223 
229 
234  int size() const { return theSize; }
235 
240  void setSize(int sz) { theSize = sz; }
241 
246  void setVariableSize() { theSize = 0; }
247 
248 private:
249 
254  int limit;
255 
259  int theSize;
260 
261 };
262 
283 template <typename Type>
285 
286 public:
287 
289  typedef vector<Type> TypeVector;
290 
291 public:
292 
322  ParVectorTBase(string newName, string newDescription,
323  string newClassName, const type_info & newTypeInfo,
324  Type newUnit, int newSize, bool depSafe,
325  bool readonly, int limits)
326  : ParVectorBase(newName, newDescription, newClassName,
327  newTypeInfo, newSize,
328  depSafe, readonly, limits), theUnit(newUnit) {}
329 
330 
334  virtual ~ParVectorTBase() {}
335 
339  virtual string type() const;
340 
345  virtual string doxygenType() const;
346 
350  virtual string fullDescription(const InterfacedBase & ib) const;
351 
357  virtual void set(InterfacedBase & ib, string val, int i) const
358  ;
359 
364  virtual void tset(InterfacedBase & ib, Type val, int i)
365  const = 0;
366 
373  virtual void insert(InterfacedBase & ib, string val, int i) const
374  ;
375 
376 private:
378  void setImpl(InterfacedBase & ib, string val, int i, StandardT)
379  const;
380 
382  void setImpl(InterfacedBase & ib, string val, int i, DimensionT)
383  const;
384 
386  void insertImpl(InterfacedBase & ib, string val, int i, StandardT)
387  const;
388 
390  void insertImpl(InterfacedBase & ib, string val, int i, DimensionT)
391  const;
392 
393 public:
394 
399  virtual void tinsert(InterfacedBase & ib, Type val, int i)
400  const = 0;
401 
407  virtual StringVector get(const InterfacedBase & ib) const
408  ;
409 
414  virtual TypeVector tget(const InterfacedBase & ib) const
415  = 0;
416 
424  virtual string minimum(const InterfacedBase & ib, int i) const
425  ;
426 
431  virtual Type tminimum(const InterfacedBase & ib, int i) const
432  = 0;
433 
440  virtual string maximum(const InterfacedBase & ib, int i) const
441  ;
442 
447  virtual Type tmaximum(const InterfacedBase & ib, int i) const
448  = 0;
449 
455  virtual string def(const InterfacedBase & ib, int i) const
456  ;
457 
462  virtual Type tdef(const InterfacedBase & ib, int i) const
463  = 0;
464 
469  virtual string def() const;
470 
474  virtual Type tdef() const = 0;
475 
480  virtual void setDef(InterfacedBase & ib, int i) const
481  ;
482 
488  Type unit() const { return theUnit; }
489 
495  void unit(Type u) { theUnit = u; }
496 
497 protected:
498 
502  void putUnit(ostream & os, Type val) const {
503  putUnitImpl2(os, val, unit(), typename TypeTraits<Type>::DimType());
504  }
505 
506 private:
507 
513  Type theUnit;
514 
515 };
516 
537 template <typename T, typename Type>
538 class ParVector: public ParVectorTBase<Type> {
539 
540 public:
541 
546  typedef void (T::*SetFn)(Type, int);
547 
552  typedef void (T::*InsFn)(Type, int);
553 
558  typedef void (T::*DelFn)(int);
559 
563  typedef vector<Type> TypeVector;
564 
569  typedef TypeVector (T::*GetFn)() const;
570 
574  typedef vector<string> StringVector;
575 
580  typedef StringVector (T::*StringGetFn)() const;
581 
586  typedef Type (T::*DefFn)(int) const;
587 
592  typedef TypeVector T::* Member;
593 
594 public:
595 
650  ParVector(string newName, string newDescription,
651  Member newMember, int newSize, Type newDef, Type newMin,
652  Type newMax, bool depSafe = false, bool readonly = false,
653  bool limits = true, SetFn newSetFn = 0,
654  InsFn newInsFn = 0, DelFn newDelFn = 0, GetFn newGetFn = 0,
655  DefFn newDefFn = 0, DefFn newMinFn = 0, DefFn newMaxFn = 0,
656  StringGetFn newStringGetFn = 0)
657  : ParVectorTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
658  typeid(T), Type(), newSize, depSafe, readonly,
659  limits),
660  theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
661  theSetFn(newSetFn), theInsFn(newInsFn), theDelFn(newDelFn),
662  theGetFn(newGetFn), theDefFn(newDefFn), theMinFn(newMinFn),
663  theMaxFn(newMaxFn), theStringGetFn(newStringGetFn) {}
664 
665 
723  ParVector(string newName, string newDescription, Member newMember,
724  Type newUnit, int newSize, Type newDef, Type newMin,
725  Type newMax, bool depSafe = false, bool readonly = false,
726  bool limits = true, SetFn newSetFn = 0,
727  InsFn newInsFn = 0, DelFn newDelFn = 0, GetFn newGetFn = 0,
728  DefFn newDefFn = 0, DefFn newMinFn = 0, DefFn newMaxFn = 0,
729  StringGetFn newStringGetFn = 0)
730  : ParVectorTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
731  typeid(T), newUnit, newSize, depSafe, readonly,
732  limits),
733  theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
734  theSetFn(newSetFn), theInsFn(newInsFn), theDelFn(newDelFn),
735  theGetFn(newGetFn), theDefFn(newDefFn), theMinFn(newMinFn),
736  theMaxFn(newMaxFn), theStringGetFn(newStringGetFn) {}
737 
793  ParVector(string newName, string newDescription,
794  Member newMember, int newSize, Type newDef, Type newMin,
795  Type newMax, bool depSafe = false, bool readonly = false,
796  int limits = Interface::limited, SetFn newSetFn = 0,
797  InsFn newInsFn = 0, DelFn newDelFn = 0, GetFn newGetFn = 0,
798  DefFn newDefFn = 0, DefFn newMinFn = 0, DefFn newMaxFn = 0,
799  StringGetFn newStringGetFn = 0)
800  : ParVectorTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
801  typeid(T), Type(), newSize, depSafe, readonly,
802  limits),
803  theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
804  theSetFn(newSetFn), theInsFn(newInsFn), theDelFn(newDelFn),
805  theGetFn(newGetFn), theDefFn(newDefFn), theMinFn(newMinFn),
806  theMaxFn(newMaxFn), theStringGetFn(newStringGetFn) {}
807 
866  ParVector(string newName, string newDescription, Member newMember,
867  Type newUnit, int newSize, Type newDef, Type newMin,
868  Type newMax, bool depSafe = false, bool readonly = false,
869  int limits = Interface::limited, SetFn newSetFn = 0,
870  InsFn newInsFn = 0, DelFn newDelFn = 0, GetFn newGetFn = 0,
871  DefFn newDefFn = 0, DefFn newMinFn = 0, DefFn newMaxFn = 0,
872  StringGetFn newStringGetFn = 0)
873  : ParVectorTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
874  typeid(T), newUnit, newSize, depSafe, readonly,
875  limits),
876  theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
877  theSetFn(newSetFn), theInsFn(newInsFn), theDelFn(newDelFn),
878  theGetFn(newGetFn), theDefFn(newDefFn), theMinFn(newMinFn),
879  theMaxFn(newMaxFn), theStringGetFn(newStringGetFn) {}
880 
885  virtual void tset(InterfacedBase & ib, Type val, int i) const
886  ;
887 
892  virtual void tinsert(InterfacedBase & ib, Type val, int i) const
893  ;
894 
899  virtual void erase(InterfacedBase & ib, int i)
900  const;
901 
905  virtual void clear(InterfacedBase & ib)
906  const;
907 
913  virtual StringVector get(const InterfacedBase & ib) const
914  ;
915 
920  virtual TypeVector tget(const InterfacedBase & ib) const
921  ;
922 
927  virtual Type tminimum(const InterfacedBase & ib, int i) const
928  ;
929 
934  virtual Type tmaximum(const InterfacedBase & ib, int i) const
935  ;
936 
941  virtual Type tdef(const InterfacedBase &, int) const
942  ;
943 
947  virtual Type tdef() const;
948 
952  void setSetFunction(SetFn sf) { theSetFn = sf; }
953 
957  void setInsertFunction(InsFn ifn) { theInsFn = ifn; }
958 
962  void setGetFunction(GetFn gf) { theGetFn = gf; }
963 
967  void setEraseFunction(DelFn df) { theDelFn = df; }
968 
972  void setDefaultFunction(GetFn df) { theDefFn = df; }
973 
977  void setMinFunction(GetFn mf) { theMinFn = mf; }
978 
982  void setMaxFunction(GetFn mf) { theMaxFn = mf; }
983 
987  void setStringGetFunction(StringGetFn gf) { theStringGetFn = gf; }
988 
993  virtual void doxygenDescription(ostream & stream) const;
994 
995 private:
996 
1001 
1006  Type theDef;
1007 
1012  Type theMin;
1013 
1018  Type theMax;
1019 
1023  SetFn theSetFn;
1024 
1028  InsFn theInsFn;
1029 
1033  DelFn theDelFn;
1034 
1038  GetFn theGetFn;
1039 
1043  DefFn theDefFn;
1044 
1048  DefFn theMinFn;
1049 
1053  DefFn theMaxFn;
1054 
1058  StringGetFn theStringGetFn;
1059 
1060 };
1061 
1062 }
1063 
1064 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
1065 #include "ParVector.tcc"
1066 #endif
1067 
1068 #endif /* ThePEG_ParVector_H */
DelFn theDelFn
A pointer to a member function to be used by terase().
Definition: ParVector.h:1033
vector< string > StringVector
A vector of strings.
Definition: ParVector.h:574
Type theUnit
The unit which an Type object is divided (multiplied) by when written to (read from) a stream via a d...
Definition: ParVector.h:513
vector< string > StringVector
A vector of strings.
Definition: ParVector.h:68
void unit(Type u)
Set the unit which an Type object is divided (multiplied) by when written to (read from) a stream via...
Definition: ParVector.h:495
virtual string maximum(const InterfacedBase &ib, int i) const =0
Return the maximum value allowed for the i&#39;th element of a container of member variables of ib...
StringGetFn theStringGetFn
A pointer to a member function to be used by set().
Definition: ParVector.h:1058
virtual string doxygenType() const =0
Return a string describing the type of interface to be included in the Doxygen documentation.
virtual ~ParVectorBase()
Destructor.
Definition: ParVector.h:111
The ParVector and its base classes ParVectorTBase and ParVectorBase defines an interface to a class d...
Definition: ParVector.h:63
Type unit() const
Get the unit which an Type object is divided (multiplied) by when written to (read from) a stream via...
Definition: ParVector.h:488
Type theMax
Maximum value to be used if no corresponding member function pointer is given.
Definition: ParVector.h:1018
virtual string type() const =0
Return a code for the type of this interface.
The InterfaceBase class defines a generic interface to any class derived from the InterfacedBase clas...
Definition: InterfaceBase.h:59
int limit
True if there are limits associated with the variables.
Definition: ParVector.h:254
virtual void setDef(InterfacedBase &ib, int i) const =0
Set the i&#39;th element of a container of member variables of ib to its default value.
virtual string fullDescription(const InterfacedBase &ib) const
Return a complete description of this parameter vector.
bool hasDefault
A flag indicating whether this interface has a default setting.
virtual void insert(InterfacedBase &ib, string val, int i) const =0
Insert a new object before the i&#39;th element of a container of member variables of ib and set it to va...
Conversion between integers and types.
Definition: TemplateTools.h:23
void setMaxFunction(GetFn mf)
Give a pointer to a member function to be used by tmaximum().
Definition: ParVector.h:982
void setLimited()
Set a flag indicating that there are limits associated with the variables.
Definition: ParVector.h:222
int size() const
Get the size of the container being interfaced.
Definition: ParVector.h:234
DefFn theDefFn
Pointer to member function to be used by tdef().
Definition: ParVector.h:1043
void setInsertFunction(InsFn ifn)
Give a pointer to a member function to be used by tinsert().
Definition: ParVector.h:957
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
bool lowerLimit() const
True if there the variable is limited from below.
Definition: ParVector.h:214
Type theMin
Minimum value to be used if no corresponding member function pointer is given.
Definition: ParVector.h:1012
This is the main config header file for ThePEG.
The ParVector and its base classes ParVectorTBase and ParVectorBase defines an interface to a class d...
Definition: ParVector.h:538
InsFn theInsFn
A pointer to a member function to be used by tinsert().
Definition: ParVector.h:1028
virtual void doxygenDescription(ostream &stream) const
Print a description to be included in the Doxygen documentation to the given stream.
int theSize
The size of the container being interfaced.
Definition: ParVector.h:259
virtual void clear(InterfacedBase &ib) const =0
Clear the container of pointers of ib.
Int2Type< Dimensioned > DimensionT
Typedef for dimensioned types.
Definition: TemplateTools.h:37
void setMinFunction(GetFn mf)
Give a pointer to a member function to be used by tminimum().
Definition: ParVector.h:977
virtual ~ParVectorTBase()
Destructor.
Definition: ParVector.h:334
ParVectorBase(string newName, string newDescription, string newClassName, const type_info &newTypeInfo, int newSize, bool depSafe, bool readonly, int limits)
Standard constructor.
Definition: ParVector.h:98
void setSetFunction(SetFn sf)
Give a pointer to a member function to be used by tset().
Definition: ParVector.h:952
Type theDef
Default value to be used if no corresponding member function pointer is given.
Definition: ParVector.h:1006
TypeVector T::* Member
Declaration of a direct pointer to the member variable in case it is a vector.
Definition: ParVector.h:592
bool limited() const
True if there the variable is limited from above and below.
Definition: ParVector.h:202
void putUnit(ostream &os, Type val) const
Write a numer to a stream with the unit specified with unit().
Definition: ParVector.h:502
vector< Type > TypeVector
A vector of objects of the template parameter Type.
Definition: ParVector.h:563
The parameter is not limited.
Definition: Interface.h:46
void setStringGetFunction(StringGetFn gf)
Give a pointer to a member function to be used by get().
Definition: ParVector.h:987
virtual string minimum(const InterfacedBase &ib, int i) const =0
Return the minimum value allowed for the i&#39;th element of a container of member variables of ib...
Member theMember
The pointer to the member variable.
Definition: ParVector.h:1000
virtual string exec(InterfacedBase &, string action, string arguments) const
The general interface method overriding the one in InterfaceBase.
InterfacedBase is the base class of all Interfaced objects to be handled by the BaseRepository class...
ParVector(string newName, string newDescription, Member newMember, Type newUnit, int newSize, Type newDef, Type newMin, Type newMax, bool depSafe=false, bool readonly=false, bool limits=true, SetFn newSetFn=0, InsFn newInsFn=0, DelFn newDelFn=0, GetFn newGetFn=0, DefFn newDefFn=0, DefFn newMinFn=0, DefFn newMaxFn=0, StringGetFn newStringGetFn=0)
Standard constructor.
Definition: ParVector.h:723
vector< Type > TypeVector
A vector of objects of the template argument type.
Definition: ParVector.h:289
void setEraseFunction(DelFn df)
Give a pointer to a member function to be used by terase().
Definition: ParVector.h:967
ParVector(string newName, string newDescription, Member newMember, int newSize, Type newDef, Type newMin, Type newMax, bool depSafe=false, bool readonly=false, bool limits=true, SetFn newSetFn=0, InsFn newInsFn=0, DelFn newDelFn=0, GetFn newGetFn=0, DefFn newDefFn=0, DefFn newMinFn=0, DefFn newMaxFn=0, StringGetFn newStringGetFn=0)
Standard constructor.
Definition: ParVector.h:650
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
The parameter has only an lower limit.
Definition: Interface.h:49
GetFn theGetFn
A pointer to a member function to be used by tget().
Definition: ParVector.h:1038
The default concrete implementation of ClassTraitsBase.
Definition: ClassTraits.h:134
ParVectorTBase(string newName, string newDescription, string newClassName, const type_info &newTypeInfo, Type newUnit, int newSize, bool depSafe, bool readonly, int limits)
Standard constructor.
Definition: ParVector.h:322
The parameter is limited (both up- and downwards.
Definition: Interface.h:47
void setDefaultFunction(GetFn df)
Give a pointer to a member function to be used by tdef().
Definition: ParVector.h:972
ParVector(string newName, string newDescription, Member newMember, Type newUnit, int newSize, Type newDef, Type newMin, Type newMax, bool depSafe=false, bool readonly=false, int limits=Interface::limited, SetFn newSetFn=0, InsFn newInsFn=0, DelFn newDelFn=0, GetFn newGetFn=0, DefFn newDefFn=0, DefFn newMinFn=0, DefFn newMaxFn=0, StringGetFn newStringGetFn=0)
Standard constructor.
Definition: ParVector.h:866
Int2Type< Standard > StandardT
Typedef for non-dimensioned types.
Definition: TemplateTools.h:40
SetFn theSetFn
A pointer to a member function to be used by tset().
Definition: ParVector.h:1023
DefFn theMinFn
Pointer to member function to be used by tminimum().
Definition: ParVector.h:1048
ParVector(string newName, string newDescription, Member newMember, int newSize, Type newDef, Type newMin, Type newMax, bool depSafe=false, bool readonly=false, int limits=Interface::limited, SetFn newSetFn=0, InsFn newInsFn=0, DelFn newDelFn=0, GetFn newGetFn=0, DefFn newDefFn=0, DefFn newMinFn=0, DefFn newMaxFn=0, StringGetFn newStringGetFn=0)
Standard constructor.
Definition: ParVector.h:793
void setSize(int sz)
Set the size of the container being interfaced.
Definition: ParVector.h:240
void setGetFunction(GetFn gf)
Give a pointer to a member function to be used by tget().
Definition: ParVector.h:962
DefFn theMaxFn
Pointer to member function to be used by tmaximum().
Definition: ParVector.h:1053
void setUnlimited()
Set a flag indicating if there are no limits associated with the variables.
Definition: ParVector.h:228
The ParVector and its base classes ParVectorTBase and ParVectorBase defines an interface to a class d...
Definition: ParVector.h:284
void setVariableSize()
Set the size of the container being interfaced to -1, i.e.
Definition: ParVector.h:246
virtual void erase(InterfacedBase &ib, int i) const =0
Remove the i&#39;th element of a container of member variables of ib.
virtual string def() const =0
Return the general default value for this parameter vector.
bool upperLimit() const
True if there the variable is limited from abovew.
Definition: ParVector.h:207