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

Generated on 5 Jan 2007 with doxygen version 1.5.1. Valid HTML 4.0! Valid CSS!