Kea 2.5.8
isc::dns::master_lexer_internal::InputSource Class Reference

An input source that is used internally by MasterLexer. More...

#include <master_lexer_inputsource.h>

+ Inheritance diagram for isc::dns::master_lexer_internal::InputSource:

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ InputSource() [1/2]

isc::dns::master_lexer_internal::InputSource::InputSource ( std::istream &  input_stream)
explicit

Constructor which takes an input stream.

The stream is read-from, but it is not closed.

Exceptions
OpenErrorIf the data size of the input stream cannot be detected.

Definition at line 85 of file master_lexer_inputsource.cc.

◆ InputSource() [2/2]

isc::dns::master_lexer_internal::InputSource::InputSource ( const char *  filename)
explicit

Constructor which takes a filename to read from.

The associated file stream is managed internally.

Exceptions
OpenErrorwhen opening the input file fails or the size of the file cannot be detected.

Definition at line 117 of file master_lexer_inputsource.cc.

◆ ~InputSource()

isc::dns::master_lexer_internal::InputSource::~InputSource ( )

Destructor.

Definition at line 128 of file master_lexer_inputsource.cc.

Member Function Documentation

◆ atEOF()

bool isc::dns::master_lexer_internal::InputSource::atEOF ( ) const
inline

Returns if the input source is at end of file.

Definition at line 115 of file master_lexer_inputsource.h.

◆ compact()

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().

◆ getChar()

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.

Exceptions
MasterLexer::ReadErrorwhen 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.

+ Here is the call graph for this function:

◆ getCurrentLine()

size_t isc::dns::master_lexer_internal::InputSource::getCurrentLine ( ) const
inline

Returns the current line number being read.

Definition at line 120 of file master_lexer_inputsource.h.

◆ getName()

const std::string & isc::dns::master_lexer_internal::InputSource::getName ( ) const
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().

◆ getPosition()

size_t isc::dns::master_lexer_internal::InputSource::getPosition ( ) const
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.

Exceptions
None

Definition at line 110 of file master_lexer_inputsource.h.

◆ getSize()

size_t isc::dns::master_lexer_internal::InputSource::getSize ( ) const
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.

Exceptions
None

Definition at line 90 of file master_lexer_inputsource.h.

◆ mark()

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().

+ Here is the call graph for this function:

◆ 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().

◆ ungetAll()

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.

◆ ungetChar()

void isc::dns::master_lexer_internal::InputSource::ungetChar ( )

Skips backward a single character in the input source.

The last-read character is unget.

Exceptions
UngetBeforeBeginningif 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.

Member Data Documentation

◆ END_OF_STREAM

const int isc::dns::master_lexer_internal::InputSource::END_OF_STREAM = -1
static

Returned by getChar() when end of stream is reached.

Note
C++ allows a static const class member of an integral type to be used without explicit definition as long as its address isn't required. But, since this is a public member variable and we cannot assume how it's used, we give a definition in the implementation.

Definition at line 41 of file master_lexer_inputsource.h.

Referenced by getChar().


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