]> git.tdb.fi Git - builder.git/blob - source/config.cpp
Builder can build itself now.
[builder.git] / source / config.cpp
1 #include <msp/error.h>
2 #include "config.h"
3
4 using namespace std;
5 using namespace Msp;
6
7 void Config::add_option(const string &n, const string &v, const string &d)
8 {
9         options.insert(OptionMap::value_type(n, Option(n, v, d)));
10 }
11
12 const Config::Option &Config::get_option(const string &name) const
13 {
14         OptionMap::const_iterator i=options.find(name);
15         if(i==options.end())
16                 throw Exception("Tried to access nonexistent option "+name);
17
18         return i->second;
19 }
20
21 bool Config::is_option(const string &name) const
22 {
23         return options.count(name);
24 }
25
26 bool Config::process(const RawOptionMap &opts)
27 {
28         bool changed=false;
29         for(RawOptionMap::const_iterator i=opts.begin(); i!=opts.end(); ++i)
30         {
31                 OptionMap::iterator j=options.find(i->first);
32                 if(j!=options.end())
33                 {
34                         if(i->second!=j->second.value)
35                                 changed=true;
36                         j->second.value=i->second;
37                 }
38         }
39
40         return changed;
41 }
42
43 Config::Option::Option(const string &n, const string &v, const string &d):
44         name(n),
45         defv(v),
46         descr(d),
47         value(v)
48 { }