1 #include <msp/core/maputils.h>
2 #include <msp/fs/stat.h>
3 #include <msp/fs/utils.h>
4 #include <msp/io/file.h>
5 #include <msp/io/print.h>
6 #include <msp/time/utils.h>
9 #include "sourcepackage.h"
14 Config::Config(SourcePackage &p):
19 const Config::Option &Config::add_option(const Feature &f)
22 InputOptions::const_iterator i = pending_options.find(opt.name);
23 if(i!=pending_options.end())
24 opt.value = i->second;
26 return options.insert(OptionMap::value_type(opt.name, opt)).first->second;
29 bool Config::set_option(const string &opt, const string &val)
33 OptionMap::iterator i = options.find(opt);
36 if(i->second.value!=val)
42 i->second.value = val;
48 bool Config::is_option(const string &name) const
50 return options.count(name);
53 const Config::Option &Config::get_option(const string &name) const
55 return get_item(options, name);
60 FS::Path fn = package.get_source_directory()/".config";
61 FS::Stat stat = FS::stat(fn);
64 package.get_builder().get_logger().log("files", format("Reading %s", fn));
65 IO::BufferedFile in(fn.str());
67 mtime = stat.get_modify_time();
69 DataFile::Parser parser(in, fn.str());
75 void Config::save() const
80 FS::Path fn = package.get_source_directory()/".config";
82 package.get_builder().get_logger().log("files", format("Writing %s", fn));
83 IO::BufferedFile out(fn.str(), IO::M_WRITE);
85 for(OptionMap::const_iterator i=options.begin(); i!=options.end(); ++i)
86 IO::print(out, "option \"%s\" \"%s\";\n", i->second.name, i->second.value);
90 Config::Option::Option(const Feature &f):
98 Config::Loader::Loader(Config &c):
99 DataFile::ObjectLoader<Config>(c)
101 add("option", &Loader::option);
104 void Config::Loader::option(const string &n, const string &v)
106 if(obj.options.count(n))
107 obj.set_option(n, v);
109 obj.pending_options[n] = v;