|
|
|||
File indexing completed on 2026-08-06 09:38:27
0001 // -*- C++ -*- 0002 // 0003 // RefVector.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_RefVector_H 0010 #define ThePEG_RefVector_H 0011 // This is the declaration of the RefVector and RefVectorBase classes. 0012 0013 #include "ThePEG/Config/ThePEG.h" 0014 #include "InterfaceBase.h" 0015 #include "RefVector.xh" 0016 #include "RefVector.fh" 0017 0018 namespace ThePEG { 0019 0020 /** 0021 * The RefVector and its base class RefVectorBase defines an interface 0022 * to a class derived from the InterfacedBase, through which vectors 0023 * (or any other container) of pointers to other InterfacedBase 0024 * objects may be manipulated. RefVector is templated on the type of 0025 * the class and the class of the objects pointed to, and is derived 0026 * from the InterfaceBase class via RefVectorBase and 0027 * RefInterfaceBase. 0028 * 0029 * For each InterfacedBase class exactly one static RefVector object 0030 * should created for each member variable of container type which 0031 * should be interfaced. This object will automatically register 0032 * itself with the BaseRepository class. 0033 * 0034 * @see InterfacedBase 0035 * @see InterfaceBase 0036 * 0037 */ 0038 class RefVectorBase: public RefInterfaceBase { 0039 0040 public: 0041 0042 /** 0043 * Standard constructor. 0044 * 0045 * @param newName the name of the interface, may only contain 0046 * letters [a-zA-z0-9_]. 0047 * 0048 * @param newDescription a brief description of the interface. 0049 * 0050 * @param newClassName the name of the corresponding class. 0051 * 0052 * @param newTypeInfo the type_info object of the corresponding 0053 * class. 0054 * 0055 * @param newRefClassName the name of the class pointed to. 0056 * 0057 * @param newRefTypeInfo the type_info object of the class pointed 0058 * to. 0059 * 0060 * @param newSize the size of the container or -1 if varying. 0061 * 0062 * @param depSafe set to true if calls to this interface for one 0063 * object does not influence other objects. 0064 * 0065 * @param readonly if this is set true the interface will not be 0066 * able to manipulate objects of the corresponding class, but will 0067 * still be able to access information. 0068 * 0069 * @param norebind if set to true, this interface is not responsible 0070 * for the rebinding of corresponding objects. 0071 * 0072 * @param nullable if set to true this corresponding references may 0073 * be null. 0074 * 0075 * @param defnull if set to true and a corresponding reference is 0076 * null it may be given a a default value in the initialization of 0077 * an EventGenerator. 0078 */ 0079 RefVectorBase(string newName, string newDescription, 0080 string newClassName, 0081 const type_info & newTypeInfo, 0082 string newRefClassName, 0083 const type_info & newRefTypeInfo, 0084 int newSize, bool depSafe, 0085 bool readonly, bool norebind, bool nullable, bool defnull); 0086 0087 /** 0088 * The general interface method overriding the one in 0089 * InterfaceBase. For this class, \a action can be any of "set", 0090 * "get", "erase" and "insert" and \a argument should be a something 0091 * which can be read into an integer while the rest of \a argument 0092 * should correspond to the name of an InterfacedBase object in the 0093 * BaseRepository. 0094 */ 0095 virtual string exec(InterfacedBase & ib, string action, 0096 string arguments) const; 0097 0098 /** 0099 * Return a complete description of this reference vector. 0100 */ 0101 virtual string fullDescription(const InterfacedBase & ib) const; 0102 0103 /** 0104 * Return a code for the type of this reference. 0105 */ 0106 virtual string type() const; 0107 0108 /** 0109 * Return a string describing the type of interface to be included 0110 * in the Doxygen documentation. 0111 */ 0112 virtual string doxygenType() const; 0113 0114 /** 0115 * Set the \a i'th element of a container of pointers of \a ib 0116 * to \a ip. 0117 */ 0118 virtual void set(InterfacedBase & ib, IBPtr ip, int i, bool chk = true) 0119 const = 0; 0120 0121 /** 0122 * Insert a new pointer before the \a i'th element of a container of 0123 * pointers of \a ib and set it to \a ip. 0124 */ 0125 virtual void insert(InterfacedBase & ib, IBPtr ip, int i, bool chk = true) 0126 const = 0; 0127 0128 /** 0129 * Remove the \a i'th element of a container of pointers of \a ib. 0130 */ 0131 virtual void erase(InterfacedBase & ib, int i) 0132 const = 0; 0133 0134 /** 0135 * Clear the container of pointers of \a ib. 0136 */ 0137 virtual void clear(InterfacedBase & ib) 0138 const = 0; 0139 0140 /** 0141 * Return a vector of pointers corresponding to the container of 0142 * pointers of \a ib. 0143 */ 0144 virtual IVector get(const InterfacedBase & ib) const 0145 = 0; 0146 0147 /** 0148 * Check if set(ib, ip, i) will be successfull but do not do 0149 * anything. 0150 */ 0151 virtual bool check(const InterfacedBase & ib, cIBPtr ip, int i) const 0152 = 0; 0153 0154 /** 0155 * In the object \a ib, replace all pointers to objects in this 0156 * interface with the translated ones provided by \a trans. If a 0157 * pointer is null, and defaultIfNull() is true, replace it with 0158 * the first alowed object found in \a defs. 0159 */ 0160 virtual void rebind(InterfacedBase & ib, const TranslationMap & trans, 0161 const IVector & defs) const; 0162 0163 /** 0164 * Return pointers to other objects in \a ib. 0165 */ 0166 virtual IVector getReferences(const InterfacedBase & ib) const; 0167 0168 /** 0169 * Get the size of the container being interfaced. If the size() is 0170 * less than 0, the size is allowed to vary. 0171 */ 0172 int size() const { return theSize; } 0173 0174 /** 0175 * Set the size of the container being interfaced. If the size is 0176 * less than 0, the size is allowed to vary. 0177 */ 0178 void setSize(int sz) { theSize = sz; } 0179 0180 /** 0181 * Set the size of the container being interfaced to -1, i.e. the 0182 * size is allowed to vary. 0183 */ 0184 void setVariableSize() { theSize = 0; } 0185 0186 private: 0187 0188 /** 0189 * The size of the container being interfaced. 0190 */ 0191 int theSize; 0192 0193 }; 0194 0195 0196 /** 0197 * The RefVector and its base class RefVectorBase defines an interface 0198 * to a class derived from the InterfacedBase, through which vectors 0199 * (or any other container) of pointers to other InterfacedBase 0200 * objects may be manipulated. RefVector is templated on the type of 0201 * the class and the class of the objects pointed to, and is derived 0202 * from the InterfaceBase class via RefVectorBase and 0203 * RefInterfaceBase. 0204 * 0205 * For each InterfacedBase class exactly one static RefVector object 0206 * should created for each member variable of container type which 0207 * should be interfaced. This object will automatically register 0208 * itself with the BaseRepository class. 0209 * 0210 * @see InterfacedBase 0211 * @see InterfaceBase 0212 * 0213 */ 0214 template <class T, class R> 0215 class RefVector: public RefVectorBase { 0216 0217 public: 0218 0219 /** A pointer to the class of objects referred to. */ 0220 typedef typename Ptr<R>::pointer RefPtr; 0221 /** A const pointer to the class of objects referred to. */ 0222 typedef typename Ptr<R>::const_pointer cRefPtr; 0223 /** A pointer to a menberfunction to be used for the 'set' action. */ 0224 typedef void (T::*SetFn)(RefPtr, int); 0225 /** A pointer to a menberfunction to be used for the 'insert' action. */ 0226 typedef void (T::*InsFn)(RefPtr, int); 0227 /** A pointer to a menberfunction to be used for the 'erase' action. */ 0228 typedef void (T::*DelFn)(int); 0229 /** A pointer to a menberfunction to be used for the 'check' action. */ 0230 typedef bool (T::*CheckFn)(cRefPtr, int) const; 0231 /** A pointer to a menberfunction to be used for the 'get' action. */ 0232 typedef vector<RefPtr> (T::*GetFn)() const; 0233 /** 0234 * Declaration of a direct pointer to the member variable in case it 0235 * is a vector. 0236 */ 0237 typedef vector<RefPtr> T::* Member; 0238 0239 public: 0240 0241 /** 0242 * Standard constructor. 0243 * 0244 * @param newName the name of the interface, may only contain 0245 * letters [a-zA-z0-9_]. 0246 * 0247 * @param newDescription a brief description of the interface. 0248 * 0249 * @param newMember a pointer to a Member which is a TypeVector. May 0250 * be null, in which case the pointers to member functions must be 0251 * specified. 0252 * 0253 * @param newSize the size of the container or -1 if varying. 0254 * 0255 * @param depSafe set to true if calls to this interface for one 0256 * object does not influence other objects. 0257 * 0258 * @param readonly if this is set true the interface will not be 0259 * able to manipulate objects of the corresponding class, but will 0260 * still be able to access information. 0261 * 0262 * @param rebind if set to true, this interface is responsible 0263 * for the rebinding of corresponding objects. 0264 * 0265 * @param nullable if set to true this corresponding references may 0266 * be null. 0267 * 0268 * @param newSetFn optional pointer to member function for the 'set' 0269 * action. 0270 * 0271 * @param newInsFn optional pointer to member function for the 0272 * 'insert' action. 0273 * 0274 * @param newDelFn optional pointer to member function for the 0275 * 'erase' action. 0276 * 0277 * @param newGetFn optional pointer to member function for the 0278 * 'get' action. 0279 * 0280 * @param newCheckFn optional pointer to member function for the 0281 * 'check' action. 0282 */ 0283 RefVector(string newName, string newDescription, 0284 Member newMember, int newSize, bool depSafe = false, 0285 bool readonly = false, bool rebind = true, bool nullable = true, 0286 SetFn newSetFn = 0, InsFn newInsFn = 0, DelFn newDelFn = 0, 0287 GetFn newGetFn = 0, CheckFn newCheckFn = 0); 0288 0289 /** 0290 * Standard constructor. 0291 * 0292 * @param newName the name of the interface, may only contain 0293 * letters [a-zA-z0-9_]. 0294 * 0295 * @param newDescription a brief description of the interface. 0296 * 0297 * @param newMember a pointer to a Member which is a TypeVector. May 0298 * be null, in which case the pointers to member functions must be 0299 * specified. 0300 * 0301 * @param newSize the size of the container or -1 if varying. 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 rebind if set to true, this interface is 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 * @param newSetFn optional pointer to member function for the 'set' 0321 * action. 0322 * 0323 * @param newInsFn optional pointer to member function for the 0324 * 'insert' action. 0325 * 0326 * @param newDelFn optional pointer to member function for the 0327 * 'erase' action. 0328 * 0329 * @param newGetFn optional pointer to member function for the 0330 * 'get' action. 0331 * 0332 * @param newCheckFn optional pointer to member function for the 0333 * 'check' action. 0334 */ 0335 RefVector(string newName, string newDescription, 0336 Member newMember, int newSize, bool depSafe, 0337 bool readonly, bool rebind, bool nullable, bool defnull, 0338 SetFn newSetFn = 0, InsFn newInsFn = 0, DelFn newDelFn = 0, 0339 GetFn newGetFn = 0, CheckFn newCheckFn = 0); 0340 0341 /** 0342 * Set the \a i'th element of a container of pointers of \a ib 0343 * to \a ip. 0344 */ 0345 virtual void set(InterfacedBase & ib, IBPtr ip, int i, bool chk = true) 0346 const; 0347 0348 /** 0349 * Insert a new pointer before the \a i'th element of a container of 0350 * pointers of \a ib and set it to \a ip. 0351 */ 0352 virtual void insert(InterfacedBase & ib, IBPtr ip, int i, bool chk = true) 0353 const; 0354 0355 /** 0356 * Remove the \a i'th element of a container of pointers of \a ib. 0357 */ 0358 virtual void erase(InterfacedBase & ib, int i) 0359 const; 0360 0361 /** 0362 * Clear the container of pointers of \a ib. 0363 */ 0364 virtual void clear(InterfacedBase & ib) 0365 const; 0366 0367 /** 0368 * Return a vector of pointers corresponding to the container of 0369 * pointers of \a ib. 0370 */ 0371 virtual IVector get(const InterfacedBase & ib) const 0372 ; 0373 0374 /** 0375 * Check if set(ib, ip, i) will be successfull but do not do 0376 * anything. 0377 */ 0378 virtual bool check(const InterfacedBase & ib, cIBPtr, int i) const 0379 ; 0380 0381 /** 0382 * Give a pointer to a member function to be used by 'set()'. 0383 */ 0384 void setSetFunction(SetFn sf) { theSetFn = sf; } 0385 0386 /** 0387 * Give a pointer to a member function to be used by 'insert()'. 0388 */ 0389 void setInsertFunction(InsFn ifn) { theInsFn = ifn; } 0390 0391 /** 0392 * Give a pointer to a member function to be used by 'get()'. 0393 */ 0394 void setGetFunction(GetFn gf) { theGetFn = gf; } 0395 0396 /** 0397 * Give a pointer to a member function to be used by 'erase()'. 0398 */ 0399 void setEraseFunction(DelFn df) { theDelFn = df; } 0400 0401 /** 0402 * Give a pointer to a member function to be used by 'check()'. 0403 */ 0404 void setCheckFunction(CheckFn cf) { theCheckFn = cf; } 0405 0406 private: 0407 0408 /** 0409 * The pointer to the member variable. 0410 */ 0411 Member theMember; 0412 0413 /** 0414 * A pointer to a member function to be used by 'set()'. 0415 */ 0416 SetFn theSetFn; 0417 0418 /** 0419 * Give a pointer to a member function to be used by 'insert()'. 0420 */ 0421 InsFn theInsFn; 0422 0423 /** 0424 * Give a pointer to a member function to be used by 'erase()'. 0425 */ 0426 DelFn theDelFn; 0427 0428 /** 0429 * Give a pointer to a member function to be used by 'get()'. 0430 */ 0431 GetFn theGetFn; 0432 0433 /** 0434 * Give a pointer to a member function to be used by 'check()'. 0435 */ 0436 CheckFn theCheckFn; 0437 0438 }; 0439 0440 } 0441 0442 #include "RefVector.tcc" 0443 0444 #endif /* ThePEG_RefVector_H */
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|