3 #include <msp/path/utils.h>
4 #include <msp/time/utils.h>
10 void Config::add_option(const string &n, const string &v, const string &d)
12 options.insert(OptionMap::value_type(n, Option(n, v, d)));
15 const Config::Option &Config::get_option(const string &name) const
17 OptionMap::const_iterator i=options.find(name);
19 throw Exception("Tried to access nonexistent option "+name);
24 bool Config::is_option(const string &name) const
26 return options.count(name);
29 bool Config::process(const RawOptionMap &opts)
32 for(RawOptionMap::const_iterator i=opts.begin(); i!=opts.end(); ++i)
34 OptionMap::iterator j=options.find(i->first);
37 if(i->second!=j->second.value)
39 j->second.value=i->second;
49 void Config::load(const Path::Path &fn)
51 ifstream in(fn.str().c_str());
56 mtime=Time::TimeStamp::from_unixtime(st.st_mtime);
58 Parser::Parser parser(in, fn.str());
63 void Config::save(const Path::Path &fn) const
65 ofstream out(fn.str().c_str());
68 for(OptionMap::const_iterator i=options.begin(); i!=options.end(); ++i)
69 out<<"option \""<<i->second.name<<"\" \""<<i->second.value<<"\";\n";
72 Config::Option::Option(const string &n, const string &v, const string &d):
79 Config::Loader::Loader(Config &c):
82 add("option", &Loader::option);
85 void Config::Loader::option(const string &n, const string &v)
87 OptionMap::iterator i=conf.options.find(n);
88 if(i!=conf.options.end())