Kea 2.7.5
master_lexer_inputsource.h
Go to the documentation of this file.
1// Copyright (C) 2012-2024 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef DNS_INPUTSOURCE_H
8#define DNS_INPUTSOURCE_H
9
11
12#include <boost/noncopyable.hpp>
13
14#include <iostream>
15#include <fstream>
16#include <string>
17#include <vector>
18
19namespace isc {
20namespace dns {
21namespace master_lexer_internal {
22
33class InputSource : boost::noncopyable {
34public:
41 static const int END_OF_STREAM = -1;
42
46 UngetBeforeBeginning(const char* file, size_t line, const char* what) :
47 OutOfRange(file, line, what)
48 {}
49 };
50
52 struct OpenError : public Unexpected {
53 OpenError(const char* file, size_t line, const char* what) :
54 Unexpected(file, line, what)
55 {}
56 };
57
63 explicit InputSource(std::istream& input_stream);
64
70 explicit InputSource(const char* filename);
71
74
78 const std::string& getName() const {
79 return (name_);
80 }
81
90 size_t getSize() const {
91 return (input_size_);
92 }
93
110 size_t getPosition() const {
111 return (total_pos_);
112 }
113
115 bool atEOF() const {
116 return (at_eof_);
117 }
118
120 size_t getCurrentLine() const {
121 return (line_);
122 }
123
130 void saveLine();
131
139 void compact();
140
142 void mark();
143
149 int getChar();
150
157 void ungetChar();
158
164 void ungetAll();
165
166private:
167 bool at_eof_;
168 size_t line_;
169 size_t saved_line_;
170
171 std::vector<char> buffer_;
172 size_t buffer_pos_;
173 size_t total_pos_;
174
175 const std::string name_;
176 std::ifstream file_stream_;
177 std::istream& input_;
178 const size_t input_size_;
179};
180
181} // namespace master_lexer_internal
182} // namespace dns
183} // namespace isc
184
185#endif // DNS_INPUTSOURCE_H
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
A generic exception that is thrown when an unexpected error condition occurs.
An input source that is used internally by MasterLexer.
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.
size_t getPosition() const
Returns the current read position in the input source.
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.
size_t getCurrentLine() const
Returns the current line number being read.
size_t getSize() const
Returns the size of the input source in bytes.
void mark()
Calls saveLine() and compact() in sequence.
static const int END_OF_STREAM
Returned by getChar() when end of stream is reached.
int getChar()
Returns a single character from the input source.
const std::string & getName() const
Returns a name for the InputSource.
void saveLine()
Saves the current line being read.
InputSource(std::istream &input_stream)
Constructor which takes an input stream.
Defines the logger used by the top-level component of kea-lfc.
Exception thrown when we fail to open the input file.
OpenError(const char *file, size_t line, const char *what)
Exception thrown when ungetChar() is made to go before the start of buffer.
UngetBeforeBeginning(const char *file, size_t line, const char *what)