From: Marcin Siodelski Date: Tue, 30 Sep 2014 17:56:08 +0000 (+0200) Subject: [3589] Refactored merge/copy to mergeTo/copyTo in CfgOption. X-Git-Tag: trac3162a_base~4^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0bbf2c0ebe35544228adb3c22814b48014438fce;p=thirdparty%2Fkea.git [3589] Refactored merge/copy to mergeTo/copyTo in CfgOption. --- diff --git a/src/lib/dhcpsrv/cfg_option.cc b/src/lib/dhcpsrv/cfg_option.cc index 63861986bb..c4b4846b16 100644 --- a/src/lib/dhcpsrv/cfg_option.cc +++ b/src/lib/dhcpsrv/cfg_option.cc @@ -54,7 +54,7 @@ CfgOption::add(const OptionPtr& option, const bool persistent, } void -CfgOption::merge(CfgOption& other) const { +CfgOption::mergeTo(CfgOption& other) const { // Merge non-vendor options. mergeInternal(options_, other.options_); // Merge vendor options. @@ -62,11 +62,11 @@ CfgOption::merge(CfgOption& other) const { } void -CfgOption::copy(CfgOption& other) const { - // Create empty object and "merge" data to it. - CfgOption new_cfg; - merge(new_cfg); - other = new_cfg; +CfgOption::copyTo(CfgOption& other) const { + // Remove any existing data in the destination. + other.options_.clearItems(); + other.vendor_options_.clearItems(); + mergeTo(other); } void diff --git a/src/lib/dhcpsrv/cfg_option.h b/src/lib/dhcpsrv/cfg_option.h index a012381ce1..a8a66b2be8 100644 --- a/src/lib/dhcpsrv/cfg_option.h +++ b/src/lib/dhcpsrv/cfg_option.h @@ -260,14 +260,14 @@ public: /// copied. /// /// @param [out] other Configuration object to merge to. - void merge(CfgOption& other) const; + void mergeTo(CfgOption& other) const; /// @brief Copies this configuration to another configuration. /// /// This method copies options configuration to another object. /// /// @param [out] other An object to copy the configuration to. - void copy(CfgOption& other) const; + void copyTo(CfgOption& other) const; /// @brief Appends encapsulated options to top-level options. /// diff --git a/src/lib/dhcpsrv/dhcp_parsers.cc b/src/lib/dhcpsrv/dhcp_parsers.cc index 6a7004b69f..3686818fcf 100644 --- a/src/lib/dhcpsrv/dhcp_parsers.cc +++ b/src/lib/dhcpsrv/dhcp_parsers.cc @@ -1066,9 +1066,9 @@ SubnetConfigParser::createSubnet() { } // Merge globally defined options to the subnet specific options. - CfgMgr::instance().getStagingCfg()->getCfgOption()->merge(*options_); + CfgMgr::instance().getStagingCfg()->getCfgOption()->mergeTo(*options_); // Copy all options to the subnet configuration. - options_->copy(*subnet_->getCfgOption()); + options_->copyTo(*subnet_->getCfgOption()); // Append suboptions to the top-level options. subnet_->getCfgOption()->encapsulate(); } diff --git a/src/lib/dhcpsrv/srv_config.cc b/src/lib/dhcpsrv/srv_config.cc index f82075ae85..f3f9912930 100644 --- a/src/lib/dhcpsrv/srv_config.cc +++ b/src/lib/dhcpsrv/srv_config.cc @@ -92,7 +92,7 @@ SrvConfig::copy(SrvConfig& new_config) const { new_config.setCfgIface(cfg_iface_); // Replace option definitions. cfg_option_def_->copyTo(*new_config.cfg_option_def_); - cfg_option_->copy(*new_config.cfg_option_); + cfg_option_->copyTo(*new_config.cfg_option_); } void diff --git a/src/lib/dhcpsrv/tests/cfg_option_unittest.cc b/src/lib/dhcpsrv/tests/cfg_option_unittest.cc index 557e2b9c83..121a2ccc73 100644 --- a/src/lib/dhcpsrv/tests/cfg_option_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_option_unittest.cc @@ -167,7 +167,7 @@ TEST(CfgOption, merge) { // Merge source configuration to the destination configuration. The options // in the destination should be preserved. The options from the source // configuration should be added. - ASSERT_NO_THROW(cfg_src.merge(cfg_dst)); + ASSERT_NO_THROW(cfg_src.mergeTo(cfg_dst)); // Validate the options in the dhcp6 option space in the destination. for (uint16_t code = 100; code < 110; ++code) { @@ -221,7 +221,7 @@ TEST(CfgOptionTest, copy) { // Copy entire configuration to the destination. This should override any // existing data. - ASSERT_NO_THROW(cfg_src.copy(cfg_dst)); + ASSERT_NO_THROW(cfg_src.copyTo(cfg_dst)); // Validate options in the destination configuration. for (uint16_t code = 100; code < 110; ++code) {