OBT::Event< TSource > Class Template Reference

#include <OBTEvent.h>

Collaboration diagram for OBT::Event< TSource >:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 Event (const TSource &source)
virtual ~Event ()
const TSource & getSource () const

Private Attributes

const TSource * source_
 event emitter


Detailed Description

template<class TSource>
class OBT::Event< TSource >

Base class of all event objects
Author:
Michaël Rouillé <michael.rouille@gmail.com> All events derive from this class, which is responsible for knowing the source object of the event.
Example :

        class Producer ;

        // MyEvent
        class MyEvent : public Event< Producer >
        {
        public:

                MyEvent( const Producer& source ) 
                        : 
                Event< Producer >( source )
                {
                }
        } ;

        // IMyEventListener
        class IMyEventListener 
        {
        public:

                virtual void onMyEvent( const MyEvent& event ) = 0 ;
        } ;

        // Producer
        class Producer
        {
        public:

                Producer() 
                        :
                _myEventSource( &IMyEventListener::onMyEvent )
                {
                }

                void foo() 
                { 
                        _myEventSource.publishEvent( MyEvent( *this ) ) ;
                }


                void addMyEventListener( IMyEventListener& listener ) 
                { 
                        _myEventSource.addListener( listener ) ; 
                }

                void removeMyEventListener( IMyEventListener& listener ) 
                { 
                        _myEventSource.removeListener( listener ) ; 
                }

        private:

                EventSource< IMyEventListener, MyEvent > _myEventSource ;
        } ;

        // Consumer
        class Consumer : public IMyEventListener
        {
        public:

                virtual ~Consumer() 
                {
                }

        protected:

                void onMyEvent( const MyEvent& event )
                {
                        //do stuff
                }
        } ;

Definition at line 91 of file OBTEvent.h.


Constructor & Destructor Documentation

template<class TSource>
OBT::Event< TSource >::Event ( const TSource &  source  )  [inline]

constructor

Parameters:
source of the event (usually this)

Definition at line 122 of file OBTEvent.h.

00123                 :
00124         source_( &source )
00125         {
00126         }

template<class TSource>
OBT::Event< TSource >::~Event (  )  [inline, virtual]

destructor

Definition at line 132 of file OBTEvent.h.

00133         {
00134         }


Member Function Documentation

template<class TSource>
const TSource & OBT::Event< TSource >::getSource (  )  const [inline]

accessor to the emitter

Returns:
a const reference to the source of the event

Definition at line 141 of file OBTEvent.h.

References OBT::Event< TSource >::source_.

00142         {
00143                 return *source_ ;
00144         }


Member Data Documentation

template<class TSource>
const TSource* OBT::Event< TSource >::source_ [private]

event emitter

Definition at line 115 of file OBTEvent.h.

Referenced by OBT::Event< TSource >::getSource().


Generated on Wed Oct 1 11:34:18 2008 for OBT by  doxygen 1.5.3