From: Michal 'vorner' Vaner Date: Tue, 12 Jun 2012 11:17:43 +0000 (+0200) Subject: [1975] Use reference instead of pointer X-Git-Tag: trac2351_base~97^2~9^2~4^2~5^2~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=abf827ef79067d74865bc4e6da349788e71fca7d;p=thirdparty%2Fkea.git [1975] Use reference instead of pointer As the pointer should never be NULL anyway, it might be better to pass reference. --- diff --git a/src/lib/datasrc/container.cc b/src/lib/datasrc/container.cc index 6e0d332e7e..0889bb3e3d 100644 --- a/src/lib/datasrc/container.cc +++ b/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 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 " diff --git a/src/lib/datasrc/container.h b/src/lib/datasrc/container.h index 4ffe1b2773..f703e3d6fd 100644 --- a/src/lib/datasrc/container.h +++ b/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, diff --git a/src/lib/datasrc/tests/container_unittest.cc b/src/lib/datasrc/tests/container_unittest.cc index a4aec1cabe..235fe0be9d 100644 --- a/src/lib/datasrc/tests/container_unittest.cc +++ b/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", "{}"); }