00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef ThePEG_HandlerGroup_H
00010 #define ThePEG_HandlerGroup_H
00011
00012
00013 #include "ThePEG/Config/ThePEG.h"
00014
00015
00016
00017 namespace ThePEG {
00018
00044 class HandlerGroupBase {
00045
00046 public:
00047
00049 typedef pair<StepHdlPtr, HintPtr> StepWithHint;
00050
00052 typedef vector<StepHdlPtr> StepVector;
00053
00055 typedef vector<StepWithHint> StepHintVector;
00056
00058 typedef deque<HintPtr> HintVector;
00059
00060 public:
00061
00065 HandlerGroupBase();
00066
00070 virtual ~HandlerGroupBase();
00071
00075 bool empty() const { return isEmpty; }
00076
00082 void init(const HandlerGroupBase & ext) {
00083 clear();
00084 refillDefaults(ext);
00085 }
00086
00090 StepWithHint next();
00091
00098 void addPreHandler(tStepHdlPtr sh, tHintPtr hint,
00099 const HandlerGroupBase & ext);
00100
00107 void addPostHandler(tStepHdlPtr sh, tHintPtr hint,
00108 const HandlerGroupBase &);
00109
00115 void addHint(tHintPtr hint, const HandlerGroupBase & ext);
00116
00120 StepVector & preHandlers() { return theDefaultPreHandlers; }
00121
00125 const StepVector & preHandlers() const { return theDefaultPreHandlers; }
00126
00130 virtual tStepHdlPtr defaultHandler() const = 0;
00131
00135 StepVector & postHandlers() { return theDefaultPostHandlers; }
00136
00140 const StepVector & postHandlers() const { return theDefaultPostHandlers; }
00141
00145 virtual tStepHdlPtr handler() const = 0;
00146
00150 virtual void setHandler() = 0;
00151
00156 virtual bool setHandler(tStepHdlPtr, const HandlerGroupBase & ext) = 0;
00157
00162 virtual void refillDefaultHandler(tStepHdlPtr) = 0;
00163
00168 void refillDefaults(const HandlerGroupBase &);
00169
00173 virtual void clear();
00174
00178 virtual string handlerClass() const = 0;
00179
00183 void interfaceSetPrehandler(StepHdlPtr p, int i);
00184
00188 void interfaceInsertPrehandler(StepHdlPtr p, int i);
00189
00193 void interfaceErasePrehandler(int i);
00194
00198 vector<StepHdlPtr> interfaceGetPrehandlers() const;
00199
00203 void interfaceSetPosthandler(StepHdlPtr p, int i);
00204
00208 void interfaceInsertPosthandler(StepHdlPtr p, int i);
00209
00213 void interfaceErasePosthandler(int i);
00214
00218 vector<StepHdlPtr> interfaceGetPosthandlers() const;
00219
00223 virtual void write(PersistentOStream &) const;
00224
00228 virtual void read(PersistentIStream &);
00229
00230 protected:
00231
00235 HandlerGroupBase(const HandlerGroupBase &);
00236
00240 bool isEmpty;
00241
00242 private:
00243
00248 void checkInsert(StepHintVector & current, const StepVector & def);
00249
00250 protected:
00251
00255 StepVector theDefaultPreHandlers;
00256
00260 StepVector theDefaultPostHandlers;
00261
00265 StepHintVector thePreHandlers;
00266
00270 HintVector theHints;
00271
00275 StepHintVector thePostHandlers;
00276
00277 private:
00278
00282 HandlerGroupBase & operator=(const HandlerGroupBase &);
00283
00284 };
00285
00320 template <typename HDLR>
00321 class HandlerGroup: public HandlerGroupBase {
00322
00323 public:
00324
00326 typedef typename Ptr<HDLR>::pointer HdlPtr;
00327
00329 typedef typename Ptr<HDLR>::transient_pointer tHdlPtr;
00330
00331 public:
00332
00336 virtual ~HandlerGroup();
00337
00342 virtual bool setHandler(tStepHdlPtr, const HandlerGroupBase & ext);
00343
00347 virtual void setHandler() { theHandler = HdlPtr(); }
00348
00352 virtual tStepHdlPtr handler() const {
00353 return dynamic_ptr_cast<tStepHdlPtr>(theHandler);
00354 }
00355
00359 virtual tStepHdlPtr defaultHandler() const {
00360 return dynamic_ptr_cast<tStepHdlPtr>(theDefaultHandler);
00361 }
00362
00367 virtual void refillDefaultHandler(tStepHdlPtr);
00368
00372 virtual void clear();
00373
00377 virtual string handlerClass() const;
00378
00382 void interfaceSetHandler(HdlPtr);
00383
00387 HdlPtr interfaceGetHandler() const;
00388
00392 virtual void write(PersistentOStream & os) const {
00393 os << theDefaultHandler << theHandler;
00394 HandlerGroupBase::write(os);
00395 }
00396
00400 virtual void read(PersistentIStream & is) {
00401 is >> theDefaultHandler >> theHandler;
00402 HandlerGroupBase::read(is);
00403 }
00404
00405 private:
00406
00407
00411 HdlPtr theDefaultHandler;
00412
00416 HdlPtr theHandler;
00417
00418 private:
00419
00423 HandlerGroup<HDLR> & operator=(const HandlerGroup<HDLR> &);
00424
00425 };
00426
00428 namespace Group {
00429
00433 enum Handler {
00434 subproc,
00435 cascade,
00436 multi,
00437 hadron,
00438 decay
00439 };
00440
00442 enum Level {
00443 before,
00444 main,
00445 after
00446 };
00447 }
00448
00450 template <typename HDLR>
00451 inline PersistentOStream & operator<<(PersistentOStream & os,
00452 const HandlerGroup<HDLR> & hg) {
00453 hg.write(os);
00454 return os;
00455 }
00456
00458 template <typename HDLR>
00459 inline PersistentIStream & operator>>(PersistentIStream & is,
00460 HandlerGroup<HDLR> & hg) {
00461 hg.read(is);
00462 return is;
00463 }
00464
00465 }
00466
00468 #define ThePEG_DECLARE_PREPOST_GROUP(HandlerClass,prepost) \
00469 \
00470 void interfaceSet##prepost##HandlerClass(StepHdlPtr, int); \
00471 \
00472 void interfaceInsert##prepost##HandlerClass(StepHdlPtr, int); \
00473 \
00474 void interfaceErase##prepost##HandlerClass(int); \
00475 \
00476 vector<StepHdlPtr> interfaceGet##prepost##HandlerClass() const
00477
00479 #define ThePEG_DECLARE_GROUPINTERFACE(HandlerClass,ptr) \
00480 ThePEG_DECLARE_PREPOST_GROUP(HandlerClass,Pre); \
00481 \
00482 void interfaceSet##HandlerClass(ptr); \
00483 \
00484 ptr interfaceGet##HandlerClass() const; \
00485 ThePEG_DECLARE_PREPOST_GROUP(HandlerClass,Post)
00486
00488 #define ThePEG_IMPLEMENT_PREPOST_GROUP(ThisClass,HandlerClass,member,pp) \
00489 void ThisClass::interfaceSet##pp##HandlerClass(StepHdlPtr p , int i) { \
00490 member.interfaceSet##pp##handler(p,i); \
00491 } \
00492 void ThisClass::interfaceInsert##pp##HandlerClass(StepHdlPtr p, int i) { \
00493 member.interfaceInsert##pp##handler(p,i); \
00494 } \
00495 void ThisClass::interfaceErase##pp##HandlerClass(int i) { \
00496 member.interfaceErase##pp##handler(i); \
00497 } \
00498 vector<StepHdlPtr> ThisClass::interfaceGet##pp##HandlerClass() const { \
00499 return member.interfaceGet##pp##handlers(); \
00500 }
00501
00503 #define ThePEG_IMPLEMENT_GROUPINTERFACE(ThisClass,HandlerClass,member,ptr) \
00504 ThePEG_IMPLEMENT_PREPOST_GROUP(ThisClass,HandlerClass,member,Pre) \
00505 void ThisClass::interfaceSet##HandlerClass(ptr p) { \
00506 member.interfaceSetHandler(p); \
00507 } \
00508 ptr ThisClass::interfaceGet##HandlerClass() const { \
00509 return member.interfaceGetHandler(); \
00510 } \
00511 ThePEG_IMPLEMENT_PREPOST_GROUP(ThisClass,HandlerClass,member,Post) \
00512
00513
00514 #define ThePEG_DECLARE_PREPOST_OBJECTS(ThisClass,HandlerClass,pp,ba) \
00515 static RefVector<ThisClass,StepHandler> interface##pp##HandlerClass \
00516 (#pp #HandlerClass "s", \
00517 "A list of handlers to be called " #ba " the " #HandlerClass ". " \
00518 "If handler objects are specified in a EventHandler and " \
00519 "the SubProcessHandler chosen in a given collision also specifies some, " \
00520 "the latter will caled first.", \
00521 0, 0, false, false, true, false, \
00522 &ThisClass::interfaceSet##pp##HandlerClass, \
00523 &ThisClass::interfaceInsert##pp##HandlerClass, \
00524 &ThisClass::interfaceErase##pp##HandlerClass, \
00525 &ThisClass::interfaceGet##pp##HandlerClass)
00526
00528 #define ThePEG_DECLARE_GROUPINTERFACE_OBJECTS(ThisClass,HandlerClass) \
00529 ThePEG_DECLARE_PREPOST_OBJECTS(ThisClass,HandlerClass,Pre, before); \
00530 static Reference<ThisClass,HandlerClass> interface ## HandlerClass \
00531 (#HandlerClass, \
00532 "The " #HandlerClass " object used in this " #ThisClass ". " \
00533 "If a " #HandlerClass " object is specified in a EventHandler and " \
00534 "the SubProcessHandler chosen in a given collision also specifies one," \
00535 "the latter will be used.", \
00536 0, false, false, true, true, \
00537 &ThisClass::interfaceSet ## HandlerClass, \
00538 &ThisClass::interfaceGet ## HandlerClass); \
00539 ThePEG_DECLARE_PREPOST_OBJECTS(ThisClass,HandlerClass,Post, after)
00540
00541 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
00542 #include "HandlerGroup.tcc"
00543 #endif
00544
00545 #endif