]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3589] Refactored merge/copy to mergeTo/copyTo in CfgOption.
authorMarcin Siodelski <marcin@isc.org>
Tue, 30 Sep 2014 17:56:08 +0000 (19:56 +0200)
committerMarcin Siodelski <marcin@isc.org>
Tue, 30 Sep 2014 17:56:08 +0000 (19:56 +0200)
src/lib/dhcpsrv/cfg_option.cc
src/lib/dhcpsrv/cfg_option.h
src/lib/dhcpsrv/dhcp_parsers.cc
src/lib/dhcpsrv/srv_config.cc
src/lib/dhcpsrv/tests/cfg_option_unittest.cc

index 63861986bbe1238af68961fdba19d7e598c5e305..c4b4846b16df09799a99f38e0694617c2fb53935 100644 (file)
@@ -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
index a012381ce175f5dcc05ed8d865cde1259eacc058..a8a66b2be8b5f8c54ba66a169b78c67eb71732ef 100644 (file)
@@ -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.
     ///
index 6a7004b69fbdcf96a099c4a615c2f7b4deb8e060..3686818fcf75753d15263f854ea4df4597e4a60e 100644 (file)
@@ -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();
 }
index f82075ae85eb738523cea30362c54046722de9ed..f3f99129303c14c3dd033296e554368ae59cc3f7 100644 (file)
@@ -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
index 557e2b9c83e2962ef3d04670de5ab421e5fd746f..121a2ccc7355d80c8ad5160850901bf6c4099a8d 100644 (file)
@@ -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) {