impl_->has_previous_ = false;
}
+size_t
+MasterLexer::getSourceCount() const {
+ return (impl_->sources_.size());
+}
+
std::string
MasterLexer::getSourceName() const {
if (impl_->sources_.empty()) {
/// \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
initialized_(false),
ok_(true),
many_errors_((options & MANY_ERRORS) != 0),
- source_count_(0),
complete_(false),
seen_error_(false)
{}
}
}
initialized_ = true;
- ++source_count_;
}
bool popSource() {
- if (--source_count_ == 0) {
+ if (lexer_.getSourceCount() == 1) {
return (false);
}
lexer_.popSource();
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.
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
}
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
// 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.