TPIE

11a2c2d
tpie::file_stream< T > Class Template Reference

Compressed stream. More...

#include <tpie/compressed/stream.h>

Public Types

typedef T item_type
 

Public Member Functions

 file_stream (double blockFactor=1.0)
 
const T & read ()
 Reads next item from stream if can_read() == true. More...
 
const T & peek ()
 Peeks next item from stream if can_read() == true. More...
 
void skip ()
 
void skip_back ()
 
template<typename IT >
void read (IT const a, IT const b)
 Precondition: is_open(). More...
 
const T & read_back ()
 
void write (const T &item)
 
template<typename IT >
void write (IT const a, IT const b)
 

Static Public Member Functions

static memory_size_type memory_usage (double blockFactor=1.0) noexcept
 

Detailed Description

template<typename T>
class tpie::file_stream< T >

Compressed stream.

We assume that T is trivially copyable and that its copy constructor and assignment operator never throws.

As a rule of thumb, when a tpie::stream_exception is thrown from a method, the stream is left in the state it was in prior to the method call. When a tpie::exception is thrown, the stream may have changed. In particular, the stream may have been closed, and it is up to the caller (if the exception is caught) to ensure that the stream is reopened as necessary.

Several methods claim the nothrow guarantee even though the implementation has throw statements. In this case, there are two reasons an exception may be thrown: A tpie::exception is thrown if some invariant in the stream has been violated, and this is a bug we must fix in the compressed stream. A tpie::stream_exception is thrown if the user has violated a precondition (for instance by passing an invalid parameter).

Definition at line 49 of file predeclare.h.

Member Function Documentation

◆ peek()

template<typename T >
const T& tpie::file_stream< T >::peek ( )
inline

Peeks next item from stream if can_read() == true.

If can_read() == false, throws an end_of_stream_exception.

Blocks to take the compressor lock.

If a stream_exception is thrown, the stream is left in the state it was in before the call to peek().

Definition at line 451 of file stream.h.

451  {
452  if (m_cachedReads == 0) peak_unlikely();
453  return *reinterpret_cast<const T*>(m_nextItem);
454  }

◆ read() [1/2]

template<typename T >
const T& tpie::file_stream< T >::read ( )
inline

Reads next item from stream if can_read() == true.

If can_read() == false, throws an end_of_stream_exception.

Blocks to take the compressor lock.

If a stream_exception is thrown, the stream is left in the state it was in before the call to read().

Definition at line 425 of file stream.h.

425  {
426  if (m_cachedReads == 0) {
427  peak_unlikely();
428  const T & res = *reinterpret_cast<const T*>(m_nextItem);
429  ++m_offset;
430  m_nextItem += sizeof(T);
431  cache_read_writes();
432  return res;
433  }
434  --m_cachedReads;
435  ++m_offset;
436  const T & res = *reinterpret_cast<const T*>(m_nextItem);
437  m_nextItem += sizeof(T);
438  return res;
439  }

Referenced by tpie::pipelining::bits::input_t< dest_t >::go(), tpie::pipelining::bits::buffer_output_t< dest_t >::go(), tpie::file_stream< tpie::stream_position >::read(), tpie::sort_manager< T, I, M >::sort(), and tpie::ami::Internal_Sorter_Obj< T, Compare >::sort().

◆ read() [2/2]

template<typename T >
template<typename IT >
void tpie::file_stream< T >::read ( IT const  a,
IT const  b 
)
inline

Precondition: is_open().

Reads min(b-a, size()-offset()) items into the range [a, b). If less than b-a items are read, throws an end_of_stream_exception.

Definition at line 471 of file stream.h.

471  {
472  for (IT i = a; i != b; ++i) *i = read();
473  }

The documentation for this class was generated from the following files:
tpie::file_stream::read
const T & read()
Reads next item from stream if can_read() == true.
Definition: stream.h:425