Stream in file. We support multiple streams per file. More...
#include <tpie/file_base.h>
Inherits tpie::stream_crtp< stream >.
Inherited by tpie::file< T >::stream.
Public Types | |
enum | offset_type |
Type describing how we should interpret the offset supplied to seek. More... | |
Public Member Functions | |
bool | attached () const |
True if we are attached to a tpie::file. More... | |
memory_size_type | block_items () const |
Fetch number of items per block. More... | |
stream (file_base &file, stream_size_type offset=0) | |
Create a stream associated with the given file. More... | |
void | seek (stream_offset_type offset, offset_type whence=beginning) throw (stream_exception) |
Moves the logical offset in the stream. More... | |
stream_size_type | offset () const throw () |
Calculate the current offset in the stream. More... | |
bool | can_read () const throw () |
Check if we can read an item with read(). More... | |
bool | can_read_back () const throw () |
Check if we can read an item with read_back(). More... | |
stream_size_type | size () const throw () |
Get the size of the file measured in items. More... | |
Protected Member Functions | |
block_t & | get_block () |
const block_t & | get_block () const |
file_base & | get_file () |
const file_base & | get_file () const |
void | update_block_core () |
void | update_vars () |
void | attach_inner (file_base &f) |
Attach to the given tpie::file. If necessary, detach first. More... | |
void | detach_inner () |
Detach from a tpie::file. More... | |
void | write_update () |
Call whenever the current block buffer is modified. More... | |
void | initialize () |
Set up block buffers and offsets. More... | |
void | update_block () |
Fetch block from disk as indicated by m_nextBlock, writing old block to disk if needed. More... | |
Static Protected Member Functions | |
static void | read_array (Stream &stream, const IT &start, const IT &end) throw (stream_exception) |
Reads several items from the stream. More... | |
static void | write_array (Stream &stream, const IT &start, const IT &end) throw (stream_exception) |
Write several items to the stream. More... | |
Protected Attributes | |
block_t * | m_block |
Current block. More... | |
memory_size_type | m_index |
Item index into the current block, or maxint if we don't have a block. More... | |
stream_size_type | m_nextBlock |
After a cross-block seek: Block index of next block, or maxint if the current block is good enough OR if we haven't read/written anything yet. More... | |
memory_size_type | m_nextIndex |
After a cross-block seek: Item index into next block. More... | |
stream_size_type | m_blockStartIndex |
The file-level item index of the first item in the current block. More... | |
Friends | |
class | stream_crtp< stream > |
Stream in file. We support multiple streams per file.
Definition at line 84 of file file_base.h.
|
inherited |
Type describing how we should interpret the offset supplied to seek.
Definition at line 38 of file stream_crtp.h.
tpie::file_base::stream::stream | ( | file_base & | file, |
stream_size_type | offset = 0 |
||
) |
Create a stream associated with the given file.
file | The file to associate with this stream. |
offset | The file-level item offset to seek to. |
|
protected |
Attach to the given tpie::file. If necessary, detach first.
Referenced by tpie::file< T >::stream::attach().
|
inline |
True if we are attached to a tpie::file.
Definition at line 111 of file file_base.h.
|
inline |
Fetch number of items per block.
Definition at line 128 of file file_base.h.
Referenced by tpie::file< T >::stream::write().
|
inlineinherited |
Check if we can read an item with read().
This is logically equivalent to:
but it might be faster.
Definition at line 108 of file stream_crtp.h.
References tpie::stream_crtp< child_t >::m_index, tpie::stream_crtp< child_t >::offset(), and tpie::stream_crtp< child_t >::size().
|
inlineinherited |
Check if we can read an item with read_back().
Definition at line 119 of file stream_crtp.h.
References tpie::stream_crtp< child_t >::m_blockStartIndex, tpie::stream_crtp< child_t >::m_index, tpie::stream_crtp< child_t >::m_nextBlock, and tpie::stream_crtp< child_t >::m_nextIndex.
|
protected |
Detach from a tpie::file.
Referenced by tpie::file< T >::stream::detach().
|
inlineprotected |
|
inlineinherited |
Calculate the current offset in the stream.
Definition at line 90 of file stream_crtp.h.
References tpie::stream_crtp< child_t >::m_blockStartIndex, tpie::stream_crtp< child_t >::m_index, tpie::stream_crtp< child_t >::m_nextBlock, and tpie::stream_crtp< child_t >::m_nextIndex.
Referenced by tpie::file< T >::stream::read_mutable().
|
inlinestaticprotectedinherited |
Reads several items from the stream.
Implementation note: If your iterator type is efficiently copyable with std::copy, then this will also read efficiently from the internal TPIE buffer.
IT | The type of Random Access Iterators used to supply the items. |
start | Iterator to the first spot to write to. |
end | Iterator past the last spot to write to. |
end_of_stream_exception | If there are not enough elements in the stream to fill all the spots between start and end. |
Definition at line 165 of file stream_crtp.h.
Referenced by tpie::file< T >::stream::read().
|
inlineinherited |
Moves the logical offset in the stream.
offset | Where to move the logical offset to. |
whence | Move the offset relative to what. |
Definition at line 50 of file stream_crtp.h.
References tpie::stream_crtp< child_t >::m_index, tpie::stream_crtp< child_t >::m_nextBlock, tpie::stream_crtp< child_t >::m_nextIndex, tpie::stream_crtp< child_t >::offset(), and tpie::stream_crtp< child_t >::size().
Referenced by tpie::file< T >::stream::read_back().
|
inlineinherited |
Get the size of the file measured in items.
Definition at line 132 of file stream_crtp.h.
Referenced by tpie::file< T >::stream::read_mutable().
|
protectedinherited |
Fetch block from disk as indicated by m_nextBlock, writing old block to disk if needed.
Update m_block, m_index, m_nextBlock and m_nextIndex. If m_nextBlock is maxint, use next block is the one numbered m_block->number+1. m_index is updated with the value of m_nextIndex.
Referenced by tpie::file< T >::stream::read_mutable(), and tpie::file< T >::stream::write().
|
inlinestaticprotectedinherited |
Write several items to the stream.
Implementation note: If your iterator type is efficiently copyable with std::copy, then this will also write efficiently into the internal TPIE buffer.
IT | The type of Random Access Iterators used to supply the items. |
start | Iterator to the first item to write. |
end | Iterator past the last item to write. |
Definition at line 211 of file stream_crtp.h.
Referenced by tpie::file< T >::stream::write().
|
inlineprotected |
Call whenever the current block buffer is modified.
Since we support multiple streams per block, we must always keep m_block->size updated when m_block is the trailing block (or the only block) in the file. For the same reasons we keep m_file->m_size updated.
Definition at line 138 of file file_base.h.
References m_block, tpie::stream_crtp< stream >::m_blockStartIndex, and tpie::stream_crtp< stream >::m_index.
Referenced by tpie::file< T >::stream::write().
|
protected |
Current block.
May be equal to &m_file->m_emptyBlock to indicate no current block.
Definition at line 105 of file file_base.h.
Referenced by initialize(), tpie::file< T >::stream::read_mutable(), tpie::file< T >::stream::write(), and write_update().
|
protectedinherited |
The file-level item index of the first item in the current block.
When m_block is not the null block, this should be equal to m_block->number * block_items().
Definition at line 255 of file stream_crtp.h.
Referenced by write_update().
|
protectedinherited |
Item index into the current block, or maxint if we don't have a block.
Definition at line 244 of file stream_crtp.h.
Referenced by tpie::file< T >::stream::read_mutable(), tpie::file< T >::stream::write(), and write_update().
|
protectedinherited |
After a cross-block seek: Block index of next block, or maxint if the current block is good enough OR if we haven't read/written anything yet.
Definition at line 248 of file stream_crtp.h.
|
protectedinherited |
After a cross-block seek: Item index into next block.
Otherwise, maxint as with m_nextBlock.
Definition at line 251 of file stream_crtp.h.