00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #if !defined(__INCLUDE_ConsoleRuleMethodIAdapterh_INCLUDE__)
00022 #define __INCLUDE_ConsoleRuleMethodIAdapterh_INCLUDE__
00023
00024 #include <console/Console.h>
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 template<class T>
00035 class ConsoleRuleMethodIAdapter : public ConsoleRule
00036 {
00037 public:
00038 ConsoleRuleMethodIAdapter(T *inst,
00039 void (T::*call)(),
00040 const char *name) :
00041 ConsoleRule(name, std::vector<ConsoleRuleParam>()), inst_(inst), call_(call)
00042 {
00043 Console::instance()->addRule(this);
00044 };
00045
00046 ConsoleRuleMethodIAdapter(T *inst,
00047 void (T::*call)(),
00048 const char *name, const std::vector<ConsoleRuleParam> ¶ms) :
00049 ConsoleRule(name, params), inst_(inst), call_(call)
00050 {
00051 Console::instance()->addRule(this);
00052 };
00053 virtual ~ConsoleRuleMethodIAdapter()
00054 {
00055 Console::instance()->removeRule(this);
00056 };
00057
00058 virtual void runRule(
00059 Console *console,
00060 const char *wholeLine,
00061 std::vector<ConsoleRuleValue> &values)
00062 {
00063 (inst_->*call_)();
00064 };
00065
00066 protected:
00067 std::string name_;
00068 T *inst_;
00069 void (T::*call_)();
00070 };
00071
00072
00073 template<class T>
00074 class ConsoleRuleMethodIAdapterEx : public ConsoleRule
00075 {
00076 public:
00077 ConsoleRuleMethodIAdapterEx(T *inst,
00078 void (T::*call)(std::vector<ConsoleRuleValue>&),
00079 const char *name, const std::vector<ConsoleRuleParam> ¶ms) :
00080 ConsoleRule(name, params), inst_(inst), call_(call)
00081 {
00082 Console::instance()->addRule(this);
00083 };
00084 virtual ~ConsoleRuleMethodIAdapterEx()
00085 {
00086 Console::instance()->removeRule(this);
00087 };
00088
00089 virtual void runRule(
00090 Console *console,
00091 const char *wholeLine,
00092 std::vector<ConsoleRuleValue> &values)
00093 {
00094 (inst_->*call_)(values);
00095 };
00096
00097 protected:
00098 std::string name_;
00099 T *inst_;
00100 void (T::*call_)(std::vector<ConsoleRuleValue>&);
00101 };
00102
00103
00104 template<class T>
00105 class ConsoleRuleMethodIAdapterEx2 : public ConsoleRule
00106 {
00107 public:
00108 ConsoleRuleMethodIAdapterEx2(T *inst,
00109 void (T::*call)(std::vector<ConsoleRuleValue>&, unsigned int),
00110 const char *name, const std::vector<ConsoleRuleParam> ¶ms,
00111 unsigned int userData) :
00112 ConsoleRule(name, params, userData), inst_(inst), call_(call)
00113 {
00114 Console::instance()->addRule(this);
00115 };
00116 virtual ~ConsoleRuleMethodIAdapterEx2()
00117 {
00118 Console::instance()->removeRule(this);
00119 };
00120
00121 virtual void runRule(
00122 Console *console,
00123 const char *wholeLine,
00124 std::vector<ConsoleRuleValue> &values)
00125 {
00126 (inst_->*call_)(values, userData_);
00127 };
00128
00129 protected:
00130 std::string name_;
00131 T *inst_;
00132 void (T::*call_)(std::vector<ConsoleRuleValue>&, unsigned int);
00133 };
00134
00135 #endif
00136