]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/driver.cpp
Avoid arriving too early if there's an unexpected stop on the last route
[r2c2.git] / source / libr2c2 / driver.cpp
1 #include <msp/strings/utils.h>
2 #include "arducontrol.h"
3 #include "centralstation.h"
4 #include "driver.h"
5 #include "dummy.h"
6 #include "intellibox.h"
7
8 using namespace std;
9 using namespace Msp;
10
11 namespace R2C2 {
12
13 Driver *Driver::create(const string &str)
14 {
15         string::size_type colon = str.find(':');
16         string type = str.substr(0, colon);
17         string params;
18
19         if(colon!=string::npos)
20                 params = str.substr(colon+1);
21
22         if(type=="ib" || type=="intellibox")
23                 return new Intellibox(params);
24         else if(type=="cs" || type=="centralstation")
25                 return new CentralStation(params);
26         else if(type=="ac" || type=="arducontrol")
27                 return new ArduControl(params);
28         else if(type=="dummy")
29                 return new Dummy(params);
30
31         throw invalid_argument("Driver::create");
32 }
33
34
35 Driver::Options::Options(const string &optstr)
36 {
37         vector<string> parts = split(optstr, ':');
38         for(vector<string>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
39         {
40                 string::size_type equals = i->find('=');
41                 if(equals==0)
42                         throw invalid_argument("Driver::Options::Options");
43
44                 if(equals==string::npos)
45                         set(string(), *i);
46                 else
47                         set(i->substr(0, equals), i->substr(equals+1));
48         }
49 }
50
51 void Driver::Options::set(const string &key, const string &value)
52 {
53         opts[key] = value;
54 }
55
56 } // namespace R2C2