A final touch to make processing of [base_unit] a little more readable...
...(adds a new merge method for configs).
This commit is contained in:
parent
45c0b21771
commit
bed49629eb
3 changed files with 26 additions and 6 deletions
|
@ -626,6 +626,26 @@ void config::merge_with(const config& c)
|
|||
}
|
||||
}
|
||||
|
||||
void config::merge_and_keep(const config& c)
|
||||
{
|
||||
// Merge not existing attributes first
|
||||
string_map::const_iterator attrib_it, attrib_end = c.values.end();
|
||||
for(attrib_it = c.values.begin(); attrib_it != attrib_end; ++attrib_it) {
|
||||
if (values[attrib_it->first] == "")
|
||||
values[attrib_it->first] = attrib_it->second;
|
||||
}
|
||||
|
||||
// Now merge unshared tags
|
||||
for(child_map::const_iterator i = c.children.begin(); i != c.children.end(); ++i) {
|
||||
const std::string& tag = i->first;
|
||||
child_map::const_iterator j = children.find(tag);
|
||||
if (j == children.end()) {
|
||||
for (int count=0; count < i->second.size(); count++)
|
||||
add_child(tag, *i->second[count]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool config::matches(const config &filter) const
|
||||
{
|
||||
// First match values. all values should match.
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "global.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -47,7 +47,7 @@ public:
|
|||
config();
|
||||
|
||||
config(const config& cfg);
|
||||
|
||||
|
||||
// Create a config with an empty child of name 'child'.
|
||||
config(const std::string& child);
|
||||
~config();
|
||||
|
@ -152,6 +152,9 @@ public:
|
|||
//! Merge config 'c' into this config.
|
||||
//! Overwrites this config's values.
|
||||
void merge_with(const config& c);
|
||||
//! Merge config 'c' into this config.
|
||||
//! Keeps this config's values and does not add existing elements.
|
||||
void config::merge_and_keep(const config& c);
|
||||
|
||||
bool matches(const config &filter) const;
|
||||
|
||||
|
|
|
@ -927,10 +927,7 @@ void unit_type_data::unit_type_map_wrapper::set_config(const config& cfg)
|
|||
config from_cfg = find_config(based_from);
|
||||
|
||||
//merge the base_unit config into this one
|
||||
//ugly hack, but couldn't think of anything better for the moment
|
||||
from_cfg.merge_with(**i.first);
|
||||
(**i.first).merge_with(from_cfg);
|
||||
|
||||
(**i.first).merge_and_keep(from_cfg);
|
||||
(**i.first).clear_children("base_unit");
|
||||
(**i.first)["id"] = id;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue