Kea 2.7.6
|
An input source that is used internally by MasterLexer. More...
#include <master_lexer_inputsource.h>
Classes | |
struct | OpenError |
Exception thrown when we fail to open the input file. More... | |
struct | UngetBeforeBeginning |
Exception thrown when ungetChar() is made to go before the start of buffer. More... | |
Public Member Functions | |
InputSource (const char *filename) | |
Constructor which takes a filename to read from. | |
InputSource (std::istream &input_stream) | |
Constructor which takes an input stream. | |
~InputSource () | |
Destructor. | |
bool | atEOF () const |
Returns if the input source is at end of file. | |
void | compact () |
Removes buffered content before the current location in the InputSource . | |
int | getChar () |
Returns a single character from the input source. | |
size_t | getCurrentLine () const |
Returns the current line number being read. | |
const std::string & | getName () const |
Returns a name for the InputSource. | |
size_t | getPosition () const |
Returns the current read position in the input source. | |
size_t | getSize () const |
Returns the size of the input source in bytes. | |
void | mark () |
Calls saveLine() and compact() in sequence. | |
void | saveLine () |
Saves the current line being read. | |
void | ungetAll () |
Forgets what was read, and skips back to the position where compact() was last called. | |
void | ungetChar () |
Skips backward a single character in the input source. | |
Static Public Attributes | |
static const int | END_OF_STREAM = -1 |
Returned by getChar() when end of stream is reached. | |
An input source that is used internally by MasterLexer.
This is a helper internal class for MasterLexer, and represents state of a single source of the entire zone data to be parsed. Normally this means the master zone file, but MasterLexer can have multiple InputSources if $INCLUDE is used. The source can also be generic input stream (std::istream).
This class is not meant for public use. We also enforce that instances are non-copyable.
Definition at line 33 of file master_lexer_inputsource.h.
|
explicit |
Constructor which takes an input stream.
The stream is read-from, but it is not closed.
OpenError | If the data size of the input stream cannot be detected. |
Definition at line 85 of file master_lexer_inputsource.cc.
|
explicit |
Constructor which takes a filename to read from.
The associated file stream is managed internally.
OpenError | when opening the input file fails or the size of the file cannot be detected. |
Definition at line 117 of file master_lexer_inputsource.cc.
isc::dns::master_lexer_internal::InputSource::~InputSource | ( | ) |
Destructor.
Definition at line 128 of file master_lexer_inputsource.cc.
|
inline |
Returns if the input source is at end of file.
Definition at line 115 of file master_lexer_inputsource.h.
void isc::dns::master_lexer_internal::InputSource::compact | ( | ) |
Removes buffered content before the current location in the InputSource
.
It's not possible to ungetChar()
after this, unless we read more data using getChar()
.
TODO: Please make this method private if it is unused after the MasterLexer implementation is complete (and only mark()
is used instead).
Definition at line 202 of file master_lexer_inputsource.cc.
Referenced by mark().
int isc::dns::master_lexer_internal::InputSource::getChar | ( | ) |
Returns a single character from the input source.
If end of file is reached, END_OF_STREAM
is returned.
MasterLexer::ReadError | when reading from the input stream or file fails. |
Definition at line 135 of file master_lexer_inputsource.cc.
References END_OF_STREAM, getName(), and isc_throw.
|
inline |
Returns the current line number being read.
Definition at line 120 of file master_lexer_inputsource.h.
|
inline |
Returns a name for the InputSource.
Typically this is the filename, but if the InputSource was constructed for an std::istream
, it returns a name in the format "stream-%p".
Definition at line 78 of file master_lexer_inputsource.h.
Referenced by getChar().
|
inline |
Returns the current read position in the input source.
This method returns the position of the character that was last retrieved from the source. Unless some characters have been "ungotten" by ungetChar()
or ungetAll()
, this value is equal to the number of calls to getChar()
until it reaches the END_OF_STREAM. Note that the position of the first character in the source is 1. At the point of the last character, the return value of this method should be equal to that of getSize()
, and recognizing END_OF_STREAM doesn't increase the position.
If ungetChar()
or ungetAll()
is called, the position is decreased by the number of "ungotten" characters. So the return values may not always monotonically increase.
None |
Definition at line 110 of file master_lexer_inputsource.h.
|
inline |
Returns the size of the input source in bytes.
If the size is unknown, it returns MasterLexer::SOURCE_SIZE_UNKNOWN
.
See MasterLexer::getTotalSourceSize()
for the definition of the size of sources and for when the size can be unknown.
None |
Definition at line 90 of file master_lexer_inputsource.h.
void isc::dns::master_lexer_internal::InputSource::mark | ( | ) |
Calls saveLine()
and compact()
in sequence.
Definition at line 213 of file master_lexer_inputsource.cc.
References compact(), and saveLine().
void isc::dns::master_lexer_internal::InputSource::saveLine | ( | ) |
Saves the current line being read.
Later, when ungetAll()
is called, it skips back to the last-saved line.
TODO: Please make this method private if it is unused after the MasterLexer implementation is complete (and only mark()
is used instead).
Definition at line 197 of file master_lexer_inputsource.cc.
Referenced by mark().
void isc::dns::master_lexer_internal::InputSource::ungetAll | ( | ) |
Forgets what was read, and skips back to the position where compact()
was last called.
If compact()
was not called, it skips back to where reading started. If saveLine()
was called previously, it sets the current line number to the line number saved.
Definition at line 188 of file master_lexer_inputsource.cc.
References isc_throw_assert.
void isc::dns::master_lexer_internal::InputSource::ungetChar | ( | ) |
Skips backward a single character in the input source.
The last-read character is unget.
UngetBeforeBeginning | if we go backwards past the start of reading, or backwards past the last time compact() was called. |
Definition at line 172 of file master_lexer_inputsource.cc.
References isc_throw.
|
static |
Returned by getChar() when end of stream is reached.
Definition at line 41 of file master_lexer_inputsource.h.
Referenced by getChar().