|
|
|||
File indexing completed on 2026-08-06 09:38:26
0001 // -*- C++ -*- 0002 // 0003 // InterfaceBase.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_InterfaceBase_H 0010 #define ThePEG_InterfaceBase_H 0011 // This is the declaration of the InterfaceBase and RefInterfaceBase classes. 0012 0013 #include "ThePEG/Config/ThePEG.h" 0014 #include "InterfaceBase.fh" 0015 #include "InterfaceBase.xh" 0016 #include "ThePEG/Utilities/Named.h" 0017 #include "ThePEG/Utilities/ClassTraits.h" 0018 #include "Interface.h" 0019 0020 namespace ThePEG { 0021 0022 /** 0023 * The InterfaceBase class defines a generic interface to any class 0024 * derived from the InterfacedBase class. Using the pure virtual 0025 * exec() function, it is possible to manipulate any InterfacedBase 0026 * object. InterfaceBase is an abstract base class for derived classes 0027 * such as Command, Parameter and Reference. 0028 * 0029 * InterfaceBase objects are managed by the BaseRepository. 0030 * 0031 * InterfaceBase is derived from the Named to manage the name of the 0032 * interface. 0033 * 0034 * From the Repository it is possible to generate a file with doxygen 0035 * comments which can be included in the documentation describing the 0036 * InterfaceBase objects defined for a class. For each class, 0037 * <code>ClassName</code>, there will be produced a file called 0038 * <code>ClassNameInterfaces.html</code> which can be referred to with 0039 * a standard html <code>href</code> anchor. Also a specific 0040 * interface, <code>InterfaceName</code> can be referred to with 0041 * <code>ClassNameInterfaces.html#InterfaceName</code>. The file can 0042 * also be referred to with the doxygen <code>\\ref</code> 0043 * command. Inside the description of an interface, other interfaces 0044 * in the same class can be tagged with 0045 * \<interface\>InterfaceName\</interface\> or, if the interface 0046 * belongs to another class, 0047 * \<interface\>ClassName::InterfaceName\</interface\>. By running the 0048 * script in <code>ThePEG/Doc/fixinterfaces.pl</code> these tags will 0049 * be converted to proper <code>href</code> anchors. 0050 * 0051 * @see InterfacedBase 0052 * @see Command 0053 * @see Parameter 0054 * @see Reference 0055 * @see BaseRepository 0056 * @see Named 0057 * 0058 */ 0059 class InterfaceBase: public Named { 0060 0061 public: 0062 0063 /** 0064 * Standard constructor. 0065 * 0066 * @param newName the name of the interface, may only contain 0067 * letters [a-zA-z0-9_]. 0068 * 0069 * @param newDescription a brief description of the interface. 0070 * 0071 * @param newClassName the name of the corresponding class. 0072 * 0073 * @param newTypeInfo the type_info object of the corresponding 0074 * class. 0075 * 0076 * @param depSafe set to true if calls to this interface for one 0077 * object does not influence other objects. 0078 * 0079 * @param readonly if this is set true the interface will not be 0080 * able to manipulate objects of the corresponding class, but will 0081 * still be able to access information. 0082 */ 0083 InterfaceBase(string newName, string newDescription, 0084 string newClassName, 0085 const type_info & newTypeInfo, bool depSafe, 0086 bool readonly); 0087 0088 /** 0089 * The destructor. 0090 */ 0091 virtual ~InterfaceBase() {} 0092 0093 /** 0094 * Create a tag for this interface using its name and optional 0095 * poisitional argument. 0096 */ 0097 string tag(int pos = -1) const; 0098 0099 /** 0100 * Manipulate an object of the corresponding class. Execute the \a 0101 * action command with the given \a arguments for the given object 0102 * \a ib. 0103 */ 0104 virtual string 0105 exec(InterfacedBase & ib, string action, string arguments) const 0106 = 0; 0107 0108 /** 0109 * Return a code for the type of this interface. 0110 */ 0111 virtual string type() const = 0; 0112 0113 /** 0114 * Returns true if the setting for this interface has been changed 0115 * from its default value. 0116 */ 0117 virtual bool notDefault(InterfacedBase &) const; 0118 0119 /** 0120 * Returns the map of objectDefaults of the given object. 0121 */ 0122 map<string,string> & objectDefaults(InterfacedBase &) const; 0123 0124 /** 0125 * Rebind all references in ib according to the translation 0126 * map. Only used by derived classed interfacing references. 0127 */ 0128 virtual void rebind(InterfacedBase &, 0129 const TranslationMap &, 0130 const IVector & = IVector()) const {} 0131 0132 /** 0133 * For derived classes interfacing references between Interfaced 0134 * objects, return the references for this interface. 0135 */ 0136 virtual IVector getReferences(const InterfacedBase &) const { 0137 return IVector(); 0138 } 0139 0140 /** 0141 * Return the description of this interface. 0142 */ 0143 string description() const { return theDescription; } 0144 0145 /** 0146 * Return a complete description of this interface. 0147 */ 0148 virtual string fullDescription(const InterfacedBase & ib) const; 0149 0150 /** 0151 * Print a description to be included in the Doxygen documentation 0152 * to the given \a stream. 0153 */ 0154 virtual void doxygenDescription(ostream & stream) const; 0155 0156 /** 0157 * Return a string describing the type of interface to be included 0158 * in the Doxygen documentation. 0159 */ 0160 virtual string doxygenType() const = 0; 0161 0162 /** 0163 * Return the class name for the class this interface is defined 0164 * for. 0165 */ 0166 string className() const { return theClassName; } 0167 0168 /** 0169 * Get the flag saying whether changing an object with this 0170 * interface may change the state of a dependent object . 0171 */ 0172 bool dependencySafe() const { return isDependencySafe; } 0173 0174 /** 0175 * Set the flag saying whether changing an object with this 0176 * interface may change the state of a dependent object . 0177 */ 0178 void setDependencySafe() { isDependencySafe = true; } 0179 0180 /** 0181 * Set the flag saying whether changing an object with this 0182 * interface may change the state of a dependent object . 0183 */ 0184 void setDependencySensitive() { isDependencySafe = false; } 0185 0186 /** 0187 * Get the flag saying whether this interface is allowed to change 0188 * an object. 0189 */ 0190 bool readOnly() const { return isReadOnly && (!NoReadOnly); } 0191 0192 /** 0193 * Set the flag saying that this interface is allowed to 0194 * change an object. 0195 */ 0196 void setReadOnly() { isReadOnly = true; } 0197 0198 /** 0199 * Unset the flag saying that this interface is allowed to change an 0200 * object. 0201 */ 0202 void setReadWrite() { isReadOnly = false; } 0203 0204 /** 0205 * Return true if this interface is anonyous, ie. invisible for the 0206 * user interface. 0207 */ 0208 bool anonymous() const { return description().empty(); } 0209 0210 /** 0211 * Get the rank for this interface. Used for sorting by user 0212 * interface. 0213 */ 0214 double rank() const { return theRank; } 0215 0216 /** 0217 * Set the rank for this interface. Used for sorting by user 0218 * interface. 0219 */ 0220 void rank(double r) { theRank = r; } 0221 0222 /** 0223 * Indicate that this interface has a default value. 0224 */ 0225 void setHasDefault(bool b) { 0226 hasDefault = b; 0227 } 0228 0229 /** 0230 * If set to true, all read-only interfaces can be changed. 0231 */ 0232 static bool NoReadOnly; 0233 0234 private: 0235 0236 /** 0237 * The description of this interface. 0238 */ 0239 string theDescription; 0240 0241 /** 0242 * The class name and for the class this interface is defined for. 0243 */ 0244 string theClassName; 0245 0246 /** 0247 * A rank assigned to this interface. Used for sorting by user 0248 * interface. 0249 */ 0250 double theRank; 0251 0252 protected: 0253 0254 /** 0255 * A flag indicating whether this interface has a default setting. 0256 */ 0257 bool hasDefault; 0258 0259 /** 0260 * The flag saying whether changing an object with this interface 0261 * may change the state of a dependent object . 0262 */ 0263 mutable bool isDependencySafe; 0264 0265 /** 0266 * The flag saying whether this interface is allowed to change an 0267 * object. 0268 */ 0269 mutable bool isReadOnly; 0270 0271 0272 }; 0273 0274 0275 /** 0276 * RefInterfaceBase is an abstract base class inheriting from 0277 * InterfaceBase used for subclasses dealing with interfaces to do 0278 * with references in one Interfaced object to another. 0279 */ 0280 class RefInterfaceBase: public InterfaceBase { 0281 0282 public: 0283 0284 /** 0285 * Standard constructor. 0286 * 0287 * @param newName the name of the interface, may only contain 0288 * letters [a-zA-z0-9_]. 0289 * 0290 * @param newDescription a brief description of the interface. 0291 * 0292 * @param newClassName the name of the corresponding class. 0293 * 0294 * @param newTypeInfo the type_info object of the corresponding 0295 * class. 0296 * 0297 * @param newRefClassName the name of the class referred to by the 0298 * corresponding class.. 0299 * 0300 * @param newRefTypeInfo the type_info object of the class referred 0301 * to by the corresponding class. 0302 * 0303 * @param depSafe set to true if calls to this interface for one 0304 * object does not influence other objects. 0305 * 0306 * @param readonly if this is set true the interface will not be 0307 * able to manipulate objects of the corresponding class, but will 0308 * still be able to access information. 0309 * 0310 * @param norebind if set to true, this interface is not responsible 0311 * for the rebinding of corresponding objects. 0312 * 0313 * @param nullable if set to true this corresponding references may 0314 * be null. 0315 * 0316 * @param defnull if set to true and a corresponding reference is 0317 * null it may be given a a default value in the initialization of 0318 * an EventGenerator. 0319 */ 0320 RefInterfaceBase(string newName, string newDescription, 0321 string newClassName, const type_info & newTypeInfo, 0322 string newRefClassName, 0323 const type_info & newRefTypeInfo, 0324 bool depSafe, bool readonly, 0325 bool norebind, bool nullable, bool defnull); 0326 0327 /** 0328 * Return the class name of the class referred to by 0329 * this interface. 0330 */ 0331 string refClassName() const { return theRefClassName; } 0332 0333 /** 0334 * Return the type_info object of the class referred to by this 0335 * interface. 0336 */ 0337 const type_info & refTypeInfo() const { return theRefTypeInfo; } 0338 0339 /** 0340 * Get the flag saying whether the interface is responsible for 0341 * rebinding of the corresponding refenerces. 0342 */ 0343 bool noRebind() const { return dontRebind; } 0344 0345 /** 0346 * Set the flag saying that the interface is not responsible for 0347 * rebinding refenerces. 0348 */ 0349 void setNoRebind() { dontRebind = true; } 0350 0351 /** 0352 * Set the flag saying that the interface is responsible for 0353 * rebinding refenerces. 0354 */ 0355 void setRebind() { dontRebind = false; } 0356 0357 /** 0358 * Get the flag saying whether the interface is allowed to set the 0359 * reference to null. 0360 */ 0361 bool noNull() const { return !isNullable; } 0362 0363 /** 0364 * Set the flag saying that the interface it is allowed to set the 0365 * reference to null. 0366 */ 0367 void setNullable() { isNullable = true; } 0368 0369 /** 0370 * Set the flag saying that the interface it is not allowed to set 0371 * the reference to null. 0372 */ 0373 void setNotNullable() { isNullable = false; } 0374 0375 /** 0376 * Get the flag saying wether a null pointer should be replaced by a 0377 * default of suitable class when rebind is called. 0378 */ 0379 bool defaultIfNull() const { return theDefaultIfNull; } 0380 0381 /** 0382 * Set the flag saying that a null pointer should be replaced by a 0383 * default of suitable class when rebind is called. 0384 */ 0385 void setDefaultIfNull() { theDefaultIfNull = true; } 0386 0387 /** 0388 * Set the flag saying that a null pointer should not be replaced by 0389 * a default of suitable class when rebind is called. 0390 */ 0391 void setNoDefaultIfNull() { theDefaultIfNull = false; } 0392 0393 private: 0394 0395 /** 0396 * The class name of the class referred to by this 0397 * interface. 0398 */ 0399 string theRefClassName; 0400 0401 /** 0402 * The type_info object of the class referred to by this interface. 0403 */ 0404 const type_info & theRefTypeInfo; 0405 0406 /** 0407 * The flag saying whether the interface is responsible for 0408 * rebinding refenerces. 0409 */ 0410 bool dontRebind; 0411 0412 /** 0413 * The flag saying whether the interface is allowed to set a 0414 * reference to null. 0415 */ 0416 bool isNullable; 0417 0418 /** 0419 * The flag saying wether a null pointer should be replaced 0420 * by a default of suitable class when rebind is called. 0421 */ 0422 bool theDefaultIfNull; 0423 0424 }; 0425 0426 /** Dummy function to ensure that strings can be used as arguments 0427 * also where numbers are assumed. */ 0428 inline double operator/(string,string) { return 0.0; } 0429 0430 /** Dummy function to ensure that strings can be used as arguments 0431 * also where numbers are assumed. */ 0432 inline string operator*(double,string) { return ""; } 0433 0434 } 0435 0436 #endif /* ThePEG_InterfaceBaseH */
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|