config::const_child_itors as_array_visitor<const vi_policy_const>::from_indexed(as_array_visitor::param_t state) const { if(static_cast<int>(state.child_->child_count(state.key_)) <= state.index_) { return get_child_range(non_empty_const_cfg, "_", 0, 1); } return get_child_range(*state.child_, state.key_, state.index_, 1); }
result_t operator()(config& child, const std::string& key, int startindex, int endindex) const { assert(endindex - startindex >= 0); if(endindex > 0) { // NOTE: currently this is only called from as_range_visitor_base<vi_policy_create> // Based on that assumption we use vi_policy_create::get_child_at here instead of making this // a class template. vi_policy_create::get_child_at(child, key, endindex - 1); } int size_diff = datasource_.size() - (endindex - startindex); // remove configs first while(size_diff < 0) { child.remove_child(key, startindex); ++size_diff; } std::size_t index = 0; for(index = 0; index < static_cast<std::size_t>(size_diff); ++index) { child.add_child_at(key, config(), startindex + index).swap(datasource_[index]); } for(; index < datasource_.size(); ++index) { child.child(key, startindex + index).swap(datasource_[index]); } return get_child_range(child, key, startindex, datasource_.size()); }
node_ptr node::get_child(const std::string& key) { const child_range range = get_child_range(key); if(range.first == range.second) { return node_ptr(); } else { return range.first->second; } }
void node::erase_child(const boost::shared_ptr<node>& child_node) { child_range range = get_child_range(child_node->name()); while(range.first != range.second) { if(range.first->second == child_node) { childmap_.erase(range.first); break; } ++range.first; } std::vector<boost::shared_ptr<node> >::iterator i = std::find(children_.begin(),children_.end(),child_node); if(i != children_.end()) { children_.erase(i); } }
result_t from_indexed(param_t state) const { // Ensure we have a config at the given explicit position. V::get_child_at(*state.child_, state.key_, state.index_); return get_child_range(*state.child_, state.key_, state.index_, 1); }
result_t from_named(param_t state) const { return get_child_range(*state.child_, state.key_, 0, state.child_->child_count(state.key_)); }