contrib/rpl/rgrl/rgrl_event.h
Go to the documentation of this file.
00001 #ifndef rgrl_event_h_
00002 #define rgrl_event_h_
00003 //:
00004 // \file
00005 // \brief   Base class for event
00006 // \author  Charlene Tsai
00007 // \date    April 2004
00008 
00009 #include <vbl/vbl_ref_count.h>
00010 #include <vcl_string.h>
00011 #include "rgrl_event_sptr.h"
00012 
00013 //: Event class provides a standard coding for sending and receiving messages.
00014 //
00015 // Common events are beginning of a process, end of a process, and end
00016 // of iteration.
00017 //
00018 // rgrl_event, together with rgrl_command and rgrl_object, implement
00019 // the Observer/Subject design patter. Observers (commands) register
00020 // their interest in particular kinds of events produced by a specific
00021 // rgrl_object.
00022 //
00023 class rgrl_event: public vbl_ref_count
00024 {
00025  public:
00026   //:
00027   rgrl_event() {}
00028 
00029   // copy constructor - compiler-provided one sets ref_count to nonzero which is wrong -PVr
00030   rgrl_event(rgrl_event const&) : vbl_ref_count() {}
00031 
00032   //:
00033   virtual ~rgrl_event() {}
00034 
00035   //: Return the string name associated with the event
00036   virtual vcl_string name(void) const = 0;
00037 
00038   virtual bool is_same_type(rgrl_event const& e) const = 0;
00039 };
00040 
00041 // Macro for creating new Events (from ITK)
00042 #define EventMacro( classname ) \
00043  class classname : public rgrl_event { \
00044   public: \
00045    classname() {} \
00046    classname(classname const& c) : rgrl_event(c) {} \
00047    virtual ~classname() {} \
00048    virtual vcl_string name() const { return #classname; } \
00049    virtual bool is_same_type(rgrl_event const& e) const \
00050      { rgrl_event const* p=&e; return dynamic_cast<classname const*>(p) ? true : false; } \
00051  }
00052 
00053 // Define some common events. To Add new type rgrl_event_X, simply add
00054 // the line "EventMacro( rgrl_event_X, rgrl_event )"
00055 //
00056 EventMacro( rgrl_event_start );
00057 EventMacro( rgrl_event_end );
00058 EventMacro( rgrl_event_iteration );
00059 EventMacro( rgrl_event_verification );
00060 EventMacro( rgrl_event_next_init );
00061 EventMacro( rgrl_matches_formed );
00062 
00063 #endif