00001 #ifndef rgrl_command_h_ 00002 #define rgrl_command_h_ 00003 //: 00004 // \file 00005 // \brief Base class for callback/observer method 00006 // \author Charlene Tsai 00007 // \date April 2004 00008 00009 #include <vbl/vbl_ref_count.h> 00010 class rgrl_object; 00011 class rgrl_event; 00012 00013 //: rgrl_command is an implementation of the command design pattern that is used in callbacks. 00014 // 00015 // rgrl_object implements the subject. When a subject needs to notify 00016 // an observer, it does so using a rgrl_command. The \a execute(.) 00017 // method is called to run the command. 00018 class rgrl_command: public vbl_ref_count 00019 { 00020 public: 00021 //: 00022 rgrl_command() {} 00023 00024 // copy constructor - compiler-provided one sets ref_count to nonzero which is wrong -PVr 00025 rgrl_command(rgrl_command const&) : vbl_ref_count() {} 00026 00027 //: 00028 virtual ~rgrl_command() {} 00029 00030 //: Abstract method that defines the action to be taken by the command 00031 virtual void execute(rgrl_object* caller, rgrl_event const& event ) = 0; 00032 00033 //: Abstract method that defines the action to be taken by the command. 00034 // 00035 // This variant is expected to be used when requests come from a 00036 // const rgrl_object 00037 virtual void execute(const rgrl_object* caller, rgrl_event const& event ) = 0; 00038 }; 00039 00040 #endif