summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface/Device.cpp
diff options
context:
space:
mode:
authorJasper St. Pierre <jstpierre@mecheye.net>2013-12-07 15:14:29 -0500
committerJasper St. Pierre <jstpierre@mecheye.net>2013-12-31 14:03:19 -0500
commit34692ab826abc8f8faa61bdb2280b742424528f1 (patch)
treeb0eedc645badbea316ff59c125eaf808b28777ec /Source/Core/InputCommon/ControllerInterface/Device.cpp
parent43e618682e8093602fc83dfa902ee7ae3fd3a4f6 (diff)
Remove unnecessary Src/ folders
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/Device.cpp')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/Device.cpp193
1 files changed, 193 insertions, 0 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/Device.cpp b/Source/Core/InputCommon/ControllerInterface/Device.cpp
new file mode 100644
index 0000000000..965ecfc817
--- /dev/null
+++ b/Source/Core/InputCommon/ControllerInterface/Device.cpp
@@ -0,0 +1,193 @@
+
+#include "Device.h"
+
+#include <string>
+#include <sstream>
+
+namespace ciface
+{
+namespace Core
+{
+
+//
+// Device :: ~Device
+//
+// Destructor, delete all inputs/outputs on device destruction
+//
+Device::~Device()
+{
+ {
+ // delete inputs
+ std::vector<Device::Input*>::iterator
+ i = m_inputs.begin(),
+ e = m_inputs.end();
+ for ( ;i!=e; ++i)
+ delete *i;
+ }
+
+ {
+ // delete outputs
+ std::vector<Device::Output*>::iterator
+ o = m_outputs.begin(),
+ e = m_outputs.end();
+ for ( ;o!=e; ++o)
+ delete *o;
+ }
+}
+
+void Device::AddInput(Device::Input* const i)
+{
+ m_inputs.push_back(i);
+}
+
+void Device::AddOutput(Device::Output* const o)
+{
+ m_outputs.push_back(o);
+}
+
+Device::Input* Device::FindInput(const std::string &name) const
+{
+ std::vector<Input*>::const_iterator
+ it = m_inputs.begin(),
+ itend = m_inputs.end();
+ for (; it != itend; ++it)
+ if ((*it)->GetName() == name)
+ return *it;
+
+ return NULL;
+}
+
+Device::Output* Device::FindOutput(const std::string &name) const
+{
+ std::vector<Output*>::const_iterator
+ it = m_outputs.begin(),
+ itend = m_outputs.end();
+ for (; it != itend; ++it)
+ if ((*it)->GetName() == name)
+ return *it;
+
+ return NULL;
+}
+
+//
+// Device :: ClearInputState
+//
+// Device classes should override this function
+// ControllerInterface will call this when the device returns failure during UpdateInput
+// used to try to set all buttons and axes to their default state when user unplugs a gamepad during play
+// buttons/axes that were held down at the time of unplugging should be seen as not pressed after unplugging
+//
+void Device::ClearInputState()
+{
+ // this is going to be called for every UpdateInput call that fails
+ // kinda slow but, w/e, should only happen when user unplugs a device while playing
+}
+
+//
+// DeviceQualifier :: ToString
+//
+// get string from a device qualifier / serialize
+//
+std::string DeviceQualifier::ToString() const
+{
+ if (source.empty() && (cid < 0) && name.empty())
+ return "";
+ std::ostringstream ss;
+ ss << source << '/';
+ if ( cid > -1 )
+ ss << cid;
+ ss << '/' << name;
+ return ss.str();
+}
+
+//
+// DeviceQualifier :: FromString
+//
+// set a device qualifier from a string / unserialize
+//
+void DeviceQualifier::FromString(const std::string& str)
+{
+ std::istringstream ss(str);
+
+ std::getline(ss, source = "", '/');
+
+ // silly
+ std::getline(ss, name, '/');
+ std::istringstream(name) >> (cid = -1);
+
+ std::getline(ss, name = "");
+}
+
+//
+// DeviceQualifier :: FromDevice
+//
+// set a device qualifier from a device
+//
+void DeviceQualifier::FromDevice(const Device* const dev)
+{
+ name = dev->GetName();
+ cid = dev->GetId();
+ source= dev->GetSource();
+}
+
+bool DeviceQualifier::operator==(const Device* const dev) const
+{
+ if (dev->GetId() == cid)
+ if (dev->GetName() == name)
+ if (dev->GetSource() == source)
+ return true;
+ return false;
+}
+
+bool DeviceQualifier::operator==(const DeviceQualifier& devq) const
+{
+ if (cid == devq.cid)
+ if (name == devq.name)
+ if (source == devq.source)
+ return true;
+
+ return false;
+}
+
+Device* DeviceContainer::FindDevice(const DeviceQualifier& devq) const
+{
+ std::vector<Device*>::const_iterator
+ di = m_devices.begin(),
+ de = m_devices.end();
+ for (; di!=de; ++di)
+ if (devq == *di)
+ return *di;
+
+ return NULL;
+}
+
+Device::Input* DeviceContainer::FindInput(const std::string& name, const Device* def_dev) const
+{
+ if (def_dev)
+ {
+ Device::Input* const inp = def_dev->FindInput(name);
+ if (inp)
+ return inp;
+ }
+
+ std::vector<Device*>::const_iterator
+ di = m_devices.begin(),
+ de = m_devices.end();
+ for (; di != de; ++di)
+ {
+ Device::Input* const i = (*di)->FindInput(name);
+
+ if (i)
+ return i;
+ }
+
+ return NULL;
+}
+
+Device::Output* DeviceContainer::FindOutput(const std::string& name, const Device* def_dev) const
+{
+ return def_dev->FindOutput(name);
+}
+
+}
+}