/* * DNN - Data News Network * * by Stephane Chatty * * Copyright 1993-1996 * Centre d'Etudes de la Navigation Aerienne (CENA) * * Reactions. * * $Id$ * $CurLog$ */ #ifndef IvlReaction_H_ #define IvlReaction_H_ #include "ivl/List.h" class IvlTrigger; class IvlEvent; class IvlBaseReaction { friend class IvlTrigger; public: enum REL_PRIORITY { isFirstPriority, isNormalPriority, isLastPriority }; protected: IvlBaseReaction (); IvlListOf Triggers; IvlListOf Grabbed; void Forget (IvlTrigger&); public: virtual ~IvlBaseReaction (); void SubscribeTo (IvlTrigger&, REL_PRIORITY = isNormalPriority); void UnsubscribeTo (IvlTrigger&); void Grab (IvlTrigger&); void Release (IvlTrigger&); virtual void Manage (IvlEvent&); }; typedef void (*IvlHandlingFunction) (IvlEvent&); class IvlCallback : public IvlBaseReaction { protected: IvlHandlingFunction Handler; public: IvlCallback (IvlHandlingFunction); ~IvlCallback (); void Manage (IvlEvent&); }; template class IvlReactionOf : public IvlBaseReaction { protected: T& Object; void (T::*Reaction) (IvlEvent&); public: IvlReactionOf (T& o, void (T::*r) (IvlEvent&)) : IvlBaseReaction (), Object (o), Reaction (r) {} ~IvlReactionOf () {} void Manage (IvlEvent& ev) { (Object.*Reaction) (ev); } }; #define SpecializedReaction(R,S) \ class R : public IvlBaseReaction { \ protected: \ S& Body; \ void (S::*React) (IvlEvent&); \ public: \ R (S& s, void (S::*sc) (IvlEvent&)) : IvlBaseReaction (), Body (s), React (sc) {} \ ~R () {} \ void Manage (IvlEvent& ev) { (Body.*React) (ev); } \ }; /* Attempt at having reactions that locate the object which should be activated. IvlObjectReactionOf should be renamed IvlReactionOf, and IvlReactionOf should be renamed IvlBasicReactionOf */ class IvlObjectReaction : public IvlBaseReaction { protected: virtual void* LocateObject (IvlEvent&) = 0; public: IvlObjectReaction () : IvlBaseReaction () {} ~IvlObjectReaction () {} }; template class IvlObjectReactionOf : public IvlObjectReaction { protected: void (T::*Reaction) (IvlEvent&); public: IvlObjectReactionOf (void (T::*r) (IvlEvent&)) : IvlObjectReaction (), Reaction (r) {} ~IvlObjectReactionOf () {} void Manage (IvlEvent& ev) { T* o = (T*) LocateObject (ev); (o->*Reaction) (ev); } }; #if 0 template class XtvReflexOf : public IvlObjectReactionOf { protected: void* LocateObject (IvlEvent& ev) { return ((XtvEvent*)&ev)->GetTarget (); } public: XtvReflexOf (void (T::*r) (IvlEvent&)) : IvlObjectReactionOf (r) {} }; #endif #endif /* IvlReaction_H_ */