Tech data accessible as "technology-data" config value

Previously, the "technology-data" complex configuration
value was stored in the configuration file, but not
accessible from scripts through Application#set_config
and Applicatiob#get_config. It was as pseudo parameter
that wasn't dynamically connected to the application
state.

Now it's handled separately as if it was a normal
parameter. This is just an intermediate solution
required because this interface is the only one
through which tech data is accessible from scripts.
This commit is contained in:
Matthias Koefferlein 2017-03-30 00:11:09 +02:00
parent a24e6d94a9
commit e35e9fe8f7
2 changed files with 37 additions and 3 deletions

View File

@ -1639,7 +1639,22 @@ void
Application::set_config (const std::string &name, const std::string &value)
{
if (mp_plugin_root) {
mp_plugin_root->config_set (name, value);
if (name == cfg_technologies) {
// HACK: cfg_technologies is not a real configuration parameter currently. Hence we emulate that
// behavior. But currently this is the only way to access technology data indirectly from a script.
// Note that this method will set only the technologies accessible through the configuration parameter.
// I.e. the ones not auto-imported.
// TODO: rework this one. This is only half-hearted.
if (! value.empty ()) {
lay::Technologies::instance ()->load_from_xml (value);
}
} else {
mp_plugin_root->config_set (name, value);
}
}
}
@ -1655,7 +1670,16 @@ std::string
Application::get_config (const std::string &name) const
{
if (mp_plugin_root) {
return mp_plugin_root->config_get (name);
if (name == cfg_technologies) {
// HACK: cfg_technologies is not a real configuration parameter currently. Hence we emulate that
// behavior. But currently this is the only way to access technology data indirectly from a script.
// Note that this method will return only the technologies accessible through the configuration parameter.
// I.e. the ones not auto-imported.
// TODO: rework this one.
return lay::Technologies::instance ()->to_xml ();
} else {
return mp_plugin_root->config_get (name);
}
} else {
return std::string ();
}

View File

@ -97,9 +97,19 @@ Technologies::to_xml () const
void
Technologies::load_from_xml (const std::string &s)
{
// create a copy to filter out the ones which are not persisted and remain
lay::Technologies copy;
for (const_iterator t = begin (); t != end (); ++t) {
if (! t->is_persisted ()) {
copy.add (new Technology (*t));
}
}
tl::XMLStringSource source (s);
tl::XMLStruct<lay::Technologies> xml_struct ("technologies", xml_elements ());
xml_struct.parse (source, *this);
xml_struct.parse (source, copy);
*this = copy;
}
void