]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/simplecontroller.cpp
Replace various map lookups with functions from maputils.h
[r2c2.git] / source / libr2c2 / simplecontroller.cpp
index 7f8b3362087ed0cee7a37eb03c55875cc31a4f20..d88ade005929309e38d15f04714e7fa08278cad0 100644 (file)
@@ -1,11 +1,5 @@
-/* $Id$
-
-This file is part of R²C²
-Copyright © 2010  Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
 #include <msp/core/except.h>
+#include <msp/core/maputils.h>
 #include <msp/time/units.h>
 #include "simplecontroller.h"
 
@@ -23,14 +17,24 @@ SimpleController::SimpleController():
        target_speed.set(0);
 }
 
+const char *SimpleController::enumerate_controls(unsigned index) const
+{
+       if(index==0)
+               return target_speed.name.c_str();
+       else if(index==1)
+               return reverse.name.c_str();
+       else
+               return 0;
+}
+
 void SimpleController::set_control(const string &name, float v)
 {
-       if(name=="speed")
+       if(name==target_speed.name)
        {
                target_speed.set(v);
                signal_control_changed.emit(target_speed);
        }
-       else if(name=="reverse")
+       else if(name==reverse.name)
        {
                if(target_speed.value || speed)
                        throw InvalidState("Must be stopped to change reverse");
@@ -41,12 +45,12 @@ void SimpleController::set_control(const string &name, float v)
 
 const Controller::Control &SimpleController::get_control(const string &name) const
 {
-       if(name=="speed")
+       if(name==target_speed.name)
                return target_speed;
-       else if(name=="reverse")
+       else if(name==reverse.name)
                return reverse;
        else
-               throw KeyError("Unknown control", name);
+               throw key_error(name);
 }
 
 float SimpleController::get_braking_distance() const