Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:38:26

0001 // -*- C++ -*-
0002 //
0003 // Parameter.h is a part of ThePEG - Toolkit for HEP Event Generation
0004 // Copyright (C) 1999-2019 Leif Lonnblad
0005 //
0006 // ThePEG is licenced under version 3 of the GPL, see COPYING for details.
0007 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
0008 //
0009 #ifndef ThePEG_Parameter_H
0010 #define ThePEG_Parameter_H
0011 // This is the declaration of the Parameter, ParameterTBase and
0012 // ParameterBase classes.
0013 
0014 
0015 #include "ThePEG/Config/ThePEG.h"
0016 #include "ThePEG/Utilities/Throw.h"
0017 #include "InterfaceBase.h"
0018 #include "Parameter.xh"
0019 #include "Parameter.fh"
0020 #include "ThePEG/Utilities/StringUtils.h"
0021 #include <limits>
0022 
0023 namespace ThePEG {
0024 
0025 /// Helper functions for putUnit()
0026 namespace {
0027   template <typename T>
0028   /**
0029    *  Helper functions for putUnit
0030    */
0031   inline void putUnitImpl(ostream & os, T v, T u, DimensionT) {
0032     os << v/u;
0033   }
0034   
0035   template <typename T>
0036   /**
0037    *  Helper functions for putUnit
0038    */
0039   inline void putUnitImpl(ostream & os, T v, T u, StandardT) {
0040     if ( u > T() )
0041       os << v/u;
0042     else
0043       os << v;
0044   }
0045 
0046   template <typename T>
0047   /**
0048    *  Helper functions for putUnit
0049    */
0050   inline void putUnitImpl(ostream & os, T v, T, EnumT) {
0051     os << v;
0052   }
0053 }
0054 
0055 
0056 /// Helper functions for unit multiplication.
0057 namespace {
0058 
0059 template<typename T, typename U>
0060 U umult(const T & t, const U & u) {
0061   return t*u;
0062 }
0063 
0064 template <typename U>
0065 bool umult(bool b, U) {
0066   return b;
0067 }
0068 }
0069 
0070 /**
0071  * The Parameter and its base classes ParameterTBase and ParameterBase
0072  * defines an interface to a class derived from the InterfacedBase,
0073  * through which simple member variables can be
0074  * manuipulated. Parameter is templated on the type of the member
0075  * variable and the type of the InterfacedBase class, and is derived
0076  * from the InterfaceBase class via ParameterTBase (which is templated
0077  * only on the type of the member variable) and ParameterBase.
0078  *
0079  * For each InterfacedBase class exactly one static Parameter object
0080  * should created for each member variable which should be
0081  * interfaced. This object will automatically register itself with the
0082  * BaseRepository class.
0083  *
0084  * @see InterfacedBase
0085  * @see InterfaceBase
0086  * 
0087  */
0088 class ParameterBase: public InterfaceBase {
0089 
0090 public:
0091 
0092   /**
0093    * Standard constructor.
0094    *
0095    * @param newName the name of the interface, may only contain
0096    * letters [a-zA-z0-9_].
0097    *
0098    * @param newDescription a brief description of the interface.
0099    *
0100    * @param newClassName the name of the corresponding class.
0101    *
0102    * @param newTypeInfo the type_info object of the corresponding
0103    * class.
0104    *
0105    * @param depSafe set to true if calls to this interface for one
0106    * object does not influence other objects.
0107    *
0108    * @param readonly if this is set true the interface will not be
0109    * able to manipulate objects of the corresponding class, but will
0110    * still be able to access information.
0111    *
0112    * @param limits determines if the values of the parameters are
0113    * limited from above and/or below. The possible values are given by
0114    * Interface::Limits.
0115    */
0116   ParameterBase(string newName, string newDescription,
0117         string newClassName,
0118         const type_info & newTypeInfo, bool depSafe,
0119         bool readonly, int limits)
0120     : InterfaceBase(newName, newDescription, 
0121             newClassName, newTypeInfo, depSafe,
0122             readonly), limit(limits) {}
0123 
0124   /**
0125    * The destructor.
0126    */
0127   virtual ~ParameterBase();
0128 
0129   /**
0130    * The general interface method overriding the one in
0131    * InterfaceBase. For this class, \a action can be any of "set",
0132    * "get", "min", "max", "def" and "setdef" and \a argument should be
0133    * a something which can be read into a variable through a
0134    * stringstream with the standard '>>' operator.
0135    */
0136   virtual string exec(InterfacedBase & ib, string action,
0137               string arguments) const;
0138 
0139   /**
0140    * Return a complete description of this parameter.
0141    */
0142   virtual string fullDescription(const InterfacedBase & ib) const;
0143 
0144   /**
0145    * Set the member variable of \a ib to \a val.
0146    */
0147   virtual void set(InterfacedBase & ib, string) const
0148     = 0;
0149 
0150   /**
0151    * Return the minimum value allowed for the member variable of \a ib.
0152    */
0153   virtual string minimum(const InterfacedBase & ib) const
0154     = 0;
0155 
0156   /**
0157    * Return the maximum value allowed for the member variable of \a ib.
0158    */
0159   virtual string maximum(const InterfacedBase & ib) const
0160     = 0;
0161 
0162   /**
0163    * Return the value of the member variable of \a ib.
0164    */
0165   virtual string get(const InterfacedBase & ib) const
0166     = 0;
0167 
0168   /**
0169    * Return the default value for the member variable of \a ib.
0170    */
0171   virtual string def(const InterfacedBase & ib) const
0172     = 0;
0173 
0174   /**
0175    * Set the member variable of \a ib to its default value.
0176    */
0177   virtual void setDef(InterfacedBase & ib) const
0178     = 0;
0179 
0180   /**
0181    * True if there the variable is limited from above and below.
0182    */
0183   bool limited() const { return limit != Interface::nolimits; }
0184 
0185   /**
0186    * True if there the variable is limited from abovew.
0187    */
0188   bool upperLimit() const { 
0189     return limit == Interface::limited || limit == Interface::upperlim;
0190   }
0191 
0192   /**
0193    * True if there the variable is limited from  below.
0194    */
0195   bool lowerLimit() const {
0196     return limit == Interface::limited || limit == Interface::lowerlim;
0197   }
0198 
0199   /**
0200    * Set flag indicating that there are limits associated with the
0201    * variable.
0202    */
0203   void setLimited() { limit = Interface::limited; }
0204 
0205   /**
0206    * Set flag indicating that there are no limits associated with the
0207    * variable.
0208    */
0209   void setUnlimited() { limit = Interface::nolimits; }
0210 
0211 private:
0212 
0213   /**
0214    * Determines if the values of the parameters are
0215    * limited from above and/or below. The possible values are given by
0216    * Interface::Limits.
0217    */
0218   int limit;
0219 
0220 };
0221 
0222 /**
0223  * The Parameter and its base classes ParameterTBase and ParameterBase
0224  * defines an interface to a class derived from the InterfacedBase,
0225  * through which simple member variables can be
0226  * manuipulated. Parameter is templated on the type of the member
0227  * variable and the type of the InterfacedBase class, and is derived
0228  * from the InterfaceBase class via ParameterTBase (which is templated
0229  * only on the type of the member variable) and ParameterBase.
0230  *
0231  * For each InterfacedBase class exactly one static Parameter object
0232  * should created for each member variable which should be
0233  * interfaced. This object will automatically register itself with the
0234  * BaseRepository class.
0235  *
0236  * @see InterfacedBase
0237  * @see InterfaceBase
0238  * 
0239  */
0240 template <typename Type>
0241 class ParameterTBase: public ParameterBase {
0242 
0243 public:
0244 
0245   /**
0246    * Standard constructor.
0247    *
0248    * @param newName the name of the interface, may only contain
0249    * letters [a-zA-z0-9_].
0250    *
0251    * @param newDescription a brief description of the interface.
0252    *
0253    * @param newClassName the name of the corresponding class.
0254    *
0255    * @param newTypeInfo the type_info object of the corresponding
0256    * class.
0257    *
0258    * @param newUnit the unit assumed when a number is read or written
0259    * to a stream.
0260    *
0261    * @param depSafe set to true if calls to this interface for one
0262    * object does not influence other objects.
0263    *
0264    * @param readonly if this is set true the interface will not be
0265    * able to manipulate objects of the corresponding class, but will
0266    * still be able to access information.
0267    *
0268    * @param limits determines if the values of the parameters are
0269    * limited from above and/or below. The possible values are given by
0270    * Interface::Limits.
0271    */
0272   ParameterTBase(string newName, string newDescription,
0273          string newClassName,
0274          const type_info & newTypeInfo, Type newUnit,
0275          bool depSafe, bool readonly, int limits) 
0276     : ParameterBase(newName, newDescription, 
0277             newClassName, newTypeInfo, depSafe,
0278             readonly, limits), theUnit(newUnit) {}
0279 
0280   /**
0281    * Destructor.
0282    */
0283   virtual ~ParameterTBase() {}
0284 
0285   /**
0286    * Return a code for the type of this parameter.
0287    */
0288   virtual string type() const;
0289 
0290 private:
0291 
0292   /// Implementation of set() for standard types.
0293   void setImpl (InterfacedBase & i, 
0294                string newValue, StandardT) 
0295     const;
0296 
0297   /// Implementation of set() for dimensioned types.
0298   void setImpl (InterfacedBase & i, 
0299                string newValue, DimensionT) 
0300     const;
0301 
0302   /// Implementation of set() for dimensioned types.
0303   void setImpl (InterfacedBase & i, 
0304                string newValue, EnumT) 
0305     const;
0306 
0307 public:
0308 
0309   /**
0310    * Set the member variables of \a ib to \a val. Uses a stringstream
0311    * to read the \a val into a Type object and then calls
0312    * tset(InterfacedBase &, Type).
0313    */
0314   virtual void set(InterfacedBase & ib, string newValue)
0315     const;
0316 
0317   /**
0318    * Set the member variables of \a ib to \a val.
0319    */
0320   virtual void tset(InterfacedBase & ib, Type) const
0321     = 0;
0322 
0323   /**
0324    * Return the value of the member variable of \a ib. Calls
0325    * tget(const InterfacedBase &) and converts the returned value with
0326    * an ostringstream.
0327    */
0328   virtual string get(const InterfacedBase & ib) const
0329    ;
0330 
0331   /**
0332    * Return the value of the member variable of \a ib.
0333    */
0334   virtual Type tget(const InterfacedBase & ib) const
0335     = 0;
0336 
0337   /**
0338    * Return the minimum value allowed for the member variable of \a
0339    * ib. Calls tmimimum(const InterfacedBase &) and converts the
0340    * returned value with an ostringstream.
0341    */
0342   virtual string minimum(const InterfacedBase & ib) const
0343    ;
0344 
0345   /**
0346    * Return the minimum value allowed for the member variable of \a
0347    * ib.
0348    */
0349   virtual Type tminimum(const InterfacedBase & ib) const
0350     = 0;
0351 
0352   /**
0353    * Return the maximum value allowed for the member variable of \a
0354    * ib. Calls tmaximum(const InterfacedBase &) and converts the
0355    * returned value with an ostringstream.
0356    */
0357   virtual string maximum(const InterfacedBase & ib) const
0358    ;
0359 
0360   /**
0361    * Return the maximum value allowed for the member variable of
0362    * \a ib.
0363    */
0364   virtual Type tmaximum(const InterfacedBase & ib) const
0365     = 0;
0366 
0367   /**
0368    * Return the default value for the member variables of \a ib. Calls
0369    * tdef(const InterfacedBase &) and converts the returned value with
0370    * an ostringstream.
0371    */
0372   virtual string def(const InterfacedBase & ib) const
0373    ;
0374 
0375   /**
0376    * Return the default value for the member variables of \a ib.
0377    */
0378   virtual Type tdef(const InterfacedBase &ib) const
0379     = 0;
0380 
0381   /**
0382    * set the member variable of \a ib to its default value.
0383    */
0384   virtual void setDef(InterfacedBase & ib) const {
0385     tset(ib, tdef(ib));
0386   }
0387 
0388   /**
0389    * Get the unit which an Type object is divided (multiplied) by when
0390    * written to (read from) a stream via a double. If unit() is zero,
0391    * the Type object is written/read directly.
0392    */
0393   Type unit() const { return theUnit; }
0394 
0395   /**
0396    * Set the unit which an Type object is divided (multiplied) by when
0397    * written to (read from) a stream via a double. If unit() is zero,
0398    * the Type object is written/read directly.
0399    */
0400   void unit(Type u) { theUnit = u; }
0401 
0402   /**
0403    * Return a string describing the type of interface to be included
0404    * in the Doxygen documentation.
0405    */
0406   virtual string doxygenType() const;
0407 
0408 protected:
0409 
0410   /**
0411    * Write a number to a stream with the unit specified with unit().
0412    */
0413   void putUnit(ostream & os, Type val) const {
0414     putUnitImpl(os, val, unit(), typename TypeTraits<Type>::DimType());
0415   }
0416 
0417 private:
0418 
0419   /**
0420    * The unit which an Type object is divided (multiplied) by
0421    * when written to (read from) a stream via a double. If unit() is
0422    * zero, the Type object is written/read directly.
0423    */
0424   Type theUnit;
0425 
0426   /**
0427    * Helper to check the unit consistency in set() operations
0428    */
0429   void checkUnitConsistency(string suffix) const;
0430 
0431 };
0432 
0433 /**
0434  * The Parameter and its base classes ParameterTBase and ParameterBase
0435  * defines an interface to a class derived from the InterfacedBase,
0436  * through which simple member variables can be
0437  * manuipulated. Parameter is templated on the type of the member
0438  * variable and the type of the InterfacedBase class, and is derived
0439  * from the InterfaceBase class via ParameterTBase (which is templated
0440  * only on the type of the member variable) and ParameterBase.
0441  *
0442  * For each InterfacedBase class exactly one static Parameter object
0443  * should created for each member variable which should be
0444  * interfaced. This object will automatically register itself with the
0445  * BaseRepository class.
0446  *
0447  * @see InterfacedBase
0448  * @see InterfaceBase
0449  * 
0450  */
0451 template <typename T, typename Type>
0452 class Parameter: public ParameterTBase<Type> {
0453 
0454 public:
0455 
0456   /**
0457    * The declaration of member functions which can be used by this
0458    * Switch interface for the 'set' action.
0459    */
0460   typedef void (T::*SetFn)(Type);
0461   /**
0462    * The declaration of member functions which can be used by this
0463    * Switch interface for the 'get', 'def', 'min' and 'max' actions.
0464    */
0465   typedef Type (T::*GetFn)() const;
0466 
0467   /**
0468    * Declaration of a direct pointer to the member variable.
0469    */
0470   typedef Type T::* Member;
0471 
0472 public:
0473 
0474   /**
0475    * Standard constructor.
0476    *
0477    * @param newName the name of the interface, may only contain
0478    * letters [a-zA-z0-9_].
0479    *
0480    * @param newDescription a brief description of the interface.
0481    *
0482    * @param newMember a pointer to the member variable. May be null if
0483    * corresponding set/get functions are provided.
0484    *
0485    * @param newDef the default value for the member variable.
0486    *
0487    * @param newMin the minimum value for the member variable.
0488    *
0489    * @param newMax the maximum value for the member variable.
0490    *
0491    * @param depSafe set to true if calls to this interface for one
0492    * object does not influence other objects.
0493    *
0494    * @param readonly if this is set true the interface will not be
0495    * able to manipulate objects of the corresponding class, but will
0496    * still be able to access information.
0497    *
0498    * @param limits determines if the values of the parameters are
0499    * limited from above and below.
0500    *
0501    * @param newSetFn optional pointer to the member function for the
0502    * 'set' action.
0503    *
0504    * @param newGetFn optional pointer to the member function for the
0505    * 'get' action.
0506    *
0507    * @param newMinFn optional pointer to the member function for the
0508    * 'min' action.
0509    *
0510    * @param newMaxFn optional pointer to the member function for the
0511    * 'max' action.
0512    *
0513    * @param newDefFn optional pointer to the member function for the
0514    * 'def' action.
0515    */
0516   Parameter(string newName, string newDescription,
0517            Member newMember, Type newDef, Type newMin,
0518            Type newMax, bool depSafe = false, bool readonly = false,
0519            bool limits = true, SetFn newSetFn = 0,
0520            GetFn newGetFn = 0, GetFn newMinFn = 0,
0521            GetFn newMaxFn = 0, GetFn newDefFn = 0)
0522   : ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
0523              typeid(T), Type(), depSafe, readonly, limits),
0524     theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
0525     theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
0526     theMinFn(newMinFn), theMaxFn(newMaxFn) {}
0527 
0528   /**
0529    * Standard constructor.
0530    *
0531    * @param newName the name of the interface, may only contain
0532    * letters [a-zA-z0-9_].
0533    *
0534    * @param newDescription a brief description of the interface.
0535    *
0536    * @param newMember a pointer to the member variable. May be null if
0537    * corresponding set/get functions are provided.
0538    *
0539    * @param newUnit the unit assumed when a number is read or written
0540    * to a stream.
0541    *
0542    * @param newDef the default value for the member variable.
0543    *
0544    * @param newMin the minimum value for the member variable.
0545    *
0546    * @param newMax the maximum value for the member variable.
0547    *
0548    * @param depSafe set to true if calls to this interface for one
0549    * object does not influence other objects.
0550    *
0551    * @param readonly if this is set true the interface will not be
0552    * able to manipulate objects of the corresponding class, but will
0553    * still be able to access information.
0554    *
0555    * @param limits determines if the values of the parameters are
0556    * limited from above and below.
0557    *
0558    * @param newSetFn optional pointer to the member function for the
0559    * 'set' action.
0560    *
0561    * @param newGetFn optional pointer to the member function for the
0562    * 'get' action.
0563    *
0564    * @param newMinFn optional pointer to the member function for the
0565    * 'min' action.
0566    *
0567    * @param newMaxFn optional pointer to the member function for the
0568    * 'max' action.
0569    *
0570    * @param newDefFn optional pointer to the member function for the
0571    * 'def' action.
0572    */
0573   Parameter(string newName, string newDescription,
0574            Member newMember, Type newUnit, Type newDef, Type newMin,
0575            Type newMax, bool depSafe = false, bool readonly = false,
0576            bool limits = true, SetFn newSetFn = 0,
0577            GetFn newGetFn = 0, GetFn newMinFn = 0,
0578            GetFn newMaxFn = 0, GetFn newDefFn = 0)
0579   : ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
0580              typeid(T), newUnit, depSafe, readonly, limits),
0581     theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
0582     theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
0583     theMinFn(newMinFn), theMaxFn(newMaxFn) {}
0584 
0585   /**
0586    * Standard constructor.
0587    *
0588    * @param newName the name of the interface, may only contain
0589    * letters [a-zA-z0-9_].
0590    *
0591    * @param newDescription a brief description of the interface.
0592    *
0593    * @param newMember a pointer to the member variable. May be null if
0594    * corresponding set/get functions are provided.
0595    *
0596    * @param newDef the default value for the member variable.
0597    *
0598    * @param newMin the minimum value for the member variable.
0599    *
0600    * @param newMax the maximum value for the member variable.
0601    *
0602    * @param depSafe set to true if calls to this interface for one
0603    * object does not influence other objects.
0604    *
0605    * @param readonly if this is set true the interface will not be
0606    * able to manipulate objects of the corresponding class, but will
0607    * still be able to access information.
0608    *
0609    * @param limits determines if the values of the parameters are
0610    * limited from above and/or below. The possible values are given by
0611    * Interface::Limits.
0612    *
0613    * @param newSetFn optional pointer to the member function for the
0614    * 'set' action.
0615    *
0616    * @param newGetFn optional pointer to the member function for the
0617    * 'get' action.
0618    *
0619    * @param newMinFn optional pointer to the member function for the
0620    * 'min' action.
0621    *
0622    * @param newMaxFn optional pointer to the member function for the
0623    * 'max' action.
0624    *
0625    * @param newDefFn optional pointer to the member function for the
0626    * 'def' action.
0627    */
0628   Parameter(string newName, string newDescription,
0629            Member newMember, Type newDef, Type newMin,
0630            Type newMax, bool depSafe = false, bool readonly = false,
0631            int limits = Interface::limited, SetFn newSetFn = 0,
0632            GetFn newGetFn = 0, GetFn newMinFn = 0,
0633            GetFn newMaxFn = 0, GetFn newDefFn = 0)
0634   : ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
0635              typeid(T), Type(), depSafe, readonly, limits),
0636     theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
0637     theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
0638     theMinFn(newMinFn), theMaxFn(newMaxFn) {}
0639 
0640   /**
0641    * Standard constructor.
0642    *
0643    * @param newName the name of the interface, may only contain
0644    * letters [a-zA-z0-9_].
0645    *
0646    * @param newDescription a brief description of the interface.
0647    *
0648    * @param newMember a pointer to the member variable. May be null if
0649    * corresponding set/get functions are provided.
0650    *
0651    * @param newUnit the unit assumed when a number is read or written
0652    * to a stream.
0653    *
0654    * @param newDef the default value for the member variable.
0655    *
0656    * @param newMin the minimum value for the member variable.
0657    *
0658    * @param newMax the maximum value for the member variable.
0659    *
0660    * @param depSafe set to true if calls to this interface for one
0661    * object does not influence other objects.
0662    *
0663    * @param readonly if this is set true the interface will not be
0664    * able to manipulate objects of the corresponding class, but will
0665    * still be able to access information.
0666    *
0667    * @param limits determines if the values of the parameters are
0668    * limited from above and/or below. The possible values are given by
0669    * Interface::Limits.
0670    *
0671    * @param newSetFn optional pointer to the member function for the
0672    * 'set' action.
0673    *
0674    * @param newGetFn optional pointer to the member function for the
0675    * 'get' action.
0676    *
0677    * @param newMinFn optional pointer to the member function for the
0678    * 'min' action.
0679    *
0680    * @param newMaxFn optional pointer to the member function for the
0681    * 'max' action.
0682    *
0683    * @param newDefFn optional pointer to the member function for the
0684    * 'def' action.
0685    */
0686   Parameter(string newName, string newDescription,
0687            Member newMember, Type newUnit, Type newDef, Type newMin,
0688            Type newMax, bool depSafe = false, bool readonly = false,
0689            int limits = Interface::limited, SetFn newSetFn = 0,
0690            GetFn newGetFn = 0, GetFn newMinFn = 0,
0691            GetFn newMaxFn = 0, GetFn newDefFn = 0)
0692   : ParameterTBase<Type>(newName, newDescription, ClassTraits<T>::className(),
0693              typeid(T), newUnit, depSafe, readonly, limits),
0694     theMember(newMember), theDef(newDef), theMin(newMin), theMax(newMax),
0695     theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn),
0696     theMinFn(newMinFn), theMaxFn(newMaxFn) {}
0697 
0698   /**
0699    * Default dtor.
0700    */
0701   virtual ~Parameter() {}
0702 
0703   /**
0704    * Set the member variable of \a ib to \a val.
0705    */
0706   virtual void tset(InterfacedBase & ib, Type val)
0707     const;
0708 
0709   /**
0710    * Return the value of the member variable of ib.
0711    */
0712   virtual Type tget(const InterfacedBase & ib) const;
0713 
0714   /**
0715    * Return the minimum value allowed for the member variable of \a ib.
0716    */
0717   virtual Type tminimum(const InterfacedBase & ib) const
0718    ;
0719 
0720   /**
0721    * Return the miaximum value allowed for the member variable of \a ib.
0722    */
0723   virtual Type tmaximum(const InterfacedBase & ib) const
0724    ;
0725 
0726   /**
0727    * Return the default value for the member variable of \a ib.
0728    */
0729   virtual Type tdef(const InterfacedBase & ib) const
0730    ;
0731 
0732   /**
0733    * Give a pointer to a member function to be used by tset().
0734    */
0735   void setSetFunction(SetFn sf) { theSetFn = sf; }
0736 
0737   /**
0738    * Give a pointer to a member function to be used by tget().
0739    */
0740   void setGetFunction(GetFn gf) { theGetFn = gf; }
0741 
0742   /**
0743    * Give a pointer to a member function to be used by tdef().
0744    */
0745   void setDefaultFunction(GetFn df) { theDefFn = df; }
0746 
0747   /**
0748    * Give a pointer to a member function to be used by tminimum().
0749    */
0750   void setMinFunction(GetFn mf) { theMinFn = mf; }
0751 
0752   /**
0753    * Give a pointer to a member function to be used by tmaximum().
0754    */
0755   void setMaxFunction(GetFn mf) { theMaxFn = mf; }
0756 
0757   /**
0758    * Print a description to be included in the Doxygen documentation
0759    * to the given \a stream.
0760    */
0761   virtual void doxygenDescription(ostream & stream) const;
0762 
0763 private:
0764 
0765   /**
0766    * The pointer to the member variable.
0767    */
0768   Member theMember;
0769 
0770   /**
0771    * Default value to be used if no corresponding member function
0772    * pointer is given.
0773    */
0774   Type theDef;
0775 
0776   /**
0777    * Minimum value to be used if no corresponding member function
0778    * pointer is given.
0779    */
0780   Type theMin;
0781 
0782   /**
0783    * Maximum value to be used if no corresponding member function
0784    * pointer is given.
0785    */
0786   Type theMax;
0787 
0788   /**
0789    * A pointer to a member function to be used by tset().
0790    */
0791   SetFn theSetFn;
0792 
0793   /**
0794    * Pointer to member function to be used by tget().
0795    */
0796   GetFn theGetFn;
0797 
0798   /**
0799    * Pointer to member function to be used by tdef().
0800    */
0801   GetFn theDefFn;
0802 
0803   /**
0804    * Pointer to member function to be used by tminimum().
0805    */
0806   GetFn theMinFn;
0807 
0808   /**
0809    * Pointer to member function to be used by tmaximum().
0810    */
0811   GetFn theMaxFn;
0812 
0813 };
0814 
0815 /**
0816  * This is a specialization of ParameterTBase for the string case.
0817  *
0818  * @see ParameterTBase
0819  * 
0820  */
0821 template <>
0822 class ParameterTBase<string>: public ParameterBase {
0823 
0824 public:
0825 
0826   /**
0827    * Enumerated variables to determine of a string parameter
0828    * corresponds to a file or a directory.
0829    */
0830   enum FileType {
0831     NoFile,    /**< Neither file nor directory. */
0832     File,      /**< The parameter corresponds to a file. */
0833     Directory  /**< The parameter corresponds to a directory. */
0834   };
0835 
0836 public:
0837 
0838   /**
0839    * Standard constructor.
0840    *
0841    * @param newName the name of the interface, may only contain
0842    * letters [a-zA-z0-9_].
0843    *
0844    * @param newDescription a brief description of the interface.
0845    *
0846    * @param newClassName the name of the corresponding class.
0847    *
0848    * @param newTypeInfo the type_info object of the corresponding
0849    * class.
0850    *
0851    * @param depSafe set to true if calls to this interface for one
0852    * object does not influence other objects.
0853    *
0854    * @param readonly if this is set true the interface will not be
0855    * able to manipulate objects of the corresponding class, but will
0856    * still be able to access information.
0857    */
0858   ParameterTBase(string newName, string newDescription,
0859          string newClassName,
0860          const type_info & newTypeInfo,
0861          bool depSafe, bool readonly)
0862     : ParameterBase(newName, newDescription, 
0863             newClassName, newTypeInfo, depSafe,
0864             readonly, false), isFileType(NoFile) {
0865     hasDefault = false;
0866   }
0867 
0868   /**
0869    * Destructor.
0870    */
0871   virtual ~ParameterTBase() {}
0872 
0873   /**
0874    * Return a code for the type of this parameter.
0875    */
0876   virtual string type() const {
0877     switch ( file() ) {
0878     case File: return "PF";
0879     case Directory: return "PD";
0880     default: return "Ps";
0881     }
0882   }
0883 
0884   /**
0885    * Indicate that this parameter corresponds to a file. 
0886    */
0887   void fileType() { file(File); }
0888 
0889   /**
0890    * Indicate that this parameter corresponds to a directory. 
0891    */
0892   void directoryType() { file(Directory); }
0893 
0894   /**
0895    * Indicate if this parameter corresponds to a file or directory. 
0896    */
0897   void file(FileType t) { isFileType = t; }
0898 
0899   /**
0900    * See if this parameter corresponds to a file or directory.
0901    */
0902   FileType file() const { return isFileType; }
0903 
0904   /**
0905    * Set the member variables of \a ib to \a val. Uses a stringstream
0906    * to read the \a val into a Type object and then calls
0907    * tset(InterfacedBase &, Type).
0908    */
0909   virtual void set(InterfacedBase & ib, string newValue)
0910     const {
0911     tset(ib, StringUtils::stripws(newValue));
0912   }
0913 
0914   /**
0915    * Set the member variables of \a ib to \a val.
0916    */
0917   virtual void tset(InterfacedBase & ib, string) const
0918     = 0;
0919 
0920   /**
0921    * Return the value of the member variable of \a ib. Calls
0922    * tget(const InterfacedBase &) and converts the returned value with
0923    * an ostringstream.
0924    */
0925   virtual string get(const InterfacedBase & ib) const
0926     {
0927     return tget(ib);
0928   }
0929 
0930   /**
0931    * Return the value of the member variable of \a ib.
0932    */
0933   virtual string tget(const InterfacedBase & ib) const
0934     = 0;
0935 
0936   /**
0937    * Return the minimum value allowed for the member variable of \a
0938    * ib. Not relevant for strings. Returns the empty string.
0939    */
0940   virtual string minimum(const InterfacedBase &) const {
0941     return "";
0942   }
0943 
0944   /**
0945    * Return the maximum value allowed for the member variable of \a
0946    * ib. Not relevant for strings. Returns the empty string.
0947    */
0948   virtual string maximum(const InterfacedBase &) const {
0949     return "";
0950   }
0951 
0952   /**
0953    * Return the default value for the member variables of \a ib. Calls
0954    * tdef(const InterfacedBase &) and converts the returned value with
0955    * an ostringstream.
0956    */
0957   virtual string def(const InterfacedBase & ib) const
0958     {
0959     return tdef(ib);
0960   }
0961 
0962   /**
0963    * Return the default value for the member variables of \a ib.
0964    */
0965   virtual string tdef(const InterfacedBase &ib) const
0966     = 0;
0967 
0968   /**
0969    * set the member variable of \a ib to its default value.
0970    */
0971   virtual void setDef(InterfacedBase & i) const {
0972     tset(i, tdef(i));
0973   }
0974 
0975   /**
0976    * Return a string describing the type of interface to be included
0977    * in the Doxygen documentation.
0978    */
0979   virtual string doxygenType() const { return "Character string parameter"; }
0980 
0981 private:
0982 
0983   /**
0984    * Indicates if this parameter corresponds to a file or directory. 
0985    */
0986   FileType isFileType;
0987 
0988 };
0989 
0990 /**
0991  * This is a partial specialization of Parameter for the string case.
0992  *
0993  * @see Parameter
0994  * 
0995  */
0996 template <typename T>
0997 class Parameter<T,string>: public ParameterTBase<string> {
0998 
0999 public:
1000 
1001   /**
1002    * The declaration of member functions which can be used by this
1003    * Switch interface for the 'set' action.
1004    */
1005   typedef void (T::*SetFn)(string);
1006   /**
1007    * The declaration of member functions which can be used by this
1008    * Switch interface for the 'get', 'def', 'min' and 'max' actions.
1009    */
1010   typedef string (T::*GetFn)() const;
1011 
1012   /**
1013    * Declaration of a direct pointer to the member variable.
1014    */
1015   typedef string T::* Member;
1016 
1017 public:
1018 
1019   /**
1020    * Standard constructor.
1021    *
1022    * @param newName the name of the interface, may only contain
1023    * letters [a-zA-z0-9_].
1024    *
1025    * @param newDescription a brief description of the interface.
1026    *
1027    * @param newMember a pointer to the member variable. May be null if
1028    * corresponding set/get functions are provided.
1029    *
1030    * @param newDef the default value for the member variable.
1031    *
1032    * @param depSafe set to true if calls to this interface for one
1033    * object does not influence other objects.
1034    *
1035    * @param readonly if this is set true the interface will not be
1036    * able to manipulate objects of the corresponding class, but will
1037    * still be able to access information.
1038    *
1039    * @param newSetFn optional pointer to the member function for the
1040    * 'set' action.
1041    *
1042    * @param newGetFn optional pointer to the member function for the
1043    * 'get' action.
1044    *
1045    * @param newDefFn optional pointer to the member function for the
1046    * 'def' action.
1047    */
1048   Parameter(string newName, string newDescription,
1049            Member newMember, string newDef,
1050            bool depSafe = false, bool readonly = false,
1051            SetFn newSetFn = 0, GetFn newGetFn = 0, GetFn newDefFn = 0)
1052     : ParameterTBase<string>(newName, newDescription,
1053                  ClassTraits<T>::className(),
1054              typeid(T), depSafe, readonly),
1055     theMember(newMember), theDef(newDef),
1056     theSetFn(newSetFn), theGetFn(newGetFn), theDefFn(newDefFn) {}
1057 
1058 
1059   /**
1060    * Default dtor.
1061    */
1062   virtual ~Parameter() {}
1063 
1064   /**
1065    * Set the member variable of \a ib to \a val.
1066    */
1067   virtual void tset(InterfacedBase & ib, string val)
1068     const;
1069 
1070   /**
1071    * Return the value of the member variable of ib.
1072    */
1073   virtual string tget(const InterfacedBase & ib) const
1074    ;
1075 
1076   /**
1077    * Return the default value for the member variable of \a ib.
1078    */
1079   virtual string tdef(const InterfacedBase & ib) const
1080    ;
1081 
1082   /**
1083    * Give a pointer to a member function to be used by tset().
1084    */
1085   void setSetFunction(SetFn sf) { theSetFn = sf; }
1086 
1087   /**
1088    * Give a pointer to a member function to be used by tget().
1089    */
1090   void setGetFunction(GetFn gf) { theGetFn = gf; }
1091 
1092   /**
1093    * Give a pointer to a member function to be used by tdef().
1094    */
1095   void setDefaultFunction(GetFn df) { theDefFn = df; }
1096 
1097   /**
1098    * Print a description to be included in the Doxygen documentation
1099    * to the given \a stream.
1100    */
1101   virtual void doxygenDescription(ostream & stream) const;
1102 
1103 private:
1104 
1105   /**
1106    * The pointer to the member variable.
1107    */
1108   Member theMember;
1109 
1110   /**
1111    * Default, minimum and maximum values to be used if no
1112    * corresponding member function pointers are given.
1113    */
1114   string theDef;
1115 
1116   /**
1117    * A pointer to a member function to be used by tset().
1118    */
1119   SetFn theSetFn;
1120 
1121   /**
1122    * Pointer to member function to be used by tget().
1123    */
1124   GetFn theGetFn;
1125 
1126   /**
1127    * Pointer to member function to be used by tdef().
1128    */
1129   GetFn theDefFn;
1130 
1131 };
1132 
1133 }
1134 
1135 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
1136 #include "Parameter.tcc"
1137 #endif
1138 
1139 #endif /* ThePEG_Parameter_H */