fix configs member variables not following our naming convention

This commit is contained in:
gfgtdf 2017-04-29 19:52:48 +02:00
parent e7d2108ba6
commit b6e398fdb1
2 changed files with 121 additions and 117 deletions

View file

@ -87,7 +87,7 @@ struct config_implementation
assert(parent[parent.size() - 1] == ']');
if(config->has_child(key)) {
return *(config->children.find(key)->second.front());
return *(config->children_.find(key)->second.front());
}
/**
@ -460,16 +460,16 @@ void config::check_valid(const config &cfg) const
throw error("Mandatory WML child missing yet untested for. Please report.");
}
config::config() : values(), children(), ordered_children()
config::config() : values_(), children_(), ordered_children()
{
}
config::config(const config& cfg) : values(cfg.values), children(), ordered_children()
config::config(const config& cfg) : values_(cfg.values_), children_(), ordered_children()
{
append_children(cfg);
}
config::config(config_key_type child) : values(), children(), ordered_children()
config::config(config_key_type child) : values_(), children_(), ordered_children()
{
add_child(child);
}
@ -490,8 +490,8 @@ config& config::operator=(const config& cfg)
}
config::config(config &&cfg):
values(std::move(cfg.values)),
children(std::move(cfg.children)),
values_(std::move(cfg.values_)),
children_(std::move(cfg.children_)),
ordered_children(std::move(cfg.ordered_children))
{
}
@ -522,15 +522,15 @@ bool config::valid_id(config_key_type id)
bool config::has_attribute(config_key_type key) const
{
check_valid();
return values.find(key) != values.end();
return values_.find(key) != values_.end();
}
bool config::has_old_attribute(config_key_type key, const std::string &old_key, const std::string& msg) const
{
check_valid();
if (values.find(key) != values.end()) {
if (values_.find(key) != values_.end()) {
return true;
} else if (values.find(old_key) != values.end()) {
} else if (values_.find(old_key) != values_.end()) {
if (!msg.empty())
lg::wml_error() << msg;
return true;
@ -542,7 +542,7 @@ bool config::has_old_attribute(config_key_type key, const std::string &old_key,
void config::remove_attribute(config_key_type key)
{
check_valid();
map_erase_key(values, key);
map_erase_key(values_, key);
}
void config::append_children(const config &cfg)
@ -557,8 +557,8 @@ void config::append_children(const config &cfg)
void config::append_attributes(const config &cfg)
{
check_valid(cfg);
for (const attribute &v : cfg.values) {
values[v.first] = v.second;
for (const attribute &v : cfg.values_) {
values_[v.first] = v.second;
}
}
@ -574,8 +574,8 @@ void config::append_children(const config &cfg, const std::string& key)
void config::append(const config &cfg)
{
append_children(cfg);
for (const attribute &v : cfg.values) {
values[v.first] = v.second;
for (const attribute &v : cfg.values_) {
values_[v.first] = v.second;
}
}
@ -616,10 +616,10 @@ config::child_itors config::child_range(config_key_type key)
{
check_valid();
child_map::iterator i = children.find(key);
child_map::iterator i = children_.find(key);
static child_list dummy;
child_list *p = &dummy;
if (i != children.end()) p = &i->second;
if (i != children_.end()) p = &i->second;
return child_itors(child_iterator(p->begin()), child_iterator(p->end()));
}
@ -627,10 +627,10 @@ config::const_child_itors config::child_range(config_key_type key) const
{
check_valid();
child_map::const_iterator i = children.find(key);
child_map::const_iterator i = children_.find(key);
static child_list dummy;
const child_list *p = &dummy;
if (i != children.end()) p = &i->second;
if (i != children_.end()) p = &i->second;
return const_child_itors(const_child_iterator(p->begin()), const_child_iterator(p->end()));
}
@ -638,8 +638,8 @@ unsigned config::child_count(config_key_type key) const
{
check_valid();
child_map::const_iterator i = children.find(key);
if(i != children.end()) {
child_map::const_iterator i = children_.find(key);
if(i != children_.end()) {
return i->second.size();
}
return 0;
@ -652,7 +652,7 @@ unsigned config::all_children_count() const
unsigned config::attribute_count() const
{
return std::count_if(values.begin(), values.end(), [](const attribute& v) {
return std::count_if(values_.begin(), values_.end(), [](const attribute& v) {
return !v.second.blank();
});
}
@ -661,15 +661,15 @@ bool config::has_child(config_key_type key) const
{
check_valid();
return children.find(key) != children.end();
return children_.find(key) != children_.end();
}
config &config::child(config_key_type key, int n)
{
check_valid();
const child_map::const_iterator i = children.find(key);
if (i == children.end()) {
const child_map::const_iterator i = children_.find(key);
if (i == children_.end()) {
DBG_CF << "The config object has no child named »"
<< key << "«.\n";
@ -706,8 +706,8 @@ const config & config::child_or_empty(config_key_type key) const
static const config empty_cfg;
check_valid();
child_map::const_iterator i = children.find(key);
if (i != children.end() && !i->second.empty())
child_map::const_iterator i = children_.find(key);
if (i != children_.end() && !i->second.empty())
return *i->second.front();
return empty_cfg;
@ -715,8 +715,8 @@ const config & config::child_or_empty(config_key_type key) const
config &config::child_or_add(config_key_type key)
{
child_map::const_iterator i = children.find(key);
if (i != children.end() && !i->second.empty())
child_map::const_iterator i = children_.find(key);
if (i != children_.end() && !i->second.empty())
return *i->second.front();
return add_child(key);
@ -726,9 +726,9 @@ config& config::add_child(config_key_type key)
{
check_valid();
child_list& v = map_get(children, key);
v.push_back(new config());
ordered_children.emplace_back(children.find(key),v.size()-1);
child_list& v = map_get(children_, key);
v.emplace_back(new config());
ordered_children.emplace_back(children_.find(key),v.size()-1);
return *v.back();
}
@ -736,9 +736,10 @@ config& config::add_child(config_key_type key, const config& val)
{
check_valid(val);
child_list& v = map_get(children, key);
v.push_back(new config(val));
ordered_children.emplace_back(children.find(key),v.size()-1);
child_list& v = map_get(children_, key);
v.emplace_back(new config(val));
ordered_children.emplace_back(children_.find(key),v.size()-1);
return *v.back();
}
@ -746,9 +747,10 @@ config &config::add_child(config_key_type key, config &&val)
{
check_valid(val);
child_list &v = map_get(children, key);
v.push_back(new config(std::move(val)));
ordered_children.emplace_back(children.find(key), v.size() - 1);
child_list &v = map_get(children_, key);
v.emplace_back(new config(std::move(val)));
ordered_children.emplace_back(children_.find(key), v.size() - 1);
return *v.back();
}
@ -756,16 +758,16 @@ config &config::add_child_at(config_key_type key, const config &val, unsigned in
{
check_valid(val);
child_list& v = map_get(children, key);
child_list& v = map_get(children_, key);
if(index > v.size()) {
throw error("illegal index to add child at");
}
v.insert(v.begin()+index,new config(val));
v.emplace(v.begin()+index,new config(val));
bool inserted = false;
const child_pos value(children.find(key),index);
const child_pos value(children_.find(key),index);
std::vector<child_pos>::iterator ord = ordered_children.begin();
for(; ord != ordered_children.end(); ++ord) {
@ -803,8 +805,8 @@ void config::clear_children_impl(config_key_type key)
{
check_valid();
child_map::iterator i = children.find(key);
if (i == children.end()) return;
child_map::iterator i = children_.find(key);
if (i == children_.end()) return;
ordered_children.erase(std::remove_if(ordered_children.begin(),
ordered_children.end(), remove_ordered(i)), ordered_children.end());
@ -813,25 +815,26 @@ void config::clear_children_impl(config_key_type key)
delete c;
}
children.erase(i);
children_.erase(i);
}
void config::splice_children(config &src, const std::string &key)
{
check_valid(src);
child_map::iterator i_src = src.children.find(key);
if (i_src == src.children.end()) return;
child_map::iterator i_src = src.children_.find(key);
if (i_src == src.children_.end()) return;
src.ordered_children.erase(std::remove_if(src.ordered_children.begin(),
src.ordered_children.end(), remove_ordered(i_src)),
src.ordered_children.end());
child_list &dst = map_get(children, key);
child_map::iterator i_dst = children.find(key);
child_list &dst = map_get(children_, key);
child_map::iterator i_dst = children_.find(key);
unsigned before = dst.size();
dst.insert(dst.end(), i_src->second.begin(), i_src->second.end());
src.children.erase(i_src);
dst.insert(dst.end(), std::make_move_iterator(i_src->second.begin()), std::make_move_iterator(i_src->second.end()));
src.children_.erase(i_src);
// key might be a reference to i_src->first, so it is no longer usable.
for (unsigned j = before; j < dst.size(); ++j) {
@ -842,9 +845,10 @@ void config::splice_children(config &src, const std::string &key)
void config::recursive_clear_value(config_key_type key)
{
check_valid();
map_erase_key(values, key);
for(std::pair<const std::string, child_list>& p : children) {
map_erase_key(values_, key);
for(std::pair<const std::string, child_list>& p : children_) {
for(config* cfg : p.second) {
cfg->recursive_clear_value(key);
}
@ -883,8 +887,8 @@ void config::remove_child(config_key_type key, unsigned index)
{
check_valid();
child_map::iterator i = children.find(key);
if (i == children.end() || index >= i->second.size()) {
child_map::iterator i = children_.find(key);
if (i == children_.end() || index >= i->second.size()) {
ERR_CF << "Error: attempting to delete non-existing child: "
<< key << "[" << index << "]\n";
return;
@ -897,8 +901,8 @@ const config::attribute_value &config::operator[](config_key_type key) const
{
check_valid();
const attribute_map::const_iterator i = values.find(key);
if (i != values.end()) return i->second;
const attribute_map::const_iterator i = values_.find(key);
if (i != values_.end()) return i->second;
static const attribute_value empty_attribute;
return empty_attribute;
}
@ -906,18 +910,18 @@ const config::attribute_value &config::operator[](config_key_type key) const
const config::attribute_value *config::get(config_key_type key) const
{
check_valid();
attribute_map::const_iterator i = values.find(key);
return i != values.end() ? &i->second : nullptr;
attribute_map::const_iterator i = values_.find(key);
return i != values_.end() ? &i->second : nullptr;
}
config::attribute_value& config::operator[](config_key_type key)
{
check_valid();
auto res = values.lower_bound(key);
auto res = values_.lower_bound(key);
if (res == values.end() || key != res->first) {
res = values.emplace_hint(res, std::piecewise_construct, std::forward_as_tuple(key), std::tuple<>());
if (res == values_.end() || key != res->first) {
res = values_.emplace_hint(res, std::piecewise_construct, std::forward_as_tuple(key), std::tuple<>());
}
return res->second;
@ -927,12 +931,12 @@ const config::attribute_value &config::get_old_attribute(config_key_type key, co
{
check_valid();
attribute_map::const_iterator i = values.find(key);
if (i != values.end())
attribute_map::const_iterator i = values_.find(key);
if (i != values_.end())
return i->second;
i = values.find(old_key);
if (i != values.end()) {
i = values_.find(old_key);
if (i != values_.end()) {
if (!msg.empty())
lg::wml_error() << msg;
return i->second;
@ -948,19 +952,19 @@ void config::merge_attributes(const config &cfg)
check_valid(cfg);
assert(this != &cfg);
for (const attribute &v : cfg.values) {
for (const attribute &v : cfg.values_) {
std::string key = v.first;
if (key.substr(0,7) == "add_to_") {
std::string add_to = key.substr(7);
values[add_to] = values[add_to].to_double() + v.second.to_double();
values_[add_to] = values_[add_to].to_double() + v.second.to_double();
} else if(key.substr(0,10) == "concat_to_") {
std::string concat_to = key.substr(10);
// TODO: Only use t_string if one or both are actually translatable?
// That probably requires using a visitor though.
values[concat_to] = values[concat_to].t_str() + v.second.t_str();
values_[concat_to] = values_[concat_to].t_str() + v.second.t_str();
} else
values[v.first] = v.second;
values_[v.first] = v.second;
}
}
@ -968,8 +972,8 @@ config::const_attr_itors config::attribute_range() const
{
check_valid();
const_attr_itors range (const_attribute_iterator(values.begin()),
const_attribute_iterator(values.end()));
const_attr_itors range (const_attribute_iterator(values_.begin()),
const_attribute_iterator(values_.end()));
// Ensure the first element is not blank, as a few places assume this
while(range.begin() != range.end() && range.begin()->second.blank()) {
@ -981,7 +985,7 @@ config::const_attr_itors config::attribute_range() const
config::attr_itors config::attribute_range()
{
check_valid();
attr_itors range(attribute_iterator(values.begin()), attribute_iterator(values.end()));
attr_itors range(attribute_iterator(values_.begin()), attribute_iterator(values_.end()));
// Ensure the first element is not blank, as a few places assume this
while(range.begin() != range.end() && range.begin()->second.blank()) {
@ -995,8 +999,8 @@ config &config::find_child(config_key_type key, const std::string &name,
{
check_valid();
const child_map::iterator i = children.find(key);
if(i == children.end()) {
const child_map::iterator i = children_.find(key);
if(i == children_.end()) {
DBG_CF << "Key »" << name << "« value »" << value
<< "« pair not found as child of key »" << key << "«.\n";
@ -1039,30 +1043,30 @@ void config::clear()
{
// No validity check for this function.
if (!children.empty()) {
if (!children_.empty()) {
//start with this node, the first entry in the child map,
//zeroeth element in that entry
config_clear_state init;
init.c = this;
init.mi = children.begin();
init.mi = children_.begin();
init.vi = 0;
std::deque<config_clear_state> l;
l.push_back(init);
while (!l.empty()) {
config_clear_state& state = l.back();
if (state.mi != state.c->children.end()) {
if (state.mi != state.c->children_.end()) {
std::vector<config*>& v = state.mi->second;
if (state.vi < v.size()) {
config* c = v[state.vi];
++state.vi;
if (c->children.empty()) {
if (c->children_.empty()) {
delete c; //special case for a slight speed increase?
} else {
//descend to the next level
config_clear_state next;
next.c = c;
next.mi = c->children.begin();
next.mi = c->children_.begin();
next.vi = 0;
l.push_back(next);
}
@ -1074,14 +1078,14 @@ void config::clear()
//reached end of child map for this element - all child nodes
//have been deleted, so it's safe to clear the map, delete the
//node and move up one level
state.c->children.clear();
state.c->children_.clear();
if (state.c != this) delete state.c;
l.pop_back();
}
}
}
values.clear();
values_.clear();
ordered_children.clear();
}
@ -1089,7 +1093,7 @@ bool config::empty() const
{
check_valid();
return children.empty() && values.empty();
return children_.empty() && values_.empty();
}
config::all_children_iterator::reference config::all_children_iterator::operator*() const
@ -1163,10 +1167,10 @@ void config::get_diff(const config& c, config& res) const
config* inserts = nullptr;
attribute_map::const_iterator i;
for(i = values.begin(); i != values.end(); ++i) {
for(i = values_.begin(); i != values_.end(); ++i) {
if(i->second.blank()) continue;
const attribute_map::const_iterator j = c.values.find(i->first);
if(j == c.values.end() || (i->second != j->second && !i->second.blank() )) {
const attribute_map::const_iterator j = c.values_.find(i->first);
if(j == c.values_.end() || (i->second != j->second && !i->second.blank() )) {
if(inserts == nullptr) {
inserts = &res.add_child("insert");
}
@ -1177,10 +1181,10 @@ void config::get_diff(const config& c, config& res) const
config* deletes = nullptr;
for(i = c.values.begin(); i != c.values.end(); ++i) {
for(i = c.values_.begin(); i != c.values_.end(); ++i) {
if(i->second.blank()) continue;
const attribute_map::const_iterator itor = values.find(i->first);
if(itor == values.end() || itor->second.blank()) {
const attribute_map::const_iterator itor = values_.find(i->first);
if(itor == values_.end() || itor->second.blank()) {
if(deletes == nullptr) {
deletes = &res.add_child("delete");
}
@ -1192,26 +1196,26 @@ void config::get_diff(const config& c, config& res) const
std::vector<std::string> entities;
child_map::const_iterator ci;
for(ci = children.begin(); ci != children.end(); ++ci) {
for(ci = children_.begin(); ci != children_.end(); ++ci) {
entities.push_back(ci->first);
}
for(ci = c.children.begin(); ci != c.children.end(); ++ci) {
if(children.count(ci->first) == 0) {
for(ci = c.children_.begin(); ci != c.children_.end(); ++ci) {
if(children_.count(ci->first) == 0) {
entities.push_back(ci->first);
}
}
for(std::vector<std::string>::const_iterator itor = entities.begin(); itor != entities.end(); ++itor) {
const child_map::const_iterator itor_a = children.find(*itor);
const child_map::const_iterator itor_b = c.children.find(*itor);
const child_map::const_iterator itor_a = children_.find(*itor);
const child_map::const_iterator itor_b = c.children_.find(*itor);
static const child_list dummy;
// Get the two child lists. 'b' has to be modified to look like 'a'.
const child_list& a = itor_a != children.end() ? itor_a->second : dummy;
const child_list& b = itor_b != c.children.end() ? itor_b->second : dummy;
const child_list& a = itor_a != children_.end() ? itor_a->second : dummy;
const child_list& b = itor_b != c.children_.end() ? itor_b->second : dummy;
size_t ndeletes = 0;
size_t ai = 0, bi = 0;
@ -1230,7 +1234,7 @@ void config::get_diff(const config& c, config& res) const
if(b.size() - bi > a.size() - ai) {
config& new_delete = res.add_child("delete_child");
buf << bi - ndeletes;
new_delete.values["index"] = buf.str();
new_delete.values_["index"] = buf.str();
new_delete.add_child(*itor);
++ndeletes;
@ -1242,7 +1246,7 @@ void config::get_diff(const config& c, config& res) const
else if(b.size() - bi < a.size() - ai) {
config& new_insert = res.add_child("insert_child");
buf << ai;
new_insert.values["index"] = buf.str();
new_insert.values_["index"] = buf.str();
new_insert.add_child(*itor,*a[ai]);
++ai;
@ -1253,7 +1257,7 @@ void config::get_diff(const config& c, config& res) const
else {
config& new_change = res.add_child("change_child");
buf << bi;
new_change.values["index"] = buf.str();
new_change.values_["index"] = buf.str();
new_change.add_child(*itor,a[ai]->get_diff(*b[bi]));
++ai;
@ -1268,17 +1272,17 @@ void config::apply_diff(const config& diff, bool track /* = false */)
{
check_valid(diff);
if (track) values[diff_track_attribute] = "modified";
if (track) values_[diff_track_attribute] = "modified";
if (const config &inserts = diff.child("insert")) {
for (const attribute &v : inserts.attribute_range()) {
values[v.first] = v.second;
values_[v.first] = v.second;
}
}
if (const config &deletes = diff.child("delete")) {
for (const attribute &v : deletes.attribute_range()) {
values.erase(v.first);
values_.erase(v.first);
}
}
@ -1291,8 +1295,8 @@ void config::apply_diff(const config& diff, bool track /* = false */)
continue;
}
const child_map::iterator itor = children.find(item.key);
if(itor == children.end() || index >= itor->second.size()) {
const child_map::iterator itor = children_.find(item.key);
if(itor == children_.end() || index >= itor->second.size()) {
throw error("error in diff: could not find element '" + item.key + "'");
}
@ -1316,11 +1320,11 @@ void config::apply_diff(const config& diff, bool track /* = false */)
if (!track) {
remove_child(item.key, index);
} else {
const child_map::iterator itor = children.find(item.key);
if(itor == children.end() || index >= itor->second.size()) {
const child_map::iterator itor = children_.find(item.key);
if(itor == children_.end() || index >= itor->second.size()) {
throw error("error in diff: could not find element '" + item.key + "'");
}
itor->second[index]->values[diff_track_attribute] = "deleted";
itor->second[index]->values_[diff_track_attribute] = "deleted";
}
}
}
@ -1346,15 +1350,15 @@ void config::clear_diff_track(const config& diff)
continue;
}
const child_map::iterator itor = children.find(item.key);
if(itor == children.end() || index >= itor->second.size()) {
const child_map::iterator itor = children_.find(item.key);
if(itor == children_.end() || index >= itor->second.size()) {
throw error("error in diff: could not find element '" + item.key + "'");
}
itor->second[index]->clear_diff_track(item.cfg);
}
}
for(std::pair<const std::string, child_list>& p : children) {
for(std::pair<const std::string, child_list>& p : children_) {
for(config* cfg : p.second) {
cfg->remove_attribute(diff_track_attribute);
}
@ -1378,8 +1382,8 @@ void config::merge_with(const config& c)
all_children_iterator::Itor i, i_end = ordered_children.end();
for(i = ordered_children.begin(); i != i_end; ++i) {
const std::string& tag = i->pos->first;
const child_map::const_iterator j = c.children.find(tag);
if (j != c.children.end()) {
const child_map::const_iterator j = c.children_.find(tag);
if (j != c.children_.end()) {
unsigned &visits = visitations[tag];
if(visits < j->second.size()) {
// Get a const config so we do not add attributes.
@ -1394,7 +1398,7 @@ void config::merge_with(const config& c)
}
// Now add any unvisited tags
for(const auto& pair : c.children) {
for(const auto& pair : c.children_) {
const std::string& tag = pair.first;
unsigned &visits = visitations[tag];
while(visits < pair.second.size()) {
@ -1498,7 +1502,7 @@ std::string config::hash() const
hash_str[hash_length] = 0;
i = 0;
for (const attribute &val : values)
for (const attribute &val : values_)
{
if (val.second.blank()) {
continue;
@ -1538,8 +1542,8 @@ void config::swap(config& cfg)
{
check_valid(cfg);
values.swap(cfg.values);
children.swap(cfg.children);
values_.swap(cfg.values_);
children_.swap(cfg.children_);
ordered_children.swap(cfg.ordered_children);
}
@ -1547,7 +1551,7 @@ bool operator==(const config& a, const config& b)
{
a.check_valid(b);
if (a.values != b.values)
if (a.values_ != b.values_)
return false;
config::const_all_children_itors x = a.all_children_range(), y = b.all_children_range();

View file

@ -895,10 +895,10 @@ private:
std::vector<child_pos>::iterator remove_child(const child_map::iterator &l, unsigned pos);
/** All the attributes of this node. */
attribute_map values;
attribute_map values_;
/** A list of all children of this node. */
child_map children;
child_map children_;
std::vector<child_pos> ordered_children;
};