Kea  1.9.9-git
isc::dns::master_lexer_internal::State Class Referenceabstract

Tokenization state for MasterLexer. More...

#include <master_lexer_state.h>

Public Types

enum  ID { CRLF, String, QString, Number }
 Types of states. More...

Public Member Functions

virtual ~State ()
 Virtual destructor. More...
virtual void handle (MasterLexer &lexer) const =0
 Handle the process of one specific state. More...
Read-only accessors for testing purposes.

These allow tests to inspect some selected portion of the internal states of MasterLexer.

These shouldn't be used except for testing purposes.

bool wasLastEOL (const MasterLexer &lexer) const
const MasterTokengetToken (const MasterLexer &lexer) const
size_t getParenCount (const MasterLexer &lexer) const

Static Public Member Functions

static const StategetInstance (ID state_id)
 Returns a State instance of the given state. More...
static const Statestart (MasterLexer &lexer, MasterLexer::Options options)
 Begin state transitions to get the next token. More...

Protected Member Functions

MasterLexer::MasterLexerImpl * getLexerImpl (MasterLexer &lexer) const
 An accessor to the internal implementation class of MasterLexer. More...

Detailed Description

Tokenization state for MasterLexer.

This is a base class of classes that represent various states of a single tokenization session of MasterLexer, i.e., the states used for a single call to MasterLexer::getNextToken().

It follows the convention of the state design pattern: each derived class corresponds to a specific state, and the state transition takes place through the virtual method named handle(). The handle() method takes the main MasterLexer object that holds all necessary internal context, and updates it as necessary; each State derived class is completely stateless.

The initial transition takes place in a static method of the base class, start(). This is mainly for implementation convenience; we need to pass options given to MasterLexer::getNextToken() for the initial state, so it makes more sense to separate the interface for the transition from the initial state.

If the whole lexer transition is completed within start(), it sets the identified token and returns NULL; otherwise it returns a pointer to an object of a specific state class that completes the session on the call of handle().

As is usual in the state design pattern, the State class is made a friend class of MasterLexer and can refer to its internal details. This is intentional; essentially its a part of MasterLexer and is defined as a separate class only for implementation clarity and better testability. It's defined in a publicly visible header, but that's only for testing purposes. No normal application or even no other classes of this library are expected to use this class.

Definition at line 48 of file master_lexer_state.h.

Member Enumeration Documentation

Types of states.

Specific states are basically hidden within the implementation, but we'd like to allow tests to examine them, so we provide a way to get an instance of a specific state.


Just seen a carriage-return character.


Handling a string token.


Handling a quoted string token.


Handling a number.

Definition at line 91 of file master_lexer_state.h.

Constructor & Destructor Documentation

virtual isc::dns::master_lexer_internal::State::~State ( )

Virtual destructor.

In our usage this actually doesn't matter, but some compilers complain about it and we need to silence them.

Definition at line 54 of file master_lexer_state.h.

Member Function Documentation

static const State& isc::dns::master_lexer_internal::State::getInstance ( ID  state_id)

Returns a State instance of the given state.

This is provided only for testing purposes so tests can check the behavior of each state separately. MasterLexer shouldn't need this method.

MasterLexer::MasterLexerImpl* isc::dns::master_lexer_internal::State::getLexerImpl ( MasterLexer lexer) const

An accessor to the internal implementation class of MasterLexer.

This is provided for specific derived classes as they are not direct friends of MasterLexer.

lexerThe lexer object that holds the main context.
A pointer to the implementation class object of the given lexer. This is never NULL.

Definition at line 126 of file master_lexer_state.h.

size_t isc::dns::master_lexer_internal::State::getParenCount ( const MasterLexer lexer) const
const MasterToken& isc::dns::master_lexer_internal::State::getToken ( const MasterLexer lexer) const
virtual void isc::dns::master_lexer_internal::State::handle ( MasterLexer lexer) const
pure virtual

Handle the process of one specific state.

This method is expected to be called on the object returned by start(). In the usual state transition design pattern, it would return the next state. But as we noticed, we never have another state, so we simplify it by not returning anything instead of returning NULL every time.

MasterLexer::ReadErrorUnexpected I/O error
std::bad_allocInternal resource allocation failure
lexerThe lexer object that holds the main context.
static const State* isc::dns::master_lexer_internal::State::start ( MasterLexer lexer,
MasterLexer::Options  options 

Begin state transitions to get the next token.

This is the first method that MasterLexer needs to call for a tokenization session. The lexer passes a reference to itself and options given in getNextToken().

MasterLexer::ReadErrorUnexpected I/O error
std::bad_allocInternal resource allocation failure
lexerThe lexer object that holds the main context.
optionsThe options passed to getNextToken().
A pointer to the next state object or NULL if the transition is completed.
bool isc::dns::master_lexer_internal::State::wasLastEOL ( const MasterLexer lexer) const

The documentation for this class was generated from the following file: