CMS 3D CMS Logo

IgDispatcher.h

Go to the documentation of this file.
00001 #ifndef IGUANA_FRAMEWORK_IG_DISPATCHER_H
00002 # define IGUANA_FRAMEWORK_IG_DISPATCHER_H
00003 
00004 //<<<<<< INCLUDES                                                       >>>>>>
00005 
00006 # include "Iguana/Framework/interface/config.h"
00007 # include "classlib/utils/Callback.h"
00008 # include "classlib/utils/DebugAids.h"
00009 # include <vector>
00010 # include <algorithm>
00011 
00012 //<<<<<< PUBLIC DEFINES                                                 >>>>>>
00013 //<<<<<< PUBLIC CONSTANTS                                               >>>>>>
00014 //<<<<<< PUBLIC TYPES                                                   >>>>>>
00015 //<<<<<< PUBLIC VARIABLES                                               >>>>>>
00016 //<<<<<< PUBLIC FUNCTIONS                                               >>>>>>
00017 //<<<<<< CLASS DECLARATIONS                                             >>>>>>
00018 
00019 template <class Message>
00020 class IgDispatcher
00021 {
00022 public:
00023     typedef lat::Callback1<Message> Observer;
00024 
00025     IgDispatcher (void);
00026     // implicit copy constructor
00027     // implicit assignment operator
00028     // implicit destructor
00029 
00030     void                add (const Observer &listener);
00031     void                remove (const Observer &listener);
00032     void                broadcast (Message event) const;
00033 
00034 private:
00035     typedef std::vector<Observer>               List;
00036     typedef typename List::iterator             iterator;
00037     typedef typename List::const_iterator       const_iterator;
00038 
00039     List                m_list;
00040 };
00041 
00042 //<<<<<< INLINE PUBLIC FUNCTIONS                                        >>>>>>
00043 //<<<<<< INLINE MEMBER FUNCTIONS                                        >>>>>>
00044 
00045 template <class Message>
00046 inline
00047 IgDispatcher<Message>::IgDispatcher (void)
00048 {}
00049 
00050 template <class Message>
00051 inline void
00052 IgDispatcher<Message>::add (const Observer &listener)
00053 { m_list.push_back (listener); }
00054 
00055 template <class Message>
00056 inline void
00057 IgDispatcher<Message>::remove (const Observer &listener)
00058 {
00059     iterator pos = std::find (m_list.begin (), m_list.end(), listener);
00060     ASSERT (pos != m_list.end ());
00061     m_list.erase (pos);
00062 }
00063 
00064 template <class Message>
00065 inline void
00066 IgDispatcher<Message>::broadcast (Message event) const
00067 {
00068     for (const_iterator pos = m_list.begin (); pos != m_list.end (); ++pos)
00069         (*pos) (event);
00070 }
00071 
00072 #endif // IGUANA_FRAMEWORK_IG_DISPATCHER_H

Generated on Tue Jun 9 17:38:15 2009 for CMSSW by  doxygen 1.5.4