Public Member Functions | Private Types | Private Attributes

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 
)

Constructor.

Parameters:
fThe file associated to the stream.
buffer_sizeThe size of the buffer.

Definition at line 40 of file buffered_ostream.tpp.

  : m_stream(f), m_begin(new char[buffer_size]), m_end(m_begin+buffer_size),
    m_current(m_begin)
{

} // buffered_ostream::buffered_ostream()
template<typename Stream >
claw::buffered_ostream< Stream >::~buffered_ostream (  )

Destructor.

Definition at line 52 of file buffered_ostream.tpp.

{
  flush();
  delete[] m_begin;
} // buffered_ostream::~buffered_ostream()

Member Function Documentation

template<typename Stream >
void claw::buffered_ostream< Stream >::flush (  )

Write the data from the buffer in the stream.

Definition at line 99 of file buffered_ostream.tpp.

{
  if (m_current != m_begin)
    {
      m_stream.write( m_begin, m_current - m_begin );
      m_current = m_begin;
    }
} // buffered_ostream::flush()
template<typename Stream >
template<typename T >
void claw::buffered_ostream< Stream >::write ( v )

Write somethnig in the buffer.

Parameters:
vThe value to write.

Definition at line 65 of file buffered_ostream.tpp.

{
  write( reinterpret_cast<const char*>(&v), sizeof(v) );
} // buffered_ostream::read_more()
template<typename Stream >
void claw::buffered_ostream< Stream >::write ( const char *  p,
unsigned int  n 
)

Write a range of data in the buffer.

Parameters:
pThe begining of the range to write.
nThe length of the buffer pointed by p.

Definition at line 77 of file buffered_ostream.tpp.

{
  while (n > 0)
    {
      unsigned int q = std::min( n, (unsigned int)(m_end - m_current) );
      const char* end = p+q;

      for ( ; p!=end ; ++p, ++m_current )
        *m_current = *p;

      n -= q;

      if (m_current == m_end)
        flush();
    }
} // buffered_ostream::write()

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.

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.

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.

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.


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