]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/device.cpp
Add conversions to/from string for key names and device types
[libs/gui.git] / source / input / device.cpp
index 7dbe8ea274812d4ecd047a16c4162a747b3b6fbb..452af22543e4f57db85a9a5271dad5c2648c96a1 100644 (file)
@@ -71,5 +71,35 @@ void Device::set_axis_value(unsigned axis, float value, bool event)
        }
 }
 
+
+void operator>>(const LexicalConverter &conv, DeviceType &type)
+{
+       if(conv.get()=="UNSPECIFIED")
+               type = UNSPECIFIED;
+       else if(conv.get()=="KEYBOARD")
+               type = KEYBOARD;
+       else if(conv.get()=="MOUSE")
+               type = MOUSE;
+       else if(conv.get()=="TOUCH_SURFACE")
+               type = TOUCH_SURFACE;
+       else if(conv.get()=="GAME_CONTROLLER")
+               type = GAME_CONTROLLER;
+       else
+               throw lexical_error(format("conversion of '%s' to DeviceType", conv.get()));
+}
+
+void operator<<(LexicalConverter &conv, DeviceType type)
+{
+       switch(type)
+       {
+       case UNSPECIFIED: conv.result("UNSPECIFIED"); break;
+       case KEYBOARD: conv.result("KEYBOARD"); break;
+       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)));
+       }
+}
+
 } // namespace Input
 } // namespace Msp