#include <msp/strings/format.h>
#include "device.h"
+using namespace std;
+
namespace Msp {
namespace Input {
Device::~Device()
{ }
+Device *Device::find_subdevice(const string &n)
+{
+ return (n==name ? this : 0);
+}
+
+Device *Device::find_subdevice(DeviceType t, unsigned i)
+{
+ return (t==type && i==0 ? this : 0);
+}
+
bool Device::get_button_state(unsigned btn) const
{
if(btn>=buttons.size())
DeviceType get_type() const { return type; }
const std::string &get_name() const { return name; }
+ virtual Device *find_subdevice(DeviceType, unsigned = 0);
+ virtual Device *find_subdevice(const std::string &);
bool get_button_state(unsigned) const;
float get_axis_value(unsigned) const;
dev.signal_axis_motion.connect(sigc::bind_return(sigc::bind(sigc::mem_fun(this, &Hub::axis_motion), index), false));
}
+Device *Hub::find_subdevice(DeviceType t, unsigned n)
+{
+ for(vector<Device *>::const_iterator i=devices.begin(); i!=devices.end(); ++i)
+ if(Device *dev = (*i)->find_subdevice(t, 0))
+ {
+ if(!n)
+ return dev;
+ --n;
+ }
+ return 0;
+}
+
+Device *Hub::find_subdevice(const string &n)
+{
+ if(n==name)
+ return this;
+ for(vector<Device *>::const_iterator i=devices.begin(); i!=devices.end(); ++i)
+ if(Device *dev = (*i)->find_subdevice(n))
+ return dev;
+ return 0;
+}
+
std::string Hub::get_button_name(unsigned btn) const
{
unsigned dev_index = btn>>8;
/// Attaches an input device to the hub.
void attach(Device &dev);
+ virtual Device *find_subdevice(DeviceType, unsigned = 0);
+ virtual Device *find_subdevice(const std::string &);
+
virtual std::string get_button_name(unsigned) const;
virtual std::string get_axis_name(unsigned) const;
protected: