Debian Codegraph @

src/gengine/BaseAgent.h

raw
1 #ifndef HEADER_BASEAGENT_H
2 #define HEADER_BASEAGENT_H
3
4 #include "NoCopy.h"
5 #include "BaseListener.h"
6 #include "ExInfo.h"
7 #include "NameException.h"
8 #include "AgentPack.h"
9
10 #include <string>
11
12 /**
13 * Ancestor for all agents.
14 */
15 class BaseAgent : public NoCopy, public BaseListener {
16 private:
17 bool m_initialized;
18 protected:
19 virtual void own_init() {}
20 virtual void own_update() {}
21 virtual void own_shutdown() {}
22 public:
23 BaseAgent();
24 virtual ~BaseAgent() {}
25 bool isInitialized() { return m_initialized; }
26
27 void init();
28 void update();
29 void shutdown();
30 };
31
32 /**
33 * Example: AGENT(VideoAgent, Name::VIDEO_NAME)
34 *
35 * Enables to obtain typed pointer
36 * static VideoAgent *VideoAgent::agent();
37 */
38 #define AGENT(TYPE, NAME) \
39 public: \
40 virtual const char *getName() const { return (NAME); } \
41 static TYPE *agent() \
42 { \
43 TYPE *result = dynamic_cast<TYPE *>(AgentPack::getAgent(sName())); \
44 if (NULL == result) { \
45 throw NameException(ExInfo("cannot cast agent") \
46 .addInfo("name", sName())); \
47 } \
48 return result; \
49 } \
50 private: \
51 static const char *sName() { return (NAME); }
52
53 #endif