]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/driver.h
Add helper class for processing driver options
[r2c2.git] / source / libr2c2 / driver.h
index 7c762d0066b4b9b668030edb0e53dec09d0ebf50..1222540c0b81e19bff985870c730124d2ea16b2f 100644 (file)
@@ -1,8 +1,10 @@
 #ifndef LIBR2C2_DRIVER_H_
 #define LIBR2C2_DRIVER_H_
 
+#include <map>
 #include <string>
 #include <sigc++/signal.h>
+#include <msp/strings/lexicalcast.h>
 
 namespace R2C2 {
 
@@ -13,6 +15,29 @@ class VehicleType;
 class Driver
 {
 public:
+       class Options
+       {
+       private:
+               typedef std::map<std::string, std::string> OptionMap;
+
+               OptionMap opts;
+
+       public:
+               Options() { }
+               Options(const std::string &);
+
+               void set(const std::string &, const std::string &);
+
+               template<typename T>
+               T get(const std::string &k, const T &d = T()) const
+               {
+                       OptionMap::const_iterator i = opts.find(k);
+                       if(i==opts.end())
+                               return d;
+                       return Msp::lexical_cast<T>(i->second);
+               }
+       };
+
        struct DetectedLocomotive
        {
                std::string protocol;