Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

BaseAgent.h

Go to the documentation of this file.
00001 #ifndef HEADER_BASEAGENT_H
00002 #define HEADER_BASEAGENT_H
00003 
00004 #include "NoCopy.h"
00005 #include "BaseListener.h"
00006 #include "ExInfo.h"
00007 #include "NameException.h"
00008 #include "AgentPack.h"
00009 
00010 #include <string>
00011 
00012 /**
00013  * Ancestor for all agents.
00014  */
00015 class BaseAgent : public NoCopy, public BaseListener {
00016     private:
00017         bool m_initialized;
00018     protected:
00019         virtual void own_init() {}
00020         virtual void own_update() {}
00021         virtual void own_shutdown() {}
00022     public:
00023         BaseAgent();
00024         virtual ~BaseAgent() {}
00025         bool isInitialized() { return m_initialized; }
00026 
00027         void init();
00028         void update();
00029         void shutdown();
00030 };
00031 
00032 /**
00033  * Example: AGENT(VideoAgent, Name::VIDEO_NAME)
00034  *
00035  * Enables to obtain typed pointer
00036  * static VideoAgent *VideoAgent::agent();
00037  */
00038 #define AGENT(TYPE, NAME) \
00039 public: \
00040 virtual const char *getName() const { return (NAME); } \
00041 static TYPE *agent() \
00042 { \
00043     TYPE *result = dynamic_cast<TYPE *>(AgentPack::getAgent(sName())); \
00044     if (NULL == result) { \
00045         throw NameException(ExInfo("cannot cast agent") \
00046                 .addInfo("name", sName())); \
00047     } \
00048     return result; \
00049 } \
00050 private: \
00051 static const char *sName() { return (NAME); }
00052 
00053 #endif

Generated on Wed Jun 1 09:54:30 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2