mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-02 01:22:25 +00:00
now able to safely insert to an index at array.length...
...using [set_variables] mode=insert (before it would create empty child data before inserting).
This commit is contained in:
parent
7498fd2fc5
commit
6511160a75
@ -113,6 +113,15 @@ config::const_child_itors config::child_range(const std::string& key) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t config::child_count(const std::string& key) const
|
||||||
|
{
|
||||||
|
child_map::const_iterator i = children.find(key);
|
||||||
|
if(i != children.end()) {
|
||||||
|
return i->second.size();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const config::child_list& config::get_children(const std::string& key) const
|
const config::child_list& config::get_children(const std::string& key) const
|
||||||
{
|
{
|
||||||
const child_map::const_iterator i = children.find(key);
|
const child_map::const_iterator i = children.find(key);
|
||||||
|
@ -75,6 +75,7 @@ public:
|
|||||||
|
|
||||||
child_itors child_range(const std::string& key);
|
child_itors child_range(const std::string& key);
|
||||||
const_child_itors child_range(const std::string& key) const;
|
const_child_itors child_range(const std::string& key) const;
|
||||||
|
size_t child_count(const std::string& key) const;
|
||||||
|
|
||||||
const child_list& get_children(const std::string& key) const;
|
const child_list& get_children(const std::string& key) const;
|
||||||
const child_map& all_children() const;
|
const child_map& all_children() const;
|
||||||
|
@ -1313,9 +1313,21 @@ namespace {
|
|||||||
std::string mode = cfg["mode"]; // replace, append, merge, or insert
|
std::string mode = cfg["mode"]; // replace, append, merge, or insert
|
||||||
if(mode == "extend") {
|
if(mode == "extend") {
|
||||||
mode = "append";
|
mode = "append";
|
||||||
} else if(mode != "append" && mode != "merge" && mode != "insert") {
|
} else if(mode != "append" && mode != "merge") {
|
||||||
|
if(mode == "insert") {
|
||||||
|
size_t child_count = dest.vars->child_count(dest.key);
|
||||||
|
if(dest.index >= child_count) {
|
||||||
|
while(dest.index >= ++child_count) {
|
||||||
|
//inserting past the end requires empty data
|
||||||
|
dest.vars->append(config(dest.key));
|
||||||
|
}
|
||||||
|
//inserting at the end is handled by an append
|
||||||
|
mode = "append";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
mode = "replace";
|
mode = "replace";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const vconfig::child_list values = cfg.get_children("value");
|
const vconfig::child_list values = cfg.get_children("value");
|
||||||
const vconfig::child_list literals = cfg.get_children("literal");
|
const vconfig::child_list literals = cfg.get_children("literal");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user