Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Command.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_Command_H
0010 #define ThePEG_Command_H
0011 // This is the declaration of the Command and CommandBase classes.
0012 
0013 #include "ThePEG/Config/ThePEG.h"
0014 #include "InterfaceBase.h"
0015 #include "Command.fh"
0016 #include "Command.xh"
0017 
0018 namespace ThePEG {
0019 
0020 /**
0021  * The CommandBase and its templated Command sub-class defines an
0022  * interface to a class derived from the InterfacedBase, through which
0023  * arbitratry command strings can be sent and
0024  * received. <code>Command</code> is templated and is derived from the
0025  * InterfaceBase class via <code>CommandBase</code>.
0026  *
0027  * For each command interface to be defined for a class
0028  * <code>T</code>, exactly one static object of the Command<T> must be
0029  * created and initialized as follows:
0030  *
0031  * <code>Command<T> comint(name, description, &T::memberfn,
0032  * depsafe);</code>
0033  *
0034  * Where <code>name</code> is an identifier <code>std::string</code> which
0035  * should only contain letters [a-zA-z0-9_], <code>description</code> is
0036  * an arbitrary <code>std::string</code>, <code>memberfn</code> should be
0037  * a non-static member function of <code>T</code> and defined as
0038  * <code>std::string T::memberfn(std::string)</code>. Finally if
0039  * <code>depsafe</code> is true it can be assumed that a call to the
0040  * <code>memberfn</code> for an object does not influence other objects
0041  * which may depend on the first.
0042  *
0043  * The <code>Command</code> class, as all other
0044  * InterfaceBase classes are mainly used in the
0045  * BaseRepository class.
0046  *
0047  *
0048  * @see InterfacedBase
0049  * @see InterfaceBase
0050  * @see BaseRepository
0051  * 
0052  */
0053 class CommandBase: public InterfaceBase {
0054 
0055 public:
0056 
0057   /**
0058    * Standard constructor.
0059    *
0060    * @param newName the name of the interface, may only contain
0061    * letters [a-zA-z0-9_].
0062    *
0063    * @param newDescription a brief description of the interface.
0064    *
0065    * @param newClassName the name of the corresponding class.
0066    *
0067    * @param newTypeInfo the type_info object of the corresponding
0068    * class.
0069    *
0070    * @param depSafe set to true if calls to this interface for one
0071    * object does not influence other objects.
0072    */
0073   CommandBase(string newName, string newDescription, string newClassName,
0074              const type_info & newTypeInfo, bool depSafe)
0075     : InterfaceBase(newName, newDescription, newClassName, 
0076             newTypeInfo, depSafe, false) {
0077     hasDefault = false;
0078   }
0079 
0080   /**
0081    * The general interface method overriding the one in
0082    * InterfaceBase. For this class, the \a action and \a argument
0083    * arguments are concatenated (with a space character inserted) and
0084    * sent to the cmd() function.
0085    */
0086   virtual string
0087   exec(InterfacedBase &ib, string action, string arguments) const
0088    ;
0089 
0090   /**
0091    * Return a string describing the type of interface to be included
0092    * in the Doxygen documentation.
0093    */
0094   virtual string doxygenType() const;
0095 
0096   /**
0097    * Return a code for the type of this interface.
0098    */
0099   virtual string type() const;
0100 
0101   /**
0102    * Execute the member function. For the object \a ib execute the
0103    * memberfunction (defined in the derived class) with \a c as
0104    * argument and return the return value.
0105    */
0106   virtual string cmd(InterfacedBase & ib, string c) const
0107     = 0;
0108 
0109 };
0110 
0111 /**
0112  * The CommandBase and its templated Command sub-class defines an
0113  * interface to a class derived from the InterfacedBase, through which
0114  * arbitratry command strings can be sent and
0115  * received. <code>Command</code> is templated and is derived from the
0116  * InterfaceBase class via <code>CommandBase</code>.
0117  *
0118  * For each command interface to be defined for a class
0119  * <code>T</code>, exactly one static object of the Command<T> must be
0120  * created and initialized as follows:
0121  *
0122  * <code>Command<T> comint(name, description, &T::memberfn,
0123  * depsafe);</code>
0124  *
0125  * Where <code>name</code> is an identifier <code>std::string</code> which
0126  * should only contain letters [a-zA-z0-9_], <code>description</code> is
0127  * an arbitrary <code>std::string</code>, <code>memberfn</code> should be
0128  * a non-static member function of <code>T</code> and defined as
0129  * <code>std::string T::memberfn(std::string)</code>. Finally if
0130  * <code>depsafe</code> is true it can be assumed that a call to the
0131  * <code>memberfn</code> for an object does not influence other objects
0132  * which may depend on the first.
0133  *
0134  * The <code>Command</code> class, as all other
0135  * InterfaceBase classes are mainly used in the
0136  * BaseRepository class.
0137  *
0138  *
0139  * @see InterfacedBase
0140  * @see InterfaceBase
0141  * @see BaseRepository
0142  * 
0143  */
0144 template <class T>
0145 class Command: public CommandBase {
0146 
0147 public:
0148 
0149   /**
0150    * The declaration of member functions which can be used by this
0151    * Command interface.
0152    */
0153   typedef string (T::*ExeFn)(string);
0154 
0155 public:
0156 
0157   /**
0158    * Standard constructor.
0159    *
0160    * @param newName the name of the interface, may only contain
0161    * letters [a-zA-z0-9_].
0162    *
0163    * @param newDescription a brief description of the interface.
0164    *
0165    * @param newExeFn pointer to the function to be called in the
0166    * corresponding class.
0167    *
0168    * @param depSafe set to true if calls to this interface for one
0169    * object does not influence other objects.
0170    */
0171   Command(string newName, string newDescription,
0172       ExeFn newExeFn, bool depSafe = false)
0173     : CommandBase(newName, newDescription, 
0174           ClassTraits<T>::className(), typeid(T), depSafe), 
0175       theExeFn(newExeFn) {}
0176 
0177   /**
0178    * Execute the member function. For the object \a ib execute the
0179    * memberfunction with \a c as argument and return the return value.
0180    */
0181   virtual string cmd(InterfacedBase & ib, string)
0182     const;
0183 
0184 
0185 private:
0186 
0187   /**
0188    * The pointer to the member function.
0189    */
0190   ExeFn theExeFn;
0191 
0192 };
0193 
0194 }
0195 
0196 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
0197 #include "Command.tcc"
0198 #endif
0199 
0200 #endif /* ThePEG_Command_H */