This class is made to help writing in ostreams with a buffer. More...
#include <buffered_ostream.hpp>
Public Member Functions | |
buffered_ostream (stream_type &f, unsigned int buffer_size=1024) | |
Constructor. | |
~buffered_ostream () | |
Destructor. | |
template<typename T > | |
void | write (T v) |
Write somethnig in the buffer. | |
void | write (const char *p, unsigned int n) |
Write a range of data in the buffer. | |
void | flush () |
Write the data from the buffer in the stream. | |
Private Types | |
typedef Stream | stream_type |
The type of the stream we will write. | |
Private Attributes | |
stream_type & | m_stream |
The stream we're writing. | |
char *const | m_begin |
Pointer to the begining of the buffer. | |
char *const | 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. |
This class is made to help writing in ostreams with a buffer.
Definition at line 40 of file buffered_ostream.hpp.
typedef Stream claw::buffered_ostream< Stream >::stream_type [private] |
The type of the stream we will write.
Definition at line 44 of file buffered_ostream.hpp.
claw::buffered_ostream< Stream >::buffered_ostream | ( | stream_type & | f, | |
unsigned int | buffer_size = 1024 | |||
) | [inline] |
Constructor.
f | The file associated to the stream. | |
buffer_size | The size of the buffer. |
Definition at line 40 of file buffered_ostream.tpp.
claw::buffered_ostream< Stream >::~buffered_ostream | ( | ) | [inline] |
Destructor.
Definition at line 52 of file buffered_ostream.tpp.
References claw::buffered_ostream< Stream >::flush(), and claw::buffered_ostream< Stream >::m_begin.
void claw::buffered_ostream< Stream >::flush | ( | ) | [inline] |
Write the data from the buffer in the stream.
Definition at line 99 of file buffered_ostream.tpp.
References claw::buffered_ostream< Stream >::m_begin, claw::buffered_ostream< Stream >::m_current, and claw::buffered_ostream< Stream >::m_stream.
Referenced by claw::buffered_ostream< Stream >::write(), and claw::buffered_ostream< Stream >::~buffered_ostream().
void claw::buffered_ostream< Stream >::write | ( | const char * | p, | |
unsigned int | n | |||
) | [inline] |
Write a range of data in the buffer.
p | The begining of the range to write. | |
n | The length of the buffer pointed by p. |
Definition at line 77 of file buffered_ostream.tpp.
References claw::buffered_ostream< Stream >::flush(), claw::buffered_ostream< Stream >::m_current, and claw::buffered_ostream< Stream >::m_end.
00078 { 00079 while (n > 0) 00080 { 00081 unsigned int q = std::min( n, (unsigned int)(m_end - m_current) ); 00082 const char* end = p+q; 00083 00084 for ( ; p!=end ; ++p, ++m_current ) 00085 *m_current = *p; 00086 00087 n -= q; 00088 00089 if (m_current == m_end) 00090 flush(); 00091 } 00092 } // buffered_ostream::write()
void claw::buffered_ostream< Stream >::write | ( | T | v | ) | [inline] |
Write somethnig in the buffer.
v | The value to write. |
Definition at line 65 of file buffered_ostream.tpp.
00066 { 00067 write( reinterpret_cast<const char*>(&v), sizeof(v) ); 00068 } // buffered_ostream::read_more()
char* const claw::buffered_ostream< Stream >::m_begin [private] |
Pointer to the begining of the buffer.
Definition at line 62 of file buffered_ostream.hpp.
Referenced by claw::buffered_ostream< Stream >::flush(), and claw::buffered_ostream< Stream >::~buffered_ostream().
char* claw::buffered_ostream< Stream >::m_current [private] |
Pointer to the current not already read valid byte.
Definition at line 69 of file buffered_ostream.hpp.
Referenced by claw::buffered_ostream< Stream >::flush(), and claw::buffered_ostream< Stream >::write().
char* const claw::buffered_ostream< Stream >::m_end [private] |
Pointer to the first invalid byte after the end of the buffer.
Definition at line 66 of file buffered_ostream.hpp.
Referenced by claw::buffered_ostream< Stream >::write().
stream_type& claw::buffered_ostream< Stream >::m_stream [private] |
The stream we're writing.
Definition at line 59 of file buffered_ostream.hpp.
Referenced by claw::buffered_ostream< Stream >::flush().