Homepage Demos Overview Downloads Tutorials Reference
Credits
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Search

BehaviorBase.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_BehaviorBase_h_
00003 #define INCLUDED_BehaviorBase_h_
00004 
00005 #include "Events/EventListener.h"
00006 #include "Shared/ReferenceCounter.h"
00007 #include <string>
00008 
00009 //! The basis from which all other Behaviors should inherit
00010 /*! Makes use of ReferenceCounter so that behaviors can automatically delete themselves if wanted\n
00011  *  Make sure your own DoStart and DoStop call BehaviorBase::DoStart (or Stop) to allow this behavior... otherwise you'll get memory leaks */
00012 class BehaviorBase : public ReferenceCounter, public EventListener {
00013  public:
00014   //! constructor
00015   BehaviorBase() : ReferenceCounter(), started(false) {}
00016   //! destructor - if is active when deleted, will call DoStop() first
00017   virtual ~BehaviorBase() { SetAutoDelete(false); if(started) DoStop();  } //{ if(started) { references++; DoStop(); references--; } }
00018   //! By default, merely adds to the reference counter (through AddReference()) @note you should still call this from your overriding methods
00019   virtual void DoStart() { if(!started) { started=true; AddReference(); } }
00020   //! By default, subtracts from the reference counter, and deletes if zero @note you should still call this when you override this @warning call this at the end of your DoStop(), not beginning (it might @c delete @c this )
00021   virtual void DoStop() { if(started) { started=false; RemoveReference(); } }
00022   //! Allows you to get away with not supplying a processEvent() function for the EventListener interface.  By default, does nothing.
00023   virtual void processEvent(const EventBase& /*event*/) {};
00024 
00025   
00026   //! Identifies the behavior in menus and such
00027   virtual std::string getName() const =0;
00028 
00029   //! Gives a short description of what this class of behaviors does... you should override this (but don't have to)
00030   static std::string getClassDescription() { return ""; }
00031 
00032   //! Gives a short description of what this particular instantiation does (in case a more specific description is needed)
00033   virtual std::string getDescription() const { return getClassDescription(); }
00034 
00035   //! Returns true if the behavior is currently running
00036   virtual bool isActive() const { return started; }
00037 
00038  protected:
00039   bool started; //!< true when the behavior is active
00040 };
00041 
00042 /*! @file
00043  * @brief Defines BehaviorBase from which all Behaviors should inherit
00044  * @author ejt (Creator)
00045  *
00046  * $Author: ejt $
00047  * $Name: tekkotsu-1_4_1 $
00048  * $Revision: 1.5 $
00049  * $State: Exp $
00050  * $Date: 2003/06/09 08:05:08 $
00051  */
00052 
00053 #endif

Tekkotsu v1.4
Generated Sat Jul 19 00:06:29 2003 by Doxygen 1.3.2