Browse Source

[1975] Use reference instead of pointer

As the pointer should never be NULL anyway, it might be better to pass
reference.
Michal 'vorner' Vaner 13 years ago
parent
commit
abf827ef79

+ 3 - 3
src/lib/datasrc/container.cc

@@ -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 "

+ 1 - 2
src/lib/datasrc/container.h

@@ -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,

+ 11 - 11
src/lib/datasrc/tests/container_unittest.cc

@@ -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", "{}");
 }