Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
588ff1ee
Commit
588ff1ee
authored
Dec 13, 2012
by
Michal 'vorner' Vaner
Browse files
[2428] Interface to get count of sources in lexer
And use it in the master loader, instead of keeping it separately there.
parent
bb1f38e0
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/lib/dns/master_lexer.cc
View file @
588ff1ee
...
...
@@ -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
())
{
...
...
src/lib/dns/master_lexer.h
View file @
588ff1ee
...
...
@@ -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
...
...
src/lib/dns/master_loader.cc
View file @
588ff1ee
...
...
@@ -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
(
--
s
ource
_c
ount
_
==
0
)
{
if
(
lexer_
.
getS
ource
C
ount
()
==
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
...
...
src/lib/dns/tests/master_lexer_unittest.cc
View file @
588ff1ee
...
...
@@ -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.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment