changed(false)
{ }
-void Config::add_option(const string &n, const string &v, const string &d)
+const Config::Option &Config::add_option(const Feature &f)
{
- Option opt(n, v, d);
- if(pending_options.count(n))
- opt.value = pending_options[n];
- options.insert(OptionMap::value_type(n, opt));
+ Option opt(f);
+ InputOptions::const_iterator i = pending_options.find(opt.name);
+ if(i!=pending_options.end())
+ opt.value = i->second;
+
+ return options.insert(OptionMap::value_type(opt.name, opt)).first->second;
}
bool Config::set_option(const string &opt, const string &val)
}
-Config::Option::Option(const string &n, const string &v, const string &d):
- name(n),
- default_value(v),
- description(d),
- value(v)
-{ }
+Config::Option::Option(const Feature &f):
+ Feature(f),
+ value(default_value)
+{
+ name = "with_"+name;
+}
Config::Loader::Loader(Config &c):
#include <msp/datafile/loader.h>
#include <msp/fs/path.h>
#include <msp/time/timestamp.h>
+#include "feature.h"
class SourcePackage;
{
public:
/** A single configuration option. */
- struct Option
+ struct Option: public Feature
{
- std::string name;
- std::string default_value;
- std::string description;
std::string value;
- Option(const std::string &, const std::string &, const std::string &);
+ Option(const Feature &);
};
typedef std::map<std::string, Option> OptionMap;
public:
Config(SourcePackage &);
- /** Adds a configuration option with name, default value and description. */
- void add_option(const std::string &, const std::string &, const std::string &);
+ /** Adds a configuration option based on a feature. */
+ const Option &add_option(const Feature &);
bool set_option(const std::string &, const std::string &);
Feature::Loader::Loader(Feature &f):
Msp::DataFile::ObjectLoader<Feature>(f)
{
- add("description", &Feature::descr);
- add("default", &Feature::def_value);
+ add("description", &Feature::description);
+ add("default", &Feature::default_value);
}
};
std::string name;
- std::string descr;
- std::string def_value;
+ std::string description;
+ std::string default_value;
Feature(const std::string &n): name(n) { }
};
void SourcePackage::Loader::feature(const string &n, const string &d)
{
Feature feat(n);
- feat.descr = d;
- feat.def_value = "no";
+ feat.description = d;
+ feat.default_value = "no";
load_sub(feat);
obj.features.push_back(feat);
- string config_key = "with_"+feat.name;
- obj.config.add_option(config_key, feat.def_value, feat.descr);
+
+ const Config::Option &opt = obj.config.add_option(feat);
if(options)
{
- Config::InputOptions::const_iterator i = options->find(config_key);
+ Config::InputOptions::const_iterator i = options->find(opt.name);
if(i!=options->end())
- obj.config.set_option(config_key, i->second);
+ obj.config.set_option(opt.name, i->second);
}
}