claw::buffered_ostream< Stream > Class Template Reference

This class is made to help writing in ostreams with a buffer. More...

#include <buffered_ostream.hpp>

List of all members.

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_typem_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.

Detailed Description

template<typename Stream>
class claw::buffered_ostream< Stream >

This class is made to help writing in ostreams with a buffer.

Author:
Julien Jorge

Definition at line 40 of file buffered_ostream.hpp.


Member Typedef Documentation

template<typename Stream >
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.


Constructor & Destructor Documentation

template<typename Stream >
claw::buffered_ostream< Stream >::buffered_ostream ( stream_type f,
unsigned int  buffer_size = 1024 
) [inline]

Constructor.

Parameters:
f The file associated to the stream.
buffer_size The size of the buffer.

Definition at line 40 of file buffered_ostream.tpp.

00041   : m_stream(f), m_begin(new char[buffer_size]), m_end(m_begin+buffer_size),
00042     m_current(m_begin)
00043 {
00044 
00045 } // buffered_ostream::buffered_ostream()

template<typename Stream >
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.

00053 {
00054   flush();
00055   delete[] m_begin;
00056 } // buffered_ostream::~buffered_ostream()


Member Function Documentation

template<typename Stream >
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().

00100 {
00101   if (m_current != m_begin)
00102     {
00103       m_stream.write( m_begin, m_current - m_begin );
00104       m_current = m_begin;
00105     }
00106 } // buffered_ostream::flush()

template<typename Stream >
void claw::buffered_ostream< Stream >::write ( const char *  p,
unsigned int  n 
) [inline]

Write a range of data in the buffer.

Parameters:
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()

template<typename Stream >
template<typename T >
void claw::buffered_ostream< Stream >::write ( v  )  [inline]

Write somethnig in the buffer.

Parameters:
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()


Member Data Documentation

template<typename Stream >
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().

template<typename Stream >
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().

template<typename Stream >
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().

template<typename Stream >
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().


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

Generated on 9 Nov 2009 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.6.1