#include "device.h"
+#include <map>
+#include <msp/core/maputils.h>
#include <msp/strings/format.h>
using namespace std;
}
+map<string, DeviceType> &get_device_types()
+{
+ static map<string, DeviceType> types;
+ return types;
+}
+
+DeviceType register_device_type(const char *name)
+{
+ static unsigned next_type = EXTENSION_DEVICE+1;
+ auto i = insert_unique(get_device_types(), name, static_cast<DeviceType>(next_type++));
+ return i->second;
+}
+
void operator>>(const LexicalConverter &conv, DeviceType &type)
{
if(conv.get()=="UNSPECIFIED")
else if(conv.get()=="GAME_CONTROLLER")
type = GAME_CONTROLLER;
else
- throw lexical_error(format("conversion of '%s' to DeviceType", conv.get()));
+ {
+ auto &ext_types = get_device_types();
+ auto i = ext_types.find(conv.get());
+ if(i!=ext_types.end())
+ type = i->second;
+ else
+ throw lexical_error(format("conversion of '%s' to DeviceType", conv.get()));
+ }
}
void operator<<(LexicalConverter &conv, DeviceType type)
case MOUSE: conv.result("MOUSE"); break;
case TOUCH_SURFACE: conv.result("TOUCH_SURFACE"); break;
case GAME_CONTROLLER: conv.result("GAME_CONTROLLER"); break;
- default: conv.result(format("DeviceType(%#x)", static_cast<int>(type)));
+ default:
+ for(const auto &kvp: get_device_types())
+ if(kvp.second==type)
+ {
+ conv.result(kvp.first);
+ return;
+ }
+ conv.result(format("DeviceType(%#x)", static_cast<int>(type)));
}
}