Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Reference.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_Reference_H
0010 #define ThePEG_Reference_H
0011 // This is the declaration of the Reference and ReferenceBase classes.
0012 
0013 #include "ThePEG/Config/ThePEG.h"
0014 #include "InterfaceBase.h"
0015 #include "Reference.xh"
0016 #include "Reference.fh"
0017 
0018 namespace ThePEG {
0019 
0020 /**
0021  * The Reference class and its base class ReferenceBase defines an
0022  * interface to a class derived from the InterfacedBase, through which
0023  * pointers to other InterfacedBase objects may be manipulated.
0024  * Reference is templated on the type of the class and the class of
0025  * the objects pointed to, and is derived from the InterfaceBase class
0026  * via ReferenceBase and RefInterfaceBase.
0027  *
0028  * For each InterfacedBase class exactly one static Reference object
0029  * should created for each member variable which should be
0030  * interfaced. This object will automatically register itself with the
0031  * BaseRepository class.
0032  *
0033  * @see InterfacedBase
0034  * @see InterfaceBase
0035  * 
0036  */
0037 class ReferenceBase: public RefInterfaceBase {
0038 
0039 public:
0040 
0041   /**
0042    * Standard constructor.
0043    *
0044    * @param newName the name of the interface, may only contain
0045    * letters [a-zA-z0-9_].
0046    *
0047    * @param newDescription a brief description of the interface.
0048    *
0049    * @param newClassName the name of the corresponding class.
0050    *
0051    * @param newTypeInfo the type_info object of the corresponding
0052    * class.
0053    *
0054    * @param newRefClassName the name of the class pointed to.
0055    *
0056    * @param newRefTypeInfo the type_info object of the class pointed
0057    * to.
0058    *
0059    * @param depSafe set to true if calls to this interface for one
0060    * object does not influence other objects.
0061    *
0062    * @param readonly if this is set true the interface will not be
0063    * able to manipulate objects of the corresponding class, but will
0064    * still be able to access information.
0065    *
0066    * @param norebind if set to true, this interface is not responsible
0067    * for the rebinding of corresponding objects.
0068    *
0069    * @param nullable if set to true this corresponding references may
0070    * be null.
0071    *
0072    * @param defnull if set to true and a corresponding reference is
0073    * null it may be given a a default value in the initialization of
0074    * an EventGenerator.
0075    */
0076   ReferenceBase(string newName, string newDescription,
0077         string newClassName,
0078         const type_info & newTypeInfo, 
0079         string newRefClassName,
0080         const type_info & newRefTypeInfo, bool depSafe,
0081         bool readonly, bool norebind, bool nullable, bool defnull);
0082 
0083   /**
0084    * The general interface method overriding the one in
0085    * InterfaceBase. For this class, \a action can be any of "set" and
0086    * "get" and \a argument should correspond to the name of an
0087    * InterfacedBase object in the BaseRepository.
0088    */
0089   virtual string exec(InterfacedBase & ib, string action,
0090               string arguments) const;
0091 
0092   /**
0093    * Return a complete description of this reference.
0094    */
0095   virtual string fullDescription(const InterfacedBase & ib) const;
0096 
0097   /**
0098    * Return a code for the type of this reference.
0099    */
0100   virtual string type() const;
0101 
0102   /**
0103    * Return a string describing the type of interface to be included
0104    * in the Doxygen documentation.
0105    */
0106   virtual string doxygenType() const;
0107 
0108   /**
0109    * Set the pointer of \a ib to \a ip.
0110    */
0111   virtual void set(InterfacedBase & ib, IBPtr ip, bool chk = true)
0112     const = 0;
0113 
0114   /**
0115    * Return the pointer of \a ib.
0116    */
0117   virtual IBPtr get(const InterfacedBase & ib)
0118     const = 0;
0119 
0120   /**
0121    * Check if set(ib, ip) will be successfull but do not do
0122    * anything.
0123    */
0124   virtual bool check(const InterfacedBase & ib, cIBPtr ip) const
0125     = 0;
0126 
0127   /**
0128    * In the object \a ib, replace the pointer in this interface with one
0129    * of the translated ones provided by trans. If the pointer is null,
0130    * and defaultIfNull() is true, replace it with the first allowed
0131    * object found in \a defs.
0132    */
0133   virtual void rebind(InterfacedBase & ib, const TranslationMap & trans,
0134               const IVector & defs) const;
0135 
0136   /**
0137    * Return the pointer to another object in \a ib (in a vector).
0138    */
0139   virtual IVector getReferences(const InterfacedBase & ib) const;
0140 
0141 };
0142 
0143 
0144 /**
0145  * The Reference and its base class ReferenceBase defines an interface
0146  * to a class derived from the InterfacedBase, through which pointers
0147  * to other InterfacedBase objects may be manipulated.  Reference is
0148  * templated on the type of the class and the class of the objects
0149  * pointed to, and is derived from the InterfaceBase class via
0150  * ReferenceBase and RefInterfaceBase.
0151  *
0152  * For each InterfacedBase class exactly one static Reference object
0153  * should created for each member variable which should be
0154  * interfaced. This object will automatically register itself with the
0155  * BaseRepository class.
0156  *
0157  * @see InterfacedBase
0158  * @see InterfaceBase
0159  * 
0160  */
0161 template <class T, class R>
0162 class Reference: public ReferenceBase {
0163 
0164 public:
0165 
0166   /** A pointer to the class of objects referred to. */
0167   typedef typename Ptr<R>::pointer RefPtr;
0168   /** A const pointer to the class of objects referred to. */
0169   typedef typename Ptr<R>::const_pointer cRefPtr;
0170   /** A pointer to a menberfunction to be used for the 'set' action. */
0171   typedef void (T::*SetFn)(RefPtr);
0172   /** A pointer to a menberfunction to be used for the 'check' action. */
0173   typedef bool (T::*CheckFn)(cRefPtr) const;
0174   /** A pointer to a menberfunction to be used for the 'get' action. */
0175   typedef RefPtr (T::*GetFn)() const;
0176   /** Declaration of a direct pointer to the member variable. */
0177   typedef RefPtr T::* Member;
0178 
0179 public:
0180 
0181   /**
0182    * Standard constructor.
0183    *
0184    * @param newName the name of the interface, may only contain
0185    * letters [a-zA-z0-9_].
0186    *
0187    * @param newDescription a brief description of the interface.
0188    *
0189    * @param newMember a pointer to a Member which is a TypeVector. May
0190    * be null, in which case the pointers to member functions must be
0191    * specified.
0192    *
0193    * @param depSafe set to true if calls to this interface for one
0194    * object does not influence other objects.
0195    *
0196    * @param readonly if this is set true the interface will not be
0197    * able to manipulate objects of the corresponding class, but will
0198    * still be able to access information.
0199    *
0200    * @param rebind if set to true, this interface is responsible
0201    * for the rebinding of corresponding objects.
0202    *
0203    * @param nullable if set to true this corresponding references may
0204    * be null.
0205    *
0206    * @param newSetFn optional pointer to member function for the 'set'
0207    * action.
0208    *
0209    * @param newGetFn optional pointer to member function for the
0210    * 'get' action.
0211    *
0212    * @param newCheckFn optional pointer to member function for the
0213    * 'check' action.
0214    */
0215   Reference(string newName, string newDescription,
0216         Member newMember, bool depSafe = false,
0217         bool readonly = false, bool rebind = true, bool nullable = true,
0218         SetFn newSetFn = 0, GetFn newGetFn = 0,
0219         CheckFn newCheckFn = 0)
0220     : ReferenceBase(newName, newDescription,
0221             ClassTraits<T>::className(), typeid(T),
0222             ClassTraits<R>::className(), typeid(R),
0223             depSafe, readonly, !rebind, nullable, false),
0224       theMember(newMember), theSetFn(newSetFn), theGetFn(newGetFn),
0225       theCheckFn(newCheckFn) {}
0226 
0227   /**
0228    * Standard constructor.
0229    *
0230    * @param newName the name of the interface, may only contain
0231    * letters [a-zA-z0-9_].
0232    *
0233    * @param newDescription a brief description of the interface.
0234    *
0235    * @param newMember a pointer to a Member which is a TypeVector. May
0236    * be null, in which case the pointers to member functions must be
0237    * specified.
0238    *
0239    * @param depSafe set to true if calls to this interface for one
0240    * object does not influence other objects.
0241    *
0242    * @param readonly if this is set true the interface will not be
0243    * able to manipulate objects of the corresponding class, but will
0244    * still be able to access information.
0245    *
0246    * @param rebind if set to true, this interface is responsible
0247    * for the rebinding of corresponding objects.
0248    *
0249    * @param nullable if set to true this corresponding references may
0250    * be null.
0251    *
0252    * @param defnull if set to true and a corresponding reference is
0253    * null it may be given a a default value in the initialization of
0254    * an EventGenerator.
0255    *
0256    * @param newSetFn optional pointer to member function for the 'set'
0257    * action.
0258    *
0259    * @param newGetFn optional pointer to member function for the
0260    * 'get' action.
0261    *
0262    * @param newCheckFn optional pointer to member function for the
0263    * 'check' action.
0264    */
0265   Reference(string newName, string newDescription,
0266         Member newMember, bool depSafe, bool readonly, bool rebind,
0267         bool nullable, bool defnull, SetFn newSetFn = 0, GetFn newGetFn = 0,
0268         CheckFn newCheckFn = 0)
0269     : ReferenceBase(newName, newDescription,
0270             ClassTraits<T>::className(), typeid(T),
0271             ClassTraits<R>::className(), typeid(R),
0272             depSafe, readonly, !rebind, nullable, defnull),
0273       theMember(newMember), theSetFn(newSetFn), theGetFn(newGetFn),
0274       theCheckFn(newCheckFn) {}
0275 
0276 
0277   /**
0278    * Set the pointer of \a ib to \a ip.
0279    */
0280   virtual void set(InterfacedBase & ib, IBPtr ip, bool chk = true) const
0281    ;
0282 
0283   /**
0284    * Return the pointer of \a ib.
0285    */
0286   virtual IBPtr get(const InterfacedBase & ib) const
0287    ;
0288 
0289   /**
0290    * Check if set(ib, ip) will be successfull but do not do
0291    * anything.
0292    */
0293   virtual bool check(const InterfacedBase & ib, cIBPtr newRef) const
0294    ;
0295 
0296   /**
0297    * Give a pointer to a member function to be used by 'set()'.
0298    */
0299   void setSetFunction(SetFn sf) { theSetFn = sf; }
0300 
0301   /**
0302    * Give a pointer to a member function to be used by 'get()'.
0303    */
0304   void setGetFunction(GetFn gf) { theGetFn = gf; }
0305 
0306   /**
0307    * Give a pointer to a member function to be used by 'check()'.
0308    */
0309   void setCheckFunction(CheckFn cf) { theCheckFn = cf; }
0310 
0311 private:
0312 
0313   /**
0314    * The pointer to the member variable.
0315    */
0316   Member theMember;
0317 
0318   /**
0319    * A pointer to a member function to be used by 'set()'.
0320    */
0321   SetFn theSetFn;
0322 
0323   /**
0324    * Give a pointer to a member function to be used by 'get()'.
0325    */
0326   GetFn theGetFn;
0327 
0328   /**
0329    * Give a pointer to a member function to be used by 'check()'.
0330    */
0331   CheckFn theCheckFn;
0332 
0333 
0334 };
0335 
0336 }
0337 
0338 #include "Reference.tcc"
0339 
0340 #endif /* ThePEG_Reference_H */