From 192fbdc17355d6a26e5c4b966190cf8f18dda57e Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Thu, 9 Nov 2017 21:11:59 +1100 Subject: [PATCH] Config: added function to move children from one config to another The regular append_children function makes a copy of the applicable child tags. This moves them from the source to the destination configs. Do note it leaves the source tags empty. --- src/config.cpp | 11 +++++++++++ src/config.hpp | 3 +++ 2 files changed, 14 insertions(+) diff --git a/src/config.cpp b/src/config.cpp index bbdebbfd7a5..34c32c66959 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -255,6 +255,17 @@ void config::append(const config& cfg) } } +void config::append_children_by_move(config& cfg, const std::string& key) +{ + check_valid(cfg); + + // DO note this leaves the tags empty in the source config. Not sure if + // that should be changed. + for(config& value : cfg.child_range(key)) { + add_child(key, std::move(value)); + } +} + void config::merge_children(const std::string& key) { check_valid(); diff --git a/src/config.hpp b/src/config.hpp index 6ab3d197336..2df54d5029a 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -733,6 +733,9 @@ public: */ void append_children(const config &cfg, const std::string& key); + /** Moves children with the given name from the given config to this one. */ + void append_children_by_move(config& cfg, const std::string& key); + /** * Adds attributes from @a cfg. */