From: Michal 'vorner' Vaner Date: Thu, 13 Dec 2012 11:32:38 +0000 (+0100) Subject: [2428] Interface to get count of sources in lexer X-Git-Tag: bind10-1.0.0-beta-release~24^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=588ff1eef555b3362954296388e93cf8729f267b;p=thirdparty%2Fkea.git [2428] Interface to get count of sources in lexer And use it in the master loader, instead of keeping it separately there. --- diff --git a/src/lib/dns/master_lexer.cc b/src/lib/dns/master_lexer.cc index 4593b48b5f..e192c72298 100644 --- a/src/lib/dns/master_lexer.cc +++ b/src/lib/dns/master_lexer.cc @@ -149,6 +149,11 @@ MasterLexer::popSource() { impl_->has_previous_ = false; } +size_t +MasterLexer::getSourceCount() const { + return (impl_->sources_.size()); +} + std::string MasterLexer::getSourceName() const { if (impl_->sources_.empty()) { diff --git a/src/lib/dns/master_lexer.h b/src/lib/dns/master_lexer.h index 35586feb0f..76147c8029 100644 --- a/src/lib/dns/master_lexer.h +++ b/src/lib/dns/master_lexer.h @@ -405,6 +405,11 @@ public: /// \throw isc::InvalidOperation Called with no pushed source. void popSource(); + /// \brief Get number of sources inside the lexer. + /// + /// This method never throws. + size_t getSourceCount() const; + /// \brief Return the name of the current input source name. /// /// If it's a file, it will be the C string given at the corresponding diff --git a/src/lib/dns/master_loader.cc b/src/lib/dns/master_loader.cc index 9a7f1ee3d9..b3474648fd 100644 --- a/src/lib/dns/master_loader.cc +++ b/src/lib/dns/master_loader.cc @@ -63,7 +63,6 @@ public: initialized_(false), ok_(true), many_errors_((options & MANY_ERRORS) != 0), - source_count_(0), complete_(false), seen_error_(false) {} @@ -94,11 +93,10 @@ public: } } initialized_ = true; - ++source_count_; } bool popSource() { - if (--source_count_ == 0) { + if (lexer_.getSourceCount() == 1) { return (false); } lexer_.popSource(); @@ -108,7 +106,6 @@ public: void pushStreamSource(std::istream& stream) { lexer_.pushSource(stream); initialized_ = true; - ++source_count_; } // Get a string token. Handle it as error if it is not string. @@ -200,7 +197,6 @@ private: bool ok_; // Is it OK to continue loading? const bool many_errors_; // Are many errors allowed (or should we abort // on the first) - size_t source_count_; // How many sources are currently pushed. public: bool complete_; // All work done. bool seen_error_; // Was there at least one error during the diff --git a/src/lib/dns/tests/master_lexer_unittest.cc b/src/lib/dns/tests/master_lexer_unittest.cc index b751da84f3..8c21bcc3fa 100644 --- a/src/lib/dns/tests/master_lexer_unittest.cc +++ b/src/lib/dns/tests/master_lexer_unittest.cc @@ -60,8 +60,10 @@ TEST_F(MasterLexerTest, preOpen) { } TEST_F(MasterLexerTest, pushStream) { + EXPECT_EQ(0, lexer.getSourceCount()); lexer.pushSource(ss); EXPECT_EQ(expected_stream_name, lexer.getSourceName()); + EXPECT_EQ(1, lexer.getSourceCount()); // From the point of view of this test, we only have to check (though // indirectly) getSourceLine calls InputSource::getCurrentLine. It should @@ -70,18 +72,22 @@ TEST_F(MasterLexerTest, pushStream) { // By popping it the stack will be empty again. lexer.popSource(); + EXPECT_EQ(0, lexer.getSourceCount()); checkEmptySource(lexer); } TEST_F(MasterLexerTest, pushFile) { // We use zone file (-like) data, but in this test that actually doesn't // matter. + EXPECT_EQ(0, lexer.getSourceCount()); EXPECT_TRUE(lexer.pushSource(TEST_DATA_SRCDIR "/masterload.txt")); + EXPECT_EQ(1, lexer.getSourceCount()); EXPECT_EQ(TEST_DATA_SRCDIR "/masterload.txt", lexer.getSourceName()); EXPECT_EQ(1, lexer.getSourceLine()); lexer.popSource(); checkEmptySource(lexer); + EXPECT_EQ(0, lexer.getSourceCount()); // If we give a non NULL string pointer, its content will be intact // if pushSource succeeds.