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 
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 
1012 
1017 
1022 
1027 
1032 
1037 
1042 
1047 
1048 };
1049 
1050 }
1051 
1052 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
1053 #include "ParVector.tcc"
1054 #endif
1055 
1056 #endif /* ThePEG_ParVector_H */