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:
Patrick Parker 2008-08-31 19:56:15 +00:00
parent 7498fd2fc5
commit 6511160a75
3 changed files with 27 additions and 5 deletions

View File

@ -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 child_map::const_iterator i = children.find(key);

View File

@ -75,6 +75,7 @@ public:
child_itors child_range(const std::string& key);
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_map& all_children() const;

View File

@ -1313,9 +1313,21 @@ namespace {
std::string mode = cfg["mode"]; // replace, append, merge, or insert
if(mode == "extend") {
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";
}
}
const vconfig::child_list values = cfg.get_children("value");
const vconfig::child_list literals = cfg.get_children("literal");