00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <iostream>
00025 #include <map>
00026 #include <vector>
00027 #include <deque>
00028 #include <sstream>
00029
00030 #include <util/Singleton.h>
00031 #include <util/Logger.h>
00032
00033 #include <InputAction.h>
00034 #include <InputData.h>
00035 #include <InputEv.h>
00036 #include <InputDevice.h>
00037
00038 namespace cmil {
00039
00040 DeviceInputs::DeviceInputs(const Inputs& cloned_base, const Inputs& cloned_custom) {
00041 InputData* input_data = NULL;
00042
00043 Inputs::const_iterator i, i_custom;
00044 std::string custom_name;
00045
00046 for(i = cloned_base.begin(); i != cloned_base.end(); ++i) {
00048 input_data = (*i).second->clone();
00049
00050 std::pair<std::string, InputData* const> input_pair ( (*i).first, input_data );
00051 m_base.insert(input_pair);
00052 }
00053
00054 if(cloned_custom.size()) {
00055 if(cloned_custom.size() != cloned_base.size())
00056 log_error("DevceInputs(cloned_base, cloned_custom) : parameter indexes are not equal in size.");
00057 else {
00058 i_custom = cloned_custom.begin();
00059
00060 for(i = m_base.begin(); i != m_base.end(); ++i) {
00061 input_data = i->second;
00062
00063 std::pair<std::string, InputData* const> input_pair ((*i_custom).first, input_data);
00064 m_custom.insert(input_pair);
00065 ++i_custom;
00066 }
00067 }
00068 }
00069 }
00070
00072 void DeviceInputs::cleanup() {
00073 Inputs::iterator i;
00074 int dcount = 0;
00075
00076 for(i = m_base.begin() ; i != m_base.end() ; ++i) {
00077 if(i->second) {
00078 delete (i->second);
00079 dcount++;
00080 }
00081 }
00082
00083 std::ostringstream debug_ss;
00084 debug_ss << "cleanup() deleted memory consisting of : " << dcount << " addresses.";
00085 log_debug( debug_ss.str() );
00086 }
00087
00088 void DeviceInputs::dumpInputs() const {
00089 for( Inputs::const_iterator i = m_custom.begin(); i != m_custom.end(); ++i)
00090 log_debug( std::string("Dumping custom, input name: ").append( i->first ) );
00091 }
00092
00093 std::string DeviceInputs::getName() const {
00094 return "DeviceInputs";
00095 }
00096
00097 DeviceInputs* DeviceInputs::clone() const {
00098 log_debug("clone()");
00100 return new DeviceInputs(m_base, m_custom);
00101 }
00102
00103 void DeviceInputs::add(const std::string& device_name, InputData* input) {
00104 if(!input)
00105 log_error("add() passed null input");
00106 else {
00107 if( m_base.find(input->getName()) != m_base.end() )
00108 log_error(std::string("DeviceInputs::add() insertion of ").append(input->getName()).append(
00109 "failed due to pre-existing input of the same name"));
00110 else {
00111 input->setDevice(device_name);
00112 std::pair<std::string, InputData* const> input_pair (input->getName(), input);
00113
00114 m_base.insert(input_pair);
00115 }
00116 }
00117 }
00118
00120 bool DeviceInputs::erase(const std::string& name, Inputs& inputs) {
00121 if(inputs.find(name) == inputs.end()) {
00122 log_error("remove() tried to remove non-existant input");
00123 return false;
00124 }
00125 else {
00126 delete inputs[name];
00127 inputs.erase(name);
00128 }
00129
00130 return true;
00131 }
00132
00133 const DeviceInputs::Inputs& DeviceInputs::getInputs() const {
00134 return m_base;
00135 }
00136
00137 const DeviceInputs::Inputs& DeviceInputs::getCustomInputs() const {
00138 return m_custom;
00139 }
00140
00141
00142 bool DeviceInputs::remove(const std::string& name, Inputs& inputs) {
00143 if(inputs.find(name) == inputs.end()) {
00144 log_debug("remove() Tried to remove non-existant input.");
00145 return false;
00146 }
00147 else {
00148 inputs.erase(name);
00149 }
00150
00151 return true;
00152 }
00153
00154 InputData* const DeviceInputs::getData(const Inputs& inputs, const std::string& name) const {
00155 Inputs::const_iterator i = inputs.find(name);
00156
00157 if (i != inputs.end() ) {
00158
00159 return i->second;
00160 }
00161
00162 log_error(std::string("getData() returning NULL for string: ").append(name));
00163
00164
00165
00166
00167
00168 return NULL;
00169 }
00170
00171 InputData* const DeviceInputs::getData(bool base_data, const std::string& name) const {
00172 if(base_data || (m_custom.size() == 0)) {
00173
00174 return getData(m_base, name);
00175 }
00176
00177
00178 return getData(m_custom, name);
00179 }
00180
00181 bool DeviceInputs::operator==(const DeviceInputs& devinputs) const {
00182 const bool match_custom = true;
00183
00184 if(isEqual(match_custom, devinputs)) {
00185 log_debug("operator== match_inputs returning true");
00186 return true;
00187 }
00188
00189 log_error("operator== match_inputs returning false");
00190 return false;
00191 }
00192
00193 bool DeviceInputs::isEqual(bool match_custom, const DeviceInputs& devinputs) const {
00194 log_debug("isEqual()");
00195 bool is_equal = false;
00196 if(match_custom)
00197 is_equal = match_inputs(m_custom, devinputs.getCustomInputs());
00198
00199 is_equal = match_inputs(m_base, devinputs.getInputs());
00200 return is_equal;
00201 }
00202
00204 bool DeviceInputs::match_inputs(const Inputs& first, const Inputs& second) const {
00205 Inputs::const_iterator a, b;
00206
00207 if(first.size() != second.size())
00208 return false;
00209
00210 for(a = first.begin() ; a != first.end(); ++a) {
00211 b = second.find(a->first);
00212
00213 if(b == second.end()) {
00214 log_error( "match_inputs() returning false due to input name mismatch");
00215 return false;
00216 }
00217 else if ( typeid(*(a->second)) != typeid(*(b->second)) ) {
00218 log_error( "match_inputs() returning false due to type mismatch");
00219 return false;
00220 }
00221 }
00222
00223 return true;
00224 }
00225
00226 void DeviceInputs::removeInput(const std::string& name) {
00227 if(m_custom.size())
00228 remove(name, m_custom);
00229 erase(name, m_base);
00230 }
00231
00232 bool DeviceInputs::setInputs(const DeviceInputs& dev_inputs) {
00233 const bool match_base = false;
00234 std::string base_name, custom_name;
00235 Inputs::const_iterator i, i_custom;
00236
00238 if( !(isEqual(match_base, dev_inputs)) ) {
00239 log_error("setInputs() This operation isn't allowed due to DeviceInputs base mismatch");
00240 return false;
00241 }
00242 else {
00243 if(dev_inputs.getInputs().size() != dev_inputs.getCustomInputs().size()) {
00244 log_error("setInputs() This operation isn't allowed due to a mismatch in size of parameter inputs.");
00245 return false;
00246 }
00247 }
00248
00250 m_custom.clear();
00251
00254
00255 for(i = dev_inputs.getInputs().begin(); i != dev_inputs.getInputs().end(); ++i)
00256 setInput(i->first, i->second->getName());
00257
00258 return true;
00259 }
00260
00261 unsigned long int DeviceInputs::resetIDs( unsigned long int count ) {
00262 log_debug("resetting base IDs");
00263 Inputs::iterator i;
00264 for(i = m_base.begin(); i != m_base.end(); ++i)
00265 (i->second)->setID(count++);
00266
00267 return count;
00268 }
00269
00270 void DeviceInputs::resetWhichDevice( unsigned long int which_device) {
00271 Inputs::iterator i;
00272 for(i = m_base.begin(); i != m_base.end(); ++i)
00273 (i->second)->setWhichDevice(which_device);
00274 }
00275
00276 bool DeviceInputs::renameData(Inputs& inputs, const std::string& old_name, const std::string& new_name) {
00277 InputData* tmp_ptr = NULL;
00278 Inputs::iterator i;
00279
00280 if( inputs.find(new_name) != inputs.end() ) {
00281
00282 return false;
00283 }
00284 else if( ( (i = inputs.find(old_name)) == inputs.end()) ) {
00285 log_error("renameData() input to be renamed doesn't exist");
00286 return false;
00287 }
00288 else if(!(tmp_ptr= inputs[old_name])) {
00289 log_error("renameData() InputData found null at old_name");
00290 return false;
00291 }
00292
00294 log_debug(std::string("setting data old name: ").append(old_name).append(" to: ").append(new_name));
00295
00296 tmp_ptr -> setName(new_name);
00297
00299 inputs.erase(inputs.find(old_name));
00300
00302 std::pair<std::string, InputData* const> input_pair (new_name, tmp_ptr);
00303 inputs.insert(input_pair);
00304
00305 return true;
00306 }
00307
00308 bool DeviceInputs::setInput(const std::string& old_name, const std::string& new_name) {
00309 if(!m_custom.size())
00310 m_custom = m_base;
00311
00312 if( renameData(m_custom, old_name, new_name) )
00313 return true;
00314
00315
00316 return false;
00317 }
00318
00319 template <typename T> bool tInputIndex<T>::addData(InputData* input) {
00320 T* tmp_input_type;
00321
00322 if(!input) {
00323 log_error("addData(input) failed to add due to null input passed.");
00324 return false;
00325 }
00326 if ( (tmp_input_type = dynamic_cast<T*>(input)) != 0 ) {
00327 m_index.push_back(tmp_input_type);
00328 return true;
00329 }
00330 else {
00331 log_error("addData(input) failed to add due to casting failure.");
00332 return false;
00333 }
00334 }
00335
00336 template <typename T> void tInputIndex<T>::fill_indexes(const std::string& device_name,
00337 const std::string& input_name,
00338 unsigned int num,
00339 DeviceInputs& inputs) {
00340
00341 std::ostringstream numeral_ss;
00342 T* tmp_input;
00343
00344 for(unsigned int i = 0; i < num; ++i) {
00345 numeral_ss << input_name << i;
00346 tmp_input = new T(numeral_ss.str());
00347
00348 inputs.add(device_name, tmp_input);
00349
00350 addData(tmp_input);
00351
00352 numeral_ss.str("");
00353 }
00354
00355 InputData *input_d = NULL;
00356
00357 for(unsigned int i = 0; i < num; ++i) {
00358 numeral_ss << input_name << i;
00359 input_d = getData(i);
00360
00361 numeral_ss.str("");
00362 }
00363 }
00364
00365 template <typename T> unsigned int tInputIndex<T>::getSize() const {
00366 return m_index.size();
00367 }
00368
00369 template <typename T> T* tInputIndex<T>::getData(unsigned int i) const {
00370 if(i <= m_index.size())
00371 return m_index[i];
00372 return NULL;
00373 }
00374
00375 template <typename T> std::string tInputIndex<T>::getName() const {
00376 return "tInputIndex";
00377 }
00378
00379 template <typename T> bool tInputIndex<T>::operator==(const tInputIndex<T>& other) const {
00380 if(m_index.size() != other.m_index.size())
00381 return false;
00382 else
00383 for(unsigned int i = 0 ; i < m_index.size() ; ++i)
00384 if( typeid(*(m_index[i])) != typeid(*(other.m_index[i])) )
00385 return false;
00386
00387 return true;
00388 }
00389
00391 InputDevice::InputDevice() {};
00392
00393 InputDevice::InputDevice(const std::string& name, const DeviceInputs& cloned_inputs) :
00394 m_inputs(*(cloned_inputs.clone())), m_name(name) {};
00395
00396 InputDevice::InputDevice( const std::string& name) : m_name(name) {};
00397
00398 unsigned long int InputDevice::resetIDs( const unsigned long int count ) {
00399 log_debug("deferring resetIDs to m_inputs");
00400 return m_inputs.resetIDs(count);
00401 };
00402
00403 void InputDevice::resetWhichDevice( const unsigned long int which_device) {
00404 m_inputs.resetWhichDevice(which_device);
00405 };
00406
00407 void InputDevice::add(InputData* const input) {
00408 m_inputs.add(m_name, input);
00409 };
00410
00411 void InputDevice::removeInput(const std::string& name) {
00412 m_inputs.removeInput(name);
00413 };
00414
00415 bool InputDevice::setInput(const std::string& old_name, const std::string& new_name) {
00416 return m_inputs.setInput(old_name, new_name);
00417 };
00418
00420 bool InputDevice::setInputs(const InputDevice& dev) {
00421 return m_inputs.setInputs(dev.getInputs());
00422 };
00423
00424 void InputDevice::cleanup() {
00425 log_debug(std::string("cleanup() of device named: ").append(m_name));
00426 m_inputs.cleanup();
00427 };
00428
00429 InputDevice* InputDevice::clone() const {
00430 return new InputDevice(m_name, m_inputs);
00431 };
00432
00433 InputData* const InputDevice::getData(const std::string& name) const {
00435 return getData(DeviceInputs::use_base, name);
00436 };
00437
00438 const DeviceInputs& InputDevice::getInputs() const {
00439 return m_inputs;
00440 };
00441
00442 InputData* const InputDevice::getData(bool base_data, const std::string& name) const {
00443 return m_inputs.getData(base_data, name);
00444 };
00445
00446 bool InputDevice::operator==(const InputDevice& dev) const {
00447 log_debug("(base) operator== comparing input data");
00448 return ((m_name == dev.m_name) && (m_inputs == dev.m_inputs));
00449 };
00450
00453 void DeviceRegistry::clear() {
00454 log_debug("cleanup()");
00455 std::cout << "registry size: " << getSize() << std::endl;
00456 DeviceIndex::iterator di_iter;
00457 DeviceMultiple::iterator dm_iter;
00458 for(di_iter = m_index.begin() ; di_iter != m_index.end() ; ++di_iter)
00459 di_iter->second.clear();
00460 m_index.clear();
00461 }
00462
00464 void DeviceRegistry::cleanup() {
00465 log_debug("cleanup()");
00466 std::cout << "registry size: " << getSize() << std::endl;
00467 DeviceIndex::iterator di_iter;
00468 DeviceMultiple::iterator dm_iter;
00469 for(di_iter = m_index.begin() ; di_iter != m_index.end() ; ++di_iter)
00470 for(dm_iter = di_iter->second.begin() ; dm_iter != di_iter->second.end() ; ++dm_iter) {
00471 log_debug("calling dm_iter->cleanup()");
00472 dm_iter->cleanup();
00473 }
00474 };
00475
00476 std::string DeviceRegistry::getDefaultDevice() const {
00477 return m_default_device;
00478 };
00479
00480 InputData* const DeviceRegistry::getData(unsigned int id) const {
00481 if(id <= m_inputs.size())
00482 return m_inputs[id];
00483
00484 log_error("getData(id) bounds error, returnning NULL");
00485 return NULL;
00486 };
00487
00488 InputData* const DeviceRegistry::getData(const Ev& event) const {
00489 std::string name;
00490
00491 if((name = event.getDeviceName()) == "") {
00492 name = getDefaultDevice();
00493 log_debug(std::string("getData() setting name to default: ").append(name));
00494 }
00495 if(name == "")
00496 log_error("getData() returning null since no default device is available.");
00497 else {
00498 log_debug(std::string("getData() for device name: ").append(name));
00499
00500
00502 DeviceIndex::const_iterator i = m_index.find(name);
00503
00504 std::ostringstream size_ss;
00505
00506 if(i != m_index.end())
00507 if(i->second.size() >= event.getDeviceMultiple()) {
00508 size_ss << "getData() number of devices with name: " << i->second.size();
00509 log_debug(size_ss.str());
00510
00512 return i->second[event.getDeviceMultiple()].getData(DeviceInputs::use_custom, event.getName());
00513 }
00514 }
00515
00516 log_error("getData() returning null");
00517 return NULL;
00518 };
00519
00520 int DeviceRegistry::getID(const Ev& event) const {
00521 if(getData(event)) {
00522 log_debug("getID() found data matching event, returning id");
00523 return getData(event)->getID();
00524 }
00525 else {
00526 log_error("getID() no id found in registry which matched id");
00527 return 0;
00528 }
00529 };
00530
00531 int DeviceRegistry::getSize() const{
00532 return m_inputs.size();
00533 };
00534
00536 void DeviceRegistry::mergeRegistry(DeviceRegistry& reg) {
00537 log_debug("mergeRegistery() ");
00538 for(DeviceIndex::iterator di_iter = reg.m_index.begin() ; di_iter != reg.m_index.end() ; ++di_iter)
00539 for(DeviceMultiple::iterator dm_iter = di_iter->second.begin() ; dm_iter != di_iter->second.end() ; ++dm_iter) {
00540 registerDevice(*dm_iter);
00541 log_debug(std::string("mergeRegistery() calling registerDevice() with name: ").append((*dm_iter).getName()));
00542 }
00543 };
00544
00546 void DeviceRegistry::registerDevice(InputDevice& dev) {
00547 DeviceIndex::iterator i;
00548
00550 if( (i=m_index.find(dev.getName())) == m_index.end()) {
00553
00554 log_debug(std::string("registerDevice() adding device named: ").append(dev.getName()));
00555
00557 if(m_index.empty()) {
00558 log_debug(std::string("registerDevice() setting default device to: ").append(dev.getName()));
00559 m_default_device = dev.getName();
00560 }
00561 copyDevice(dev);
00562 }
00563 else {
00565 if ( *(i->second.begin()) == dev) {
00566 log_debug(std::string("registerDevices() registering another device of the same type and name: ").append(dev.getName()));
00567
00568 copyDevice(dev);
00569 }
00570 else {
00571 log_error(std::string("registerDevices() not adding device of the same name and type: ").append(dev.getName()).
00572 append("due to member unequality."));
00573 }
00574 }
00575 }
00576
00577 void DeviceRegistry::copyDevice(InputDevice& dev) {
00578 DeviceInputs::Inputs::const_iterator i;
00579 int which_device;
00580
00582 log_debug("copyDevice(): copying device");
00583 m_index[dev.getName()].push_back(dev);
00584
00585 which_device = m_index[dev.getName()].size();
00586
00587
00588
00589 dev.resetIDs(m_inputs.size());
00590 dev.resetWhichDevice(which_device);
00591
00592 for(i = dev.getInputs().getCustomInputs().begin(); i != dev.getInputs().getCustomInputs().end(); ++i)
00594 m_inputs.push_back(i->second);
00595
00596 }
00597
00598 GameController::GameController(const std::string& name,
00599 unsigned int axes,
00600 unsigned int buttons,
00601 unsigned int balls,
00602 unsigned int hats)
00603 : InputDevice(name) {
00604 m_axes.fill_indexes (name, "axis", axes, m_inputs);
00605 m_buttons.fill_indexes (name, "button", buttons, m_inputs);
00606 m_balls.fill_indexes (name, "ball", balls, m_inputs);
00607 m_hats.fill_indexes (name, "hat", hats, m_inputs);
00608 }
00609
00610 InputDevice* GameController::clone() const {
00611 log_debug("clone() ");
00613 InputDevice* clone = new GameController(getName(), m_axes.getSize(), m_buttons.getSize(), m_balls.getSize(), m_hats.getSize());
00614
00616 clone->setInputs( *this );
00617
00618 log_debug("clone() returning clone");
00619 return clone;
00620 };
00621
00622 bool GameController::operator==(const GameController& controller) const {
00623 log_debug("operator==");
00624 if ((m_axes == controller.m_axes) ||
00625 (m_buttons == controller.m_buttons) ||
00626 (m_balls == controller.m_balls) ||
00627 (m_hats == controller.m_hats)) {
00628 log_debug("operator== returning false due to member mismatch");
00629 return false;
00630 }
00631
00632 return ((getName() == controller.getName()) && (m_inputs == controller.getInputs()));
00633 };
00634
00635 Keyboard::Keyboard(const std::string& name) : InputDevice(name) {
00636 log_debug("Keyboard constructing");
00637 init_inputs();
00638 };
00639
00640 Keyboard::Keyboard() : InputDevice("Keyboard") {
00641 init_inputs();
00642 };
00643
00644 void Keyboard::init_inputs() {
00645
00646 add(new Press("Escape"));
00647 add(new Press("F1")); add(new Press("F2"));
00648 add(new Press("F3")); add(new Press("F4"));
00649 add(new Press("F5")); add(new Press("F6"));
00650 add(new Press("F7")); add(new Press("F8"));
00651 add(new Press("F9")); add(new Press("F10"));
00652 add(new Press("F11")); add(new Press("F12"));
00653
00654 add(new Press("Print")); add(new Press("Scroll Lock"));
00655 add(new Press("Pause"));
00656
00657
00658 add(new Press("1")); add(new Press("Exclaimation Mark"));
00659 add(new Press("2")); add(new Press("@"));
00660 add(new Press("3")); add(new Press("Hash"));
00661 add(new Press("4")); add(new Press("Dollar Sign"));
00662 add(new Press("5")); add(new Press("Percent"));
00663 add(new Press("6")); add(new Press("Caret"));
00664 add(new Press("7")); add(new Press("Ampersand"));
00665 add(new Press("8")); add(new Press("Asterisk"));
00666 add(new Press("9")); add(new Press("Left Parenthesis"));
00667 add(new Press("0")); add(new Press("Right Parenthesis"));
00668 add(new Press("Minus")); add(new Press("Underscore"));
00669 add(new Press("Plus")); add(new Press("Equals"));
00670 add(new Press("Backspace"));
00671
00672 add(new Press("Q")); add(new Press("W")); add(new Press("E"));
00673 add(new Press("R")); add(new Press("T")); add(new Press("Y"));
00674 add(new Press("U")); add(new Press("I")); add(new Press("O"));
00675 add(new Press("P")); add(new Press("A")); add(new Press("S"));
00676 add(new Press("D")); add(new Press("F")); add(new Press("G"));
00677 add(new Press("H")); add(new Press("J")); add(new Press("K"));
00678 add(new Press("L")); add(new Press("Z")); add(new Press("X"));
00679 add(new Press("C")); add(new Press("V")); add(new Press("B"));
00680 add(new Press("N")); add(new Press("M"));
00681
00682
00683 add(new Press("Tab"));
00684 add(new Press("Capslock"));
00685
00686 add(new Press("Less Than")); add(new Press("Comma"));
00687 add(new Press("Greater Than")); add(new Press("Period"));
00688
00689 add(new Press("Left Shift"));
00690 add(new Press("Right Shift"));
00691 add(new Press("Shift"));
00692
00693 add(new Press("Left Ctrl"));
00694 add(new Press("Right Ctrl"));
00695 add(new Press("Ctrl"));
00696
00697 add(new Press("Left Alt"));
00698 add(new Press("Right Alt"));
00699 add(new Press("Alt"));
00700
00701 add(new Press("Return"));
00702 add(new Press("Space"));
00703
00704 add(new Press("Insert"));
00705 add(new Press("Home"));
00706 add(new Press("Page Up"));
00707 add(new Press("Delete"));
00708 add(new Press("End"));
00709 add(new Press("Page Down"));
00710
00711 add(new Press("Left"));
00712 add(new Press("Right"));
00713 add(new Press("Up"));
00714 add(new Press("Down"));
00715
00716 add(new Press("NumLock"));
00717 add(new Press("Keypad Forward Slash"));
00718 add(new Press("Keypad Asterisk"));
00719 add(new Press("Keypad Minus "));
00720 add(new Press("Keypad Plus"));
00721 add(new Press("Keypad Enter"));
00722
00723 add(new Press("Keypad Zero")); add(new Press("Keypad Insert"));
00724 add(new Press("Keypad Period")); add(new Press("Keypad Delete"));
00725
00726 add(new Press("Keypad Left")); add(new Press("Keypad 4"));
00727 add(new Press("Keypad Right")); add(new Press("Keypad 6"));
00728 add(new Press("Keypad Up")); add(new Press("Keypad 8"));
00729 add(new Press("Keypad Down")); add(new Press("Keypad 2"));
00730
00731 add(new Press("Keypad Home")); add(new Press("Keypad 7"));
00732 add(new Press("Keypad Page Up")); add(new Press("Keypad 9"));
00733 add(new Press("Keypad Page Down")); add(new Press("Keypad 3"));
00734 add(new Press("Keypad End")); add(new Press("Keypad 1"));
00735 add(new Press("Keypad 5"));
00736
00737 add(new Press("Foward Slash")); add(new Press("Question Mark"));
00738 add(new Press("|")); add(new Press("Back Slash"));
00739 add(new Press("Right Bracket"));
00740 add(new Press("Left Bracket"));
00741 add(new Press("Backquote"));
00742 add(new Press("Colon")); add(new Press("Semi Colon"));
00743 add(new Press("Double Quote")); add(new Press("Quote"));
00744 };
00745
00746 bool Keyboard::operator==(const Keyboard& keyboard) const {
00747 log_debug("(Keyboard) operator== Keyboard& ");
00748 return (m_inputs == keyboard.getInputs());
00749 };
00750
00751 InputDevice* Keyboard::clone() const {
00752 InputDevice* clone = new Keyboard(getName());
00753 clone->setInputs( *this );
00754 return clone;
00755 };
00756
00757 Mouse::Mouse(const std::string& name,
00758 unsigned int buttons,
00759 unsigned int coords) :
00760 InputDevice(name) {
00761 init_inputs( name, buttons, coords );
00762 }
00763
00764 void Mouse::init_inputs(const std::string& name, unsigned int buttons, unsigned int coords) {
00765 m_buttons.fill_indexes(name, "button", buttons, m_inputs);
00766 m_coords.fill_indexes(name, "coord", coords, m_inputs);
00767 };
00768
00769 InputDevice* Mouse::clone() const {
00770 log_debug( "Mouse clone()" );
00771
00772 InputDevice* clone = new Mouse(getName(), m_buttons.getSize(), m_coords.getSize());
00773
00775 clone->setInputs( *this );
00776 log_debug("clone() returning clone");
00777 return clone;
00778 }
00779
00780 bool Mouse::operator==(const Mouse& mouse) const {
00781 log_debug("(Mouse) operator== Mouse& ");
00782
00783 if(!(m_buttons == mouse.m_buttons) && (m_coords == mouse.m_coords))
00784 return false;
00785
00786 if ( ( m_inputs.getInputs() == mouse.getInputs().getInputs()) )
00787 return false;
00788 return true;
00789 };
00790 }