http://stxxl.sourceforge.net
<dementiev@mpi-sb.mpg.de>
http://www.boost.org/LICENSE_1_0.txt
#ifndef STXXL_BUF_OSTREAM_HEADER
#define STXXL_BUF_OSTREAM_HEADER
#include <stxxl/bits/mng/buf_writer.h>
__STXXL_BEGIN_NAMESPACE
template <typename BlkTp_, typename BIDIteratorTp_>
class buf_ostream
{
public:
typedef BlkTp_ block_type;
typedef BIDIteratorTp_ bid_iterator_type;
protected:
buffered_writer<block_type> writer;
bid_iterator_type current_bid;
int_type current_elem;
block_type * current_blk;
public:
typedef typename block_type::const_reference const_reference;
typedef typename block_type::reference reference;
typedef buf_ostream<block_type, bid_iterator_type> _Self;
buf_ostream(bid_iterator_type first_bid, int_type nbuffers) :
writer(nbuffers, nbuffers / 2), current_bid(first_bid),
current_elem(0)
{
current_blk = writer.get_free_block();
}
_Self & operator << (const_reference record)
{
current_blk->elem[current_elem++] = record;
if (UNLIKELY(current_elem >= block_type::size))
{
current_elem = 0;
current_blk = writer.write(current_blk, *(current_bid++));
}
return (*this);
}
reference current()
{
return current_blk->elem[current_elem];
}
reference operator * ()
{
return current_blk->elem[current_elem];
}
_Self& operator ++ ()
{
++current_elem;
if (UNLIKELY(current_elem >= block_type::size))
{
current_elem = 0;
current_blk = writer.write(current_blk, *(current_bid++));
}
return (*this);
}
_Self& fill(const_reference record)
{
while (current_elem != 0)
{
operator<< (record);
}
return *this;
}
virtual ~buf_ostream()
{
assert(current_elem == 0);
}
};
__STXXL_END_NAMESPACE
#endif