00001 /* 00002 * Copyright (C) 2003-2009 Olivier Boudeville 00003 * 00004 * This file is part of the Ceylan library. 00005 * 00006 * The Ceylan library is free software: you can redistribute it and/or modify 00007 * it under the terms of either the GNU Lesser General Public License or 00008 * the GNU General Public License, as they are published by the Free Software 00009 * Foundation, either version 3 of these Licenses, or (at your option) 00010 * any later version. 00011 * 00012 * The Ceylan library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License and the GNU General Public License 00016 * for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License and the GNU General Public License along with the Ceylan library. 00020 * If not, see <http://www.gnu.org/licenses/>. 00021 * 00022 * Author: Olivier Boudeville (olivier.boudeville@esperide.com) 00023 * 00024 */ 00025 00026 00027 #include "CeylanInputDevice.h" 00028 00029 #include "CeylanController.h" // for Controller 00030 00031 #include "CeylanLogPlug.h" // for LogPlug 00032 #include "CeylanOperators.h" // for Ceylan::toString 00033 00034 #include <list> 00035 00036 00037 using std::string ; 00038 using std::list ; 00039 00040 00041 using namespace Ceylan ; 00042 using namespace Ceylan::Log ; 00043 00044 00045 00046 00047 InputDevice::InputDevice() : 00048 TextDisplayable(), 00049 _controller( 0 ) 00050 { 00051 00052 } 00053 00054 00055 00056 InputDevice::InputDevice( Controller & controller ) : 00057 TextDisplayable(), 00058 _controller( & controller ) 00059 { 00060 00061 } 00062 00063 00064 00065 InputDevice::~InputDevice() throw() 00066 { 00067 00068 // Controller not owned. 00069 00070 } 00071 00072 00073 00074 bool InputDevice::isLinkedToController() const 00075 { 00076 00077 return ( _controller != 0 ) ; 00078 00079 } 00080 00081 00082 00083 Controller & InputDevice::getController() const 00084 { 00085 00086 if ( _controller == 0 ) 00087 throw EventException( 00088 "InputDevice::getController: not linked to any controller." ) ; 00089 00090 return * _controller ; 00091 00092 } 00093 00094 00095 00096 void InputDevice::setController( Controller & controller ) 00097 { 00098 00099 if ( _controller != 0 ) 00100 throw EventException( 00101 "InputDevice::setController: already linked with controller " 00102 + _controller->toString() ) ; 00103 00104 _controller = & controller ; 00105 00106 } 00107 00108 00109 00110 bool InputDevice::dropController() 00111 { 00112 00113 if ( _controller != 0 ) 00114 { 00115 _controller = 0 ; 00116 return true ; 00117 } 00118 00119 return false ; 00120 00121 } 00122 00123 00124 00125 const string InputDevice::toString( Ceylan::VerbosityLevels level ) const 00126 { 00127 00128 if ( _controller == 0 ) 00129 return "Input device currently not linked to any controller" ; 00130 else 00131 return "Input device currently linked with following controller: " 00132 + _controller->toString( level ) ; 00133 00134 } 00135