BIND 10 trac2375, updated. 2183a9d5b46c20ed8c481f505b57494d3142e654 [2375] Move the FakeState to the master_lexer.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Nov 12 18:44:55 UTC 2012
The branch, trac2375 has been updated
via 2183a9d5b46c20ed8c481f505b57494d3142e654 (commit)
from 89a6e668f647c323849e78449f00efad1ca624c4 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 2183a9d5b46c20ed8c481f505b57494d3142e654
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Mon Nov 12 19:43:17 2012 +0100
[2375] Move the FakeState to the master_lexer.cc
So it can access the impl of the MasterLexer. Also, add the ability to
eat some chars from the input source.
-----------------------------------------------------------------------
Summary of changes:
src/lib/dns/master_lexer.cc | 51 +++++++++++++++++++++++++---
src/lib/dns/master_lexer_state.h | 26 +++++++++++---
src/lib/dns/tests/master_lexer_unittest.cc | 27 ---------------
3 files changed, 67 insertions(+), 37 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dns/master_lexer.cc b/src/lib/dns/master_lexer.cc
index 76c40e1..507c3b1 100644
--- a/src/lib/dns/master_lexer.cc
+++ b/src/lib/dns/master_lexer.cc
@@ -178,11 +178,6 @@ State::getParenCount(const MasterLexer& lexer) const {
return (lexer.impl_->paren_count_);
}
-void
-State::setToken(MasterLexer& lexer, const Token& token) {
- lexer.impl_->token_ = token;
-}
-
class CRLF : public State {
public:
CRLF() {}
@@ -292,6 +287,52 @@ State::start(MasterLexer& lexer, MasterLexer::Options options) {
}
}
+namespace {
+
+// A fake state that just eats something from the input, pushes
+// a given token and calls a callback if it is set. It refers to
+// another state to return.
+class FakeState : public State {
+public:
+ FakeState(const State* next, size_t eat_chars,
+ MasterLexer::Token* token = NULL,
+ const boost::function<void ()>& callback =
+ boost::function<void ()>()) :
+ next_(next),
+ eat_chars_(eat_chars),
+ token_(token),
+ callback_(callback)
+ {}
+ virtual const State* handle(MasterLexer& lexer) const {
+ for (size_t i = 0; i < eat_chars_; ++i) {
+ getLexerImpl(lexer)->source_->getChar();
+ }
+ if (token_ != NULL) {
+ getLexerImpl(lexer)->token_ = *token_;
+ }
+ if (!callback_.empty()) {
+ callback_();
+ }
+ return (next_);
+ }
+private:
+ const State* const next_;
+ size_t eat_chars_;
+ MasterLexer::Token* const token_;
+ const boost::function<void ()> callback_;
+};
+
+}
+
+State*
+State::getFakeState(const State* next, size_t eat_chars,
+ MasterLexer::Token* token,
+ const boost::function<void ()>& callback)
+{
+ // Just allocate new FakeState with the parameters.
+ return (new FakeState(next, eat_chars, token, callback));
+}
+
} // namespace master_lexer_internal
} // end of namespace dns
diff --git a/src/lib/dns/master_lexer_state.h b/src/lib/dns/master_lexer_state.h
index aad557e..a76d8ec 100644
--- a/src/lib/dns/master_lexer_state.h
+++ b/src/lib/dns/master_lexer_state.h
@@ -17,6 +17,8 @@
#include <dns/master_lexer.h>
+#include <boost/function.hpp>
+
namespace isc {
namespace dns {
@@ -55,6 +57,10 @@ namespace master_lexer_internal {
/// this library are expected to use this class.
class State {
public:
+
+ /// \brief Virtual destructor.
+ virtual ~State() {}
+
/// \brief Begin state transitions to get the next token.
///
/// This is the first method that \c MasterLexer needs to call for a
@@ -102,6 +108,21 @@ public:
/// need this method.
static const State& getInstance(ID state_id);
+ /// \brief Returns a fake State instance.
+ ///
+ /// The returned State will eat eat_chars from the input source,
+ /// it'll set the given token if not NULL, call the given callback
+ /// and return the next state when its handle() is called.
+ ///
+ /// This is provided only for testing purposes. MasterLexer shouldn't
+ /// need this method.
+ ///
+ /// The caller is responsible for deleting the State.
+ static State* getFakeState(const State* next, size_t eat_chars,
+ MasterLexer::Token* token = NULL,
+ const boost::function<void ()>& callback =
+ boost::function<void ()>());
+
/// \name Read-only accessors for testing purposes.
///
/// These allow tests to inspect some selected portion of the internal
@@ -126,11 +147,6 @@ protected:
MasterLexer::MasterLexerImpl* getLexerImpl(MasterLexer& lexer) const {
return (lexer.impl_);
}
-
- /// \brief Set the token in master lexer.
- ///
- /// The reason is similar as with getLexerImpl.
- void setToken(MasterLexer& lexer, const MasterLexer::Token& token) const;
};
} // namespace master_lexer_internal
diff --git a/src/lib/dns/tests/master_lexer_unittest.cc b/src/lib/dns/tests/master_lexer_unittest.cc
index 0b19984..c91639e 100644
--- a/src/lib/dns/tests/master_lexer_unittest.cc
+++ b/src/lib/dns/tests/master_lexer_unittest.cc
@@ -32,33 +32,6 @@ using boost::lexical_cast;
namespace {
-// A fake state that just eats something from the input, pushes
-// a given token and calls a callback if it is set. It refers to
-// another state to return.
-class FakeState : public master_lexer_internal::State {
-public:
- FakeState(const State* next, MasterLexer::Token* token = NULL,
- const boost::function<void ()>& callback =
- boost::function<void ()>()) :
- next_(next),
- token_(token),
- callback_(callback)
- {}
- virtual const State* handle(MasterLexer& lexer) const {
- if (token_ != NULL) {
- setToken(lexer, *token_);
- }
- if (!callback_.empty()) {
- callback_();
- }
- return (next_);
- }
-private:
- const State* const next_;
- MasterLexer::Token* const token_;
- const boost::function<void ()> callback_;
-};
-
class MasterLexerTest : public ::testing::Test {
protected:
MasterLexerTest() :
More information about the bind10-changes
mailing list