Home Hierarchy Members Alphabetical Related Pages

event.h

Go to the documentation of this file.
00001 #ifndef XDKWRL_EVENT_H
00002 #define XDKWRL_EVENT_H
00003 
00004 #include <xdkwrl/fieldtypes.h>
00005 #include <list>
00006 
00007 namespace wrl
00008 {
00009   template <class T> class Route;
00010   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00011   // Interface of Event
00012   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00013   template <class T>
00014   class Event
00015   {
00016   public:
00017     inline FieldTypeId fieldTypeId() const;
00018     inline const char* fieldTypeName() const;
00019 
00020     typedef typename std::list<Route<T>*>::const_iterator route_const_iterator;
00021     inline unsigned int nbRoutes() const;
00022     inline route_const_iterator routes_begin() const;
00023     inline route_const_iterator routes_end() const;
00024   protected:
00025     friend class Route<T>;
00026     void add(Route<T>* r);
00027     void remove(Route<T>* r);
00028   private:
00029     std::list<Route<T>*> routes_;
00030   };
00031   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00032   // Interface of EventIn
00033   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00034   template <class T>
00035   class EventIn : public Event<T>
00036   {
00037   public:
00038   };
00039   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00040   // Interface of EventOut
00041   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00042   template <class T>
00043   class EventOut : public Event<T>
00044   {
00045   public:
00046   };
00047   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00048   // Interface of Route
00049   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00050   template <class T>
00051   class Route
00052   {
00053   public:
00054     Route(EventIn<T>& ei,EventOut<T>& eo);
00055     ~Route();
00056   private:
00057     EventIn<T>*  ei_;
00058     EventOut<T>* eo_;
00059   };
00060   //************************************************************
00061   // Implementation of Event
00062   //************************************************************
00063   template <class T>
00064   inline FieldTypeId
00065   Event<T>::fieldTypeId() const
00066   {
00067     return T::typeId();
00068   }
00069   template <class T>
00070   inline const char*
00071   Event<T>::fieldTypeName() const
00072   {
00073     return T::typeName();
00074   }
00075   template <class T>
00076   inline unsigned int
00077   Event<T>::nbRoutes() const
00078   {
00079     return routes_.size();
00080   }
00081   template <class T>
00082   inline typename Event<T>::route_const_iterator
00083   Event<T>::routes_begin() const
00084   {
00085     return routes_.begin();
00086   }
00087   template <class T>
00088   inline typename Event<T>::route_const_iterator
00089   Event<T>::routes_end() const
00090   {
00091     return routes_.end();
00092   }
00093   template <class T>
00094   void
00095   Event<T>::add(Route<T>* r)
00096   {
00097     routes_.push_back(r);
00098   }
00099   template <class T>
00100   void
00101   Event<T>::remove(Route<T>* r)
00102   {
00103     typename std::list<Route<T>*>::iterator iter = routes_.begin();
00104     while (iter != routes_.end() &&
00105            *iter != r)
00106     {
00107       ++iter;
00108     }
00109     if (iter != routes_.end())
00110     {
00111       routes_.erase(iter);
00112     }
00113   }
00114   //************************************************************
00115   // Implementation of Route
00116   //************************************************************
00117   template <class T>
00118   Route<T>::Route(EventIn<T>& ei,EventOut<T>& eo)
00119     : ei_(&ei),
00120       eo_(&eo)
00121   {
00122     ei.add(this);
00123     eo.ass(this);
00124   }
00125   template <class T>
00126   Route<T>::~Route()
00127   {
00128     ei_->remove(this);
00129     eo_->remove(this);
00130   }
00131 };
00132 #endif // XDKWRL_EVENT_H
00133 
00134 // Local variables section.
00135 // This is only used by emacs!
00136 // Local Variables:
00137 // ff-search-directories: ("." "../../src/xdkwrl/")
00138 // End:

Generated on 24 Feb 2005 with doxygen version 1.3.9.1. Valid HTML 4.0! Valid CSS!