00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 namespace cmil {
00027
00028 class InputNode : public SystemClient, Logger {
00029 public:
00030 typedef std::vector<InputNode* > NodeIndex;
00031
00032
00033 static InputNode* createRoot(System* sys, unsigned long int index_size) ;
00034
00035 InputNode* const createChild(bool indexing, int id);
00036 InputNode* const createChild(bool forced_index, const Ev& event);
00037
00038 bool deleteChild(int id);
00039
00040 NodeIndex getStandardIndex();
00041
00042 virtual ~InputNode() {
00043 std::ostringstream dtor_ss;
00044 dtor_ss << "calling InputNode dtor with m_id: " << m_id;
00045 log_debug(dtor_ss.str());
00046 cleanup();
00047 }
00048
00049 std::string getName() const {
00050 return "InputNode";
00051 }
00052
00053 unsigned long getTime() const {
00054 return m_time;
00055 }
00056
00057 unsigned long getTimeMargin() const {
00058 return m_time_margin;
00059 }
00060
00061 void setTime(unsigned long int time) {
00062 m_time = time;
00063 }
00064
00065 void setTimeMargin(unsigned long int time) {
00066 m_time_margin = time;
00067 }
00068
00069 NodeIndex* getIndex() const {
00070 return m_index;
00071 }
00072
00073
00074 InputNode* getChild(unsigned int id) {
00075 if(id <= m_index->size())
00076 return ((*m_index)[id]);
00077
00078 log_error("getChild() returning null due to bounds error");
00079 return NULL;
00080 }
00081
00082 int getChildren() const {
00083 int count = 0;
00084 if(m_index)
00085 for(InputNode::NodeIndex::iterator i = m_index->begin(); i != m_index->end(); ++i)
00086 if(*i) count++;
00087
00088 return count;
00089 }
00090
00091 InputAction* getAction() const {
00092 return m_action;
00093 }
00094
00095 void setAction(InputAction* action) {
00096 m_action = action;
00097 }
00098
00099 InputNode* getParent() const {
00100 return m_parent;
00101 }
00102
00103 int getID() const {
00104 return m_id;
00105 }
00106
00107 InputNode* getActiveChild() {
00108 return m_activechild;
00109 }
00110
00111 void setActiveChild(InputNode* node) {
00112 m_activechild = node;
00113 }
00114
00115
00116
00117 private:
00118
00119
00120
00121 InputNode(InputAction* action, System* const sys, const NodeIndex& index, InputNode* parent, const int id);
00122 InputNode(InputAction* action, System* const sys, InputNode* parent, const int id);
00123
00124
00125 void cleanup();
00126
00127 InputAction* m_action;
00128 const System* m_system;
00129 NodeIndex* m_index;
00130
00131 InputNode* const m_parent;
00132 const int m_id;
00133
00134 unsigned long m_time_margin;
00135 unsigned long m_time;
00136
00137
00138
00139
00140
00141 InputNode* m_activechild;
00142
00143
00144
00145 InputNode& operator=(const InputNode& );
00146 };
00147
00150
00151 class ComboHandler : public SystemClient, Logger {
00152 public:
00153 ComboHandler(System* const sys) : SystemClient(sys), m_root(NULL), m_controlling(NULL) {}
00154 virtual ~ComboHandler() { delete m_root; }
00155
00156 bool add(const Ev::Sequence& seq);
00157 virtual bool handle(const InputData& input);
00158
00159 bool isCombo(const Ev::Sequence& seq) const;
00160
00161 virtual std::string getName() const{ return "ComboHandler"; }
00162
00163
00164 private:
00165 bool canHandle(const InputData& input) const;
00166 bool Merge(const Ev::Sequence& seq);
00167 bool check_time(const InputNode* child) const;
00168
00169 const System* m_system;
00170
00172 InputNode* m_root;
00173
00175 InputNode* m_controlling;
00176 };
00177
00180
00181 class NormalHandler : public SystemClient, Logger {
00182 public:
00185 class NodeSequence {
00186 public:
00187 NodeSequence(InputNode* last) : m_last_node(last) {}
00188 InputNode* getLastNode() const { return m_last_node; }
00189
00190 private:
00191 InputNode* const m_last_node;
00192 };
00193
00194 typedef std::map<Ev::Sequence, NodeSequence* > AddedSequences;
00195
00196
00199
00200 NormalHandler(System* const sys) : SystemClient(sys), m_root(NULL) {}
00201 virtual ~NormalHandler() {
00202 delete m_root;
00203
00204 for(AddedSequences::iterator i = m_added_seq.begin(); i != m_added_seq.end() ; i++)
00205 delete (i->second);
00206 }
00207 virtual std::string getName() const { return "NormalHandler"; }
00208
00209 bool add(const Ev::Sequence& seq);
00210 bool remove(const Ev::Sequence& seq);
00211
00212 virtual bool handle(const InputData& input);
00213 virtual bool handle(const ModData& input);
00214 bool isNormal(const Ev::Sequence& seq) const;
00215
00216 private:
00217 bool canHandle(const InputData& input) const;
00218
00219 bool Merge(const Ev::Sequence& seq);
00220 bool unMerge(const Ev::Sequence& seq);
00221
00222 InputNode* HandleActivity(const ModData& input);
00223 InputNode* recurChildController(InputNode* const node);
00224 InputNode* recurParentController(InputNode* const node);
00225
00226 void RemoveControl(InputNode* node);
00227
00230 std::deque <InputNode* >::iterator m_i;
00231
00237 std::deque <InputNode* > m_controlnodes;
00238
00240 InputNode* m_root;
00241
00243 InputNode::NodeIndex m_active;
00244
00245 AddedSequences m_added_seq;
00246 };
00247
00248
00256
00257 class NodeSequencer : public InputSequencer {
00258 public:
00259 NodeSequencer(System* const sys) : m_chandler(sys), m_nhandler(sys) {}
00260
00261 virtual ~NodeSequencer() {}
00262
00263 std::string getName() const { return "NodeSequencer"; }
00264
00265 bool imp_handle(const ModData& input) {
00266 bool normal_success, combo_success;
00267
00268
00269 normal_success = m_nhandler.handle(input);
00270 combo_success = m_chandler.handle(input);
00271 return (combo_success || normal_success);
00272 }
00273
00274 bool imp_handle(const InputData& input) {
00275 bool normal_success, combo_success;
00276
00277
00278 normal_success = m_nhandler.handle(input);
00279 combo_success = m_chandler.handle(input);
00280 return (combo_success || normal_success);
00281 }
00282
00283 private:
00284 Ev::Sequence* capture(const ModData& input);
00285 bool imp_addNormal(const Ev::Sequence& seq) {
00286 return m_nhandler.add(seq);
00287 }
00288
00289 bool imp_removeNormal(const Ev::Sequence& seq) {
00290 return m_nhandler.remove(seq);
00291 }
00292
00293 bool imp_addCombo(const Ev::Sequence& seq) {
00294 return m_chandler.add(seq);
00295 }
00296
00297 bool isCombo(const Ev::Sequence& seq) const {
00298 return m_chandler.isCombo(seq);
00299 }
00300
00301 bool isNormal(const Ev::Sequence& seq) const {
00302 return m_nhandler.isNormal(seq);
00303 }
00304
00305 ComboHandler m_chandler;
00306 NormalHandler m_nhandler;
00307 };
00308 }