Helper class for buffering a std::istream
.
More...
#include <buffered_istream.hpp>
Public Member Functions | |
buffered_istream (std::istream &in) | |
int | get () |
Gets and consumes a character from the buffer. More... | |
int | peek () |
Gets a character from the buffer. More... | |
bool | eof () const |
Is the end of input reached? More... | |
std::istream & | stream () |
Returns the owned stream. More... | |
Private Member Functions | |
void | fill_buffer () |
Fills the buffer. More... | |
Private Attributes | |
std::istream & | stream_ |
The input to read from. More... | |
char | buffer_ [1024] |
Buffer to store the data read from std::istream . More... | |
unsigned | buffer_size_ |
The size of buffer_. More... | |
unsigned | buffer_offset_ |
The offset of the current character in the buffer. More... | |
bool | eof_ |
Is the end of input reached? More... | |
Helper class for buffering a std::istream
.
This class is used to buffer a std::istream
which is used for small reads; a character at a time. The std::istream
needs to create a sentinel object for every read and profiling showed the std::istream
class was causing a lot of overhead when parsing WML. This class helps by reading chunks from the std::stream
and store them in an internal buffer. Then the next request can deliver data from this buffer.
Since the class is only designed for small reads it only offers the get() and the peek() to get data and eof() to signal the end of data. The original stream should not be used from, while being owned by this class.
Definition at line 42 of file buffered_istream.hpp.
|
inlineexplicit |
Definition at line 46 of file buffered_istream.hpp.
|
inline |
Is the end of input reached?
Definition at line 101 of file buffered_istream.hpp.
References eof_.
Referenced by preprocessor_data::get_chunk(), preprocessor_data::read_line(), preprocessor_data::read_rest_of_line(), preprocessor_data::skip_eol(), and preprocessor_data::skip_spaces().
|
inlineprivate |
|
inline |
Gets and consumes a character from the buffer.
EOF | The end of input has been read. |
Definition at line 61 of file buffered_istream.hpp.
References buffer_, buffer_offset_, c, eof_, fill_buffer(), and UNLIKELY.
Referenced by preprocessor_data::get_chunk(), tokenizer::next_char_fast(), preprocessor_data::read_line(), preprocessor_data::read_rest_of_line(), preprocessor_data::read_word(), preprocessor_data::skip_eol(), and preprocessor_data::skip_spaces().
|
inline |
Gets a character from the buffer.
This version only gets a character, but doesn't consume it.
EOF | The end of input has been read. |
Definition at line 88 of file buffered_istream.hpp.
References buffer_, buffer_offset_, eof_, fill_buffer(), and UNLIKELY.
Referenced by preprocessor_data::get_chunk(), tokenizer::peek_char(), preprocessor_data::read_rest_of_line(), preprocessor_data::read_word(), and preprocessor_data::skip_spaces().
|
inline |
Returns the owned stream.
Definition at line 107 of file buffered_istream.hpp.
References stream_.
Referenced by tokenizer::tokenizer(), and tokenizer::~tokenizer().
|
private |
Buffer to store the data read from std::istream
.
Reading from std::istream
isn't to fast, especially not a byte at a time. This buffer is used to buffer x bytes at a time. The size of the buffer is determined experimentally.
Definition at line 124 of file buffered_istream.hpp.
|
private |
The offset of the current character in the buffer.
buffer_[buffer_offset_] is the current character, and can be peaked or consumed.
Definition at line 145 of file buffered_istream.hpp.
|
private |
The size of buffer_.
When buffering the data there might be less data in the stream as in the buffer. This variable contains the exact size of the buffer. For example the last chunk read from the stream is unlikely to have the same size a buffer_.
Definition at line 134 of file buffered_istream.hpp.
|
private |
Is the end of input reached?
Definition at line 148 of file buffered_istream.hpp.
|
private |
The input to read from.
Definition at line 115 of file buffered_istream.hpp.
Referenced by stream().