Parcourir la source

[3589] Refactored merge/copy to mergeTo/copyTo in CfgOption.

Marcin Siodelski il y a 10 ans
Parent
commit
0bbf2c0ebe

+ 6 - 6
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

+ 2 - 2
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.
     ///

+ 2 - 2
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();
 }

+ 1 - 1
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

+ 2 - 2
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) {