]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1975] Use reference instead of pointer
authorMichal 'vorner' Vaner <michal.vaner@nic.cz>
Tue, 12 Jun 2012 11:17:43 +0000 (13:17 +0200)
committerMichal 'vorner' Vaner <michal.vaner@nic.cz>
Tue, 12 Jun 2012 11:17:43 +0000 (13:17 +0200)
As the pointer should never be NULL anyway, it might be better to pass
reference.

src/lib/datasrc/container.cc
src/lib/datasrc/container.h
src/lib/datasrc/tests/container_unittest.cc

index 6e0d332e7e3734831202fe2c70903643de50c617..0889bb3e3d93270095a2f46983a55a4c405b54be 100644 (file)
@@ -26,15 +26,15 @@ namespace isc {
 namespace datasrc {
 
 void
-ConfigurableContainer::configure(const ConstElementPtr& config, bool) {
+ConfigurableContainer::configure(const Element& config, bool) {
     // TODO: Implement the cache
     // TODO: Implement recyclation from the old configuration.
     size_t i(0); // Outside of the try to be able to access it in the catch
     try {
         vector<DataSourceInfo> new_data_sources;
-        for (; i < config->size(); ++i) {
+        for (; i < config.size(); ++i) {
             // Extract the parameters
-            const ConstElementPtr dconf(config->get(i));
+            const ConstElementPtr dconf(config.get(i));
             const ConstElementPtr typeElem(dconf->get("type"));
             if (typeElem == ConstElementPtr()) {
                 isc_throw(ConfigurationError, "Missing the type option in "
index 4ffe1b27738519bf0530a8458bf89f0c51032854..f703e3d6fd8b13c4a3ecfc0276418b62d5ed529b 100644 (file)
@@ -213,8 +213,7 @@ public:
     /// \throw DataSourceError if there's a problem creating a data source.
     /// \throw ConfigurationError if the configuration is invalid in some
     ///     sense.
-    void configure(const data::ConstElementPtr& configuration,
-                   bool allow_cache);
+    void configure(const data::Element& configuration, bool allow_cache);
 
     /// \brief Implementation of the Container::search.
     virtual SearchResult search(const dns::Name& zone,
index a4aec1cabe8a747a21aa670481f7a2c2e30a5194..235fe0be9d643d7a59d5e522bc134fe35cfe5386 100644 (file)
@@ -346,7 +346,7 @@ TEST_F(ContainerTest, multiBestMatch) {
 // Check the configuration is empty when the list is empty
 TEST_F(ContainerTest, configureEmpty) {
     ConstElementPtr elem(new ListElement);
-    container_->configure(elem, true);
+    container_->configure(*elem, true);
     EXPECT_TRUE(container_->dataSources().empty());
 }
 
@@ -364,7 +364,7 @@ TEST_F(ContainerTest, configureMulti) {
         "   \"params\": {}"
         "}]"
     ));
-    container_->configure(elem, true);
+    container_->configure(*elem, true);
     EXPECT_EQ(2, container_->dataSources().size());
     checkDS(0, "type1", "{}");
     checkDS(1, "type2", "{}");
@@ -390,7 +390,7 @@ TEST_F(ContainerTest, configureParams) {
             "   \"cache\": \"off\","
             "   \"params\": ") + *param +
             "}]"));
-        container_->configure(elem, true);
+        container_->configure(*elem, true);
         EXPECT_EQ(1, container_->dataSources().size());
         checkDS(0, "t", *param);
     }
@@ -418,12 +418,12 @@ TEST_F(ContainerTest, wrongConfig) {
         NULL
     };
     // Put something inside to see it survives the exception
-    container_->configure(config_elem_, true);
+    container_->configure(*config_elem_, true);
     checkDS(0, "test_type", "{}");
     for (const char** config(configs); *config; ++config) {
         SCOPED_TRACE(*config);
         ConstElementPtr elem(Element::fromJSON(*config));
-        EXPECT_THROW(container_->configure(elem, true),
+        EXPECT_THROW(container_->configure(*elem, true),
                      ConfigurableContainer::ConfigurationError);
         // Still untouched
         checkDS(0, "test_type", "{}");
@@ -436,7 +436,7 @@ TEST_F(ContainerTest, defaults) {
         "{"
         "   \"type\": \"type1\""
         "}]"));
-    container_->configure(elem, true);
+    container_->configure(*elem, true);
     EXPECT_EQ(1, container_->dataSources().size());
     checkDS(0, "type1", "null");
 }
@@ -444,11 +444,11 @@ TEST_F(ContainerTest, defaults) {
 // Check we can call the configure multiple times, to change the configuration
 TEST_F(ContainerTest, reconfigure) {
     ConstElementPtr empty(new ListElement);
-    container_->configure(config_elem_, true);
+    container_->configure(*config_elem_, true);
     checkDS(0, "test_type", "{}");
-    container_->configure(empty, true);
+    container_->configure(*empty, true);
     EXPECT_TRUE(container_->dataSources().empty());
-    container_->configure(config_elem_, true);
+    container_->configure(*config_elem_, true);
     checkDS(0, "test_type", "{}");
 }
 
@@ -458,9 +458,9 @@ TEST_F(ContainerTest, dataSrcError) {
         "{"
         "   \"type\": \"error\""
         "}]"));
-    container_->configure(config_elem_, true);
+    container_->configure(*config_elem_, true);
     checkDS(0, "test_type", "{}");
-    EXPECT_THROW(container_->configure(elem, true), DataSourceError);
+    EXPECT_THROW(container_->configure(*elem, true), DataSourceError);
     checkDS(0, "test_type", "{}");
 }