ThePEG  1.8.0
ParVector.h
1 // -*- C++ -*-
2 //
3 // ParVector.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_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 StringVector get(const InterfacedBase & ib) const
158  = 0;
159 
164  virtual string minimum(const InterfacedBase & ib, int i) const
165  = 0;
166 
171  virtual string maximum(const InterfacedBase & ib, int i) const
172  = 0;
173 
178  virtual string def(const InterfacedBase & ib, int i) const
179  = 0;
180 
184  virtual string def() const = 0;
185 
190  virtual void setDef(InterfacedBase & ib, int i) const
191  = 0;
192 
196  bool limited() const { return limit != Interface::nolimits; }
197 
201  bool upperLimit() const {
203  }
204 
208  bool lowerLimit() const {
210  }
211 
217 
223 
228  int size() const { return theSize; }
229 
234  void setSize(int sz) { theSize = sz; }
235 
240  void setVariableSize() { theSize = 0; }
241 
242 private:
243 
248  int limit;
249 
253  int theSize;
254 
255 };
256 
277 template <typename Type>
279 
280 public:
281 
283  typedef vector<Type> TypeVector;
284 
285 public:
286 
316  ParVectorTBase(string newName, string newDescription,
317  string newClassName, const type_info & newTypeInfo,
318  Type newUnit, int newSize, bool depSafe,
319  bool readonly, int limits)
320  : ParVectorBase(newName, newDescription, newClassName,
321  newTypeInfo, newSize,
322  depSafe, readonly, limits), theUnit(newUnit) {}
323 
324 
328  virtual ~ParVectorTBase() {}
329 
333  virtual string type() const;
334 
339  virtual string doxygenType() const;
340 
344  virtual string fullDescription(const InterfacedBase & ib) const;
345 
351  virtual void set(InterfacedBase & ib, string val, int i) const
352  ;
353 
358  virtual void tset(InterfacedBase & ib, Type val, int i)
359  const = 0;
360 
367  virtual void insert(InterfacedBase & ib, string val, int i) const
368  ;
369 
370 private:
372  void setImpl(InterfacedBase & ib, string val, int i, StandardT)
373  const;
374 
376  void setImpl(InterfacedBase & ib, string val, int i, DimensionT)
377  const;
378 
380  void insertImpl(InterfacedBase & ib, string val, int i, StandardT)
381  const;
382 
384  void insertImpl(InterfacedBase & ib, string val, int i, DimensionT)
385  const;
386 
387 public:
388 
393  virtual void tinsert(InterfacedBase & ib, Type val, int i)
394  const = 0;
395 
401  virtual StringVector get(const InterfacedBase & ib) const
402  ;
403 
408  virtual TypeVector tget(const InterfacedBase & ib) const
409  = 0;
410 
418  virtual string minimum(const InterfacedBase & ib, int i) const
419  ;
420 
425  virtual Type tminimum(const InterfacedBase & ib, int i) const
426  = 0;
427 
434  virtual string maximum(const InterfacedBase & ib, int i) const
435  ;
436 
441  virtual Type tmaximum(const InterfacedBase & ib, int i) const
442  = 0;
443 
449  virtual string def(const InterfacedBase & ib, int i) const
450  ;
451 
456  virtual Type tdef(const InterfacedBase & ib, int i) const
457  = 0;
458 
463  virtual string def() const;
464 
468  virtual Type tdef() const = 0;
469 
474  virtual void setDef(InterfacedBase & ib, int i) const
475  ;
476 
482  Type unit() const { return theUnit; }
483 
489  void unit(Type u) { theUnit = u; }
490 
491 protected:
492 
496  void putUnit(ostream & os, Type val) const {
497  putUnitImpl2(os, val, unit(), typename TypeTraits<Type>::DimType());
498  }
499 
500 private:
501 
507  Type theUnit;
508 
509 };
510 
531 template <typename T, typename Type>
532 class ParVector: public ParVectorTBase<Type> {
533 
534 public:
535 
540  typedef void (T::*SetFn)(Type, int);
541 
546  typedef void (T::*InsFn)(Type, int);
547 
552  typedef void (T::*DelFn)(int);
553 
557  typedef vector<Type> TypeVector;
558 
563  typedef TypeVector (T::*GetFn)() const;
564 
568  typedef vector<string> StringVector;
569 
574  typedef StringVector (T::*StringGetFn)() const;
575 
580  typedef Type (T::*DefFn)(int) const;
581 
586  typedef TypeVector T::* Member;
587 
588 public:
589 
644  ParVector(string newName, string newDescription,
645  Member newMember, int newSize, Type newDef, Type newMin,
646  Type newMax, bool depSafe = false, bool readonly = false,
647  bool limits = true, SetFn newSetFn = 0,
648  InsFn newInsFn = 0, DelFn newDelFn = 0, GetFn newGetFn = 0,
649  DefFn newDefFn = 0, DefFn newMinFn = 0, DefFn newMaxFn = 0,
650  StringGetFn newStringGetFn = 0)
651  : ParVectorTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
652  typeid(T), Type(), newSize, depSafe, readonly,
653  limits),
654  theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
655  theSetFn(newSetFn), theInsFn(newInsFn), theDelFn(newDelFn),
656  theGetFn(newGetFn), theDefFn(newDefFn), theMinFn(newMinFn),
657  theMaxFn(newMaxFn), theStringGetFn(newStringGetFn) {}
658 
659 
717  ParVector(string newName, string newDescription, Member newMember,
718  Type newUnit, int newSize, Type newDef, Type newMin,
719  Type newMax, bool depSafe = false, bool readonly = false,
720  bool limits = true, SetFn newSetFn = 0,
721  InsFn newInsFn = 0, DelFn newDelFn = 0, GetFn newGetFn = 0,
722  DefFn newDefFn = 0, DefFn newMinFn = 0, DefFn newMaxFn = 0,
723  StringGetFn newStringGetFn = 0)
724  : ParVectorTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
725  typeid(T), newUnit, newSize, depSafe, readonly,
726  limits),
727  theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
728  theSetFn(newSetFn), theInsFn(newInsFn), theDelFn(newDelFn),
729  theGetFn(newGetFn), theDefFn(newDefFn), theMinFn(newMinFn),
730  theMaxFn(newMaxFn), theStringGetFn(newStringGetFn) {}
731 
787  ParVector(string newName, string newDescription,
788  Member newMember, int newSize, Type newDef, Type newMin,
789  Type newMax, bool depSafe = false, bool readonly = false,
790  int limits = Interface::limited, SetFn newSetFn = 0,
791  InsFn newInsFn = 0, DelFn newDelFn = 0, GetFn newGetFn = 0,
792  DefFn newDefFn = 0, DefFn newMinFn = 0, DefFn newMaxFn = 0,
793  StringGetFn newStringGetFn = 0)
794  : ParVectorTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
795  typeid(T), Type(), newSize, depSafe, readonly,
796  limits),
797  theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
798  theSetFn(newSetFn), theInsFn(newInsFn), theDelFn(newDelFn),
799  theGetFn(newGetFn), theDefFn(newDefFn), theMinFn(newMinFn),
800  theMaxFn(newMaxFn), theStringGetFn(newStringGetFn) {}
801 
860  ParVector(string newName, string newDescription, Member newMember,
861  Type newUnit, int newSize, Type newDef, Type newMin,
862  Type newMax, bool depSafe = false, bool readonly = false,
863  int limits = Interface::limited, SetFn newSetFn = 0,
864  InsFn newInsFn = 0, DelFn newDelFn = 0, GetFn newGetFn = 0,
865  DefFn newDefFn = 0, DefFn newMinFn = 0, DefFn newMaxFn = 0,
866  StringGetFn newStringGetFn = 0)
867  : ParVectorTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
868  typeid(T), newUnit, newSize, depSafe, readonly,
869  limits),
870  theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
871  theSetFn(newSetFn), theInsFn(newInsFn), theDelFn(newDelFn),
872  theGetFn(newGetFn), theDefFn(newDefFn), theMinFn(newMinFn),
873  theMaxFn(newMaxFn), theStringGetFn(newStringGetFn) {}
874 
879  virtual void tset(InterfacedBase & ib, Type val, int i) const
880  ;
881 
886  virtual void tinsert(InterfacedBase & ib, Type val, int i) const
887  ;
888 
893  virtual void erase(InterfacedBase & ib, int i)
894  const;
895 
901  virtual StringVector get(const InterfacedBase & ib) const
902  ;
903 
908  virtual TypeVector tget(const InterfacedBase & ib) const
909  ;
910 
915  virtual Type tminimum(const InterfacedBase & ib, int i) const
916  ;
917 
922  virtual Type tmaximum(const InterfacedBase & ib, int i) const
923  ;
924 
929  virtual Type tdef(const InterfacedBase &, int) const
930  ;
931 
935  virtual Type tdef() const;
936 
940  void setSetFunction(SetFn sf) { theSetFn = sf; }
941 
945  void setInsertFunction(InsFn ifn) { theInsFn = ifn; }
946 
950  void setGetFunction(GetFn gf) { theGetFn = gf; }
951 
955  void setEraseFunction(DelFn df) { theDelFn = df; }
956 
960  void setDefaultFunction(GetFn df) { theDefFn = df; }
961 
965  void setMinFunction(GetFn mf) { theMinFn = mf; }
966 
970  void setMaxFunction(GetFn mf) { theMaxFn = mf; }
971 
975  void setStringGetFunction(StringGetFn gf) { theStringGetFn = gf; }
976 
981  virtual void doxygenDescription(ostream & stream) const;
982 
983 private:
984 
989 
994  Type theDef;
995 
1000  Type theMin;
1001 
1006  Type theMax;
1007 
1011  SetFn theSetFn;
1012 
1016  InsFn theInsFn;
1017 
1021  DelFn theDelFn;
1022 
1026  GetFn theGetFn;
1027 
1031  DefFn theDefFn;
1032 
1036  DefFn theMinFn;
1037 
1041  DefFn theMaxFn;
1042 
1046  StringGetFn theStringGetFn;
1047 
1048 };
1049 
1050 }
1051 
1052 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
1053 #include "ParVector.tcc"
1054 #endif
1055 
1056 #endif /* ThePEG_ParVector_H */
DelFn theDelFn
A pointer to a member function to be used by terase().
Definition: ParVector.h:1021
vector< string > StringVector
A vector of strings.
Definition: ParVector.h:568
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:507
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:489
bool upperLimit() const
True if there the variable is limited from abovew.
Definition: ParVector.h:201
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:1046
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
virtual string fullDescription(const InterfacedBase &ib) const
Return a complete description of this parameter vector.
bool lowerLimit() const
True if there the variable is limited from below.
Definition: ParVector.h:208
Type theMax
Maximum value to be used if no corresponding member function pointer is given.
Definition: ParVector.h:1006
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:248
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.
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:21
void setMaxFunction(GetFn mf)
Give a pointer to a member function to be used by tmaximum().
Definition: ParVector.h:970
void setLimited()
Set a flag indicating that there are limits associated with the variables.
Definition: ParVector.h:216
DefFn theDefFn
Pointer to member function to be used by tdef().
Definition: ParVector.h:1031
void setInsertFunction(InsFn ifn)
Give a pointer to a member function to be used by tinsert().
Definition: ParVector.h:945
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
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:482
Type theMin
Minimum value to be used if no corresponding member function pointer is given.
Definition: ParVector.h:1000
The ParVector and its base classes ParVectorTBase and ParVectorBase defines an interface to a class d...
Definition: ParVector.h:532
InsFn theInsFn
A pointer to a member function to be used by tinsert().
Definition: ParVector.h:1016
int theSize
The size of the container being interfaced.
Definition: ParVector.h:253
Int2Type< Dimensioned > DimensionT
Typedef for dimensioned types.
Definition: TemplateTools.h:68
void setMinFunction(GetFn mf)
Give a pointer to a member function to be used by tminimum().
Definition: ParVector.h:965
string className() const
Return the class name for the class this interface is defined for.
virtual ~ParVectorTBase()
Destructor.
Definition: ParVector.h:328
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 putUnit(ostream &os, Type val) const
Write a numer to a stream with the unit specified with unit().
Definition: ParVector.h:496
void setSetFunction(SetFn sf)
Give a pointer to a member function to be used by tset().
Definition: ParVector.h:940
Type theDef
Default value to be used if no corresponding member function pointer is given.
Definition: ParVector.h:994
TypeVector T::* Member
Declaration of a direct pointer to the member variable in case it is a vector.
Definition: ParVector.h:586
vector< Type > TypeVector
A vector of objects of the template parameter Type.
Definition: ParVector.h:557
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:975
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:988
virtual void doxygenDescription(ostream &stream) const
Print a description to be included in the Doxygen documentation to the given stream.
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:717
vector< Type > TypeVector
A vector of objects of the template argument type.
Definition: ParVector.h:283
void setEraseFunction(DelFn df)
Give a pointer to a member function to be used by terase().
Definition: ParVector.h:955
virtual string exec(InterfacedBase &, string action, string arguments) const
The general interface method overriding the one in InterfaceBase.
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:644
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:1026
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:316
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:960
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:860
Int2Type< Standard > StandardT
Typedef for non-dimensioned types.
Definition: TemplateTools.h:71
SetFn theSetFn
A pointer to a member function to be used by tset().
Definition: ParVector.h:1011
bool limited() const
True if there the variable is limited from above and below.
Definition: ParVector.h:196
DefFn theMinFn
Pointer to member function to be used by tminimum().
Definition: ParVector.h:1036
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:787
void setSize(int sz)
Set the size of the container being interfaced.
Definition: ParVector.h:234
int size() const
Get the size of the container being interfaced.
Definition: ParVector.h:228
void setGetFunction(GetFn gf)
Give a pointer to a member function to be used by tget().
Definition: ParVector.h:950
DefFn theMaxFn
Pointer to member function to be used by tmaximum().
Definition: ParVector.h:1041
void setUnlimited()
Set a flag indicating if there are no limits associated with the variables.
Definition: ParVector.h:222
The ParVector and its base classes ParVectorTBase and ParVectorBase defines an interface to a class d...
Definition: ParVector.h:278
void setVariableSize()
Set the size of the container being interfaced to -1, i.e.
Definition: ParVector.h:240
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.