|
CLAW Library (a C++ Library Absolutely Wonderful) 1.5.5
|
This class is made to help reading istreams with a buffer. More...
#include <buffered_istream.hpp>
Public Member Functions | |
| buffered_istream (stream_type &f) | |
| Constructor. | |
| ~buffered_istream () | |
| Destructor. | |
| unsigned int | remaining () const |
| Tell how many bytes are ready in the buffer. | |
| bool | read_more (unsigned int n) |
| Increase the number of ready bytes to a given number. | |
| const char * | get_buffer () const |
| Get the input buffer. | |
| char | get_next () |
| Get the next value in the buffer and move one byte forward. | |
| bool | read (char *buf, unsigned int n) |
| Read a range of data. | |
| void | move (unsigned int n) |
| Move some bytes forward. | |
| void | close () |
| Closes this buffer (not the stream). | |
| operator bool () const | |
| Tell if there is still datas in the buffer/stream. | |
Private Types | |
| typedef Stream | stream_type |
| The type of the stream we will read. | |
Private Attributes | |
| stream_type & | m_stream |
| The stream we're reading. | |
| char * | m_begin |
| Pointer to the begining of the buffer. | |
| char * | m_end |
| Pointer to the first invalid byte after the end of the buffer. | |
| char * | m_current |
| Pointer to the current not already read valid byte. | |
| unsigned int | m_buffer_size |
| The size of the allocated buffer. | |
This class is made to help reading istreams with a buffer.
Definition at line 42 of file buffered_istream.hpp.
typedef Stream claw::buffered_istream< Stream >::stream_type [private] |
The type of the stream we will read.
Definition at line 46 of file buffered_istream.hpp.
| claw::buffered_istream< Stream >::buffered_istream | ( | stream_type & | f | ) |
Constructor.
| f | The file associated to the stream. |
Definition at line 38 of file buffered_istream.tpp.
References claw::buffered_istream< Stream >::m_begin, claw::buffered_istream< Stream >::m_buffer_size, claw::buffered_istream< Stream >::m_current, and claw::buffered_istream< Stream >::m_end.
| claw::buffered_istream< Stream >::~buffered_istream | ( | ) |
Destructor.
Definition at line 52 of file buffered_istream.tpp.
| void claw::buffered_istream< Stream >::close | ( | ) |
Closes this buffer (not the stream).
The cursor of the stream is repositioned according to the remaining data, and the buffer is cleared.
Definition at line 183 of file buffered_istream.tpp.
| const char * claw::buffered_istream< Stream >::get_buffer | ( | ) | const |
Get the input buffer.
Definition at line 118 of file buffered_istream.tpp.
Referenced by claw::graphic::bitmap::reader::rle_bitmap_output_buffer< Coded4bits >::copy().
{
return m_current;
} // buffered_istream::get_buffer()
| char claw::buffered_istream< Stream >::get_next | ( | ) |
Get the next value in the buffer and move one byte forward.
Definition at line 128 of file buffered_istream.tpp.
Referenced by claw::graphic::bitmap::reader::rle_bitmap_decoder< OutputBuffer >::read_mode().
| void claw::buffered_istream< Stream >::move | ( | unsigned int | n | ) |
Move some bytes forward.
| n | The number of bytes to skip. |
Definition at line 169 of file buffered_istream.tpp.
Referenced by claw::graphic::bitmap::reader::rle_bitmap_output_buffer< Coded4bits >::copy().
| claw::buffered_istream< Stream >::operator bool | ( | ) | const |
Tell if there is still datas in the buffer/stream.
Definition at line 195 of file buffered_istream.tpp.
| bool claw::buffered_istream< Stream >::read | ( | char * | buf, |
| unsigned int | n | ||
| ) |
Read a range of data.
| buf | The buffer in which we write the read data. |
| n | The number of bytes to read. |
Definition at line 145 of file buffered_istream.tpp.
Referenced by claw::graphic::pcx::reader::load_256_color_mapped().
| bool claw::buffered_istream< Stream >::read_more | ( | unsigned int | n | ) |
Increase the number of ready bytes to a given number.
| n | The number of bytes you need. |
Definition at line 77 of file buffered_istream.tpp.
Referenced by claw::graphic::bitmap::reader::rle_bitmap_output_buffer< Coded4bits >::copy(), and claw::graphic::bitmap::reader::rle_bitmap_decoder< OutputBuffer >::read_mode().
{
if ( n <= remaining() )
return true;
unsigned int r = remaining();
// we'll reach the end of the buffer
if ( m_current + n > m_begin + m_buffer_size )
{
// try to avoid reallocation
if (n <= m_buffer_size)
std::copy(m_current, m_end, m_begin);
else // not enough space in the buffer
{
m_buffer_size = n;
char* new_buffer = new char[m_buffer_size];
std::copy(m_current, m_end, new_buffer);
delete[] m_begin;
m_begin = new_buffer;
}
m_current = m_begin;
m_end = m_current + r;
}
m_stream.read( m_end, n-r );
m_end += m_stream.gcount();
return !!m_stream;
} // buffered_istream::read_more()
| unsigned int claw::buffered_istream< Stream >::remaining | ( | ) | const |
Tell how many bytes are ready in the buffer.
Definition at line 65 of file buffered_istream.tpp.
Referenced by claw::graphic::bitmap::reader::rle_bitmap_output_buffer< Coded4bits >::copy(), and claw::graphic::bitmap::reader::rle_bitmap_decoder< OutputBuffer >::read_mode().
char* claw::buffered_istream< Stream >::m_begin [private] |
Pointer to the begining of the buffer.
Definition at line 70 of file buffered_istream.hpp.
Referenced by claw::buffered_istream< Stream >::buffered_istream().
unsigned int claw::buffered_istream< Stream >::m_buffer_size [private] |
The size of the allocated buffer.
Definition at line 80 of file buffered_istream.hpp.
Referenced by claw::buffered_istream< Stream >::buffered_istream().
char* claw::buffered_istream< Stream >::m_current [private] |
Pointer to the current not already read valid byte.
Definition at line 77 of file buffered_istream.hpp.
Referenced by claw::buffered_istream< Stream >::buffered_istream().
char* claw::buffered_istream< Stream >::m_end [private] |
Pointer to the first invalid byte after the end of the buffer.
Definition at line 74 of file buffered_istream.hpp.
Referenced by claw::buffered_istream< Stream >::buffered_istream().
stream_type& claw::buffered_istream< Stream >::m_stream [private] |
The stream we're reading.
Definition at line 67 of file buffered_istream.hpp.
1.7.3