|
| enum | offset_type { beginning,
end,
current
} |
| | Type describing how we should interpret the offset supplied to seek. More...
|
| |
|
| void | seek (stream_offset_type offset, offset_type whence=beginning) |
| | 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...
|
| |
|
|
void | initialize () |
| |
| void | update_block () |
| | Fetch block from disk as indicated by m_nextBlock, writing old block to disk if needed. More...
|
| |
|
| template<typename IT , typename Stream > |
| static void | read_array (Stream &stream, const IT &start, const IT &end) |
| | Reads several items from the stream. More...
|
| |
| template<typename IT , typename Stream > |
| static void | write_array (Stream &stream, const IT &start, const IT &end) |
| | Write several items to the stream. 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...
|
| |
template<typename child_t>
class tpie::stream_crtp< child_t >
Definition at line 36 of file stream_crtp.h.
◆ offset_type
template<typename child_t >
Type describing how we should interpret the offset supplied to seek.
Definition at line 39 of file stream_crtp.h.
◆ can_read()
template<typename child_t >
Check if we can read an item with read().
This is logically equivalent to:
but it might be faster.
- Returns
- Whether or not we can read more items from the stream.
Definition at line 109 of file stream_crtp.h.
110 assert(
self().get_file().is_open());
111 if (
m_index <
self().get_block().
size )
return true;
◆ can_read_back()
template<typename child_t >
Check if we can read an item with read_back().
- Returns
- Whether or not we can read an item with read_back().
Definition at line 120 of file stream_crtp.h.
121 assert(
self().get_file().is_open());
122 if (
m_nextBlock == std::numeric_limits<stream_size_type>::max())
◆ offset()
template<typename child_t >
Calculate the current offset in the stream.
- Returns
- The current offset in the stream
Definition at line 91 of file stream_crtp.h.
92 assert(
self().get_file().is_open());
93 if (
m_nextBlock == std::numeric_limits<stream_size_type>::max())
◆ read_array()
template<typename child_t >
template<typename IT , typename Stream >
| static void tpie::stream_crtp< child_t >::read_array |
( |
Stream & |
stream, |
|
|
const IT & |
start, |
|
|
const IT & |
end |
|
) |
| |
|
inlinestaticprotected |
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.
- Template Parameters
-
| IT | The type of Random Access Iterators used to supply the items. |
- Parameters
-
| start | Iterator to the first spot to write to. |
| end | Iterator past the last spot to write to. |
- Exceptions
-
Definition at line 166 of file stream_crtp.h.
167 typedef typename Stream::item_type T;
170 if (stream.m_index >= stream.block_items()) {
172 stream_size_type offs = stream.offset();
173 if (offs >= stream.size()
174 || offs + (end-i) > stream.size()) {
176 throw end_of_stream_exception();
180 stream.update_block();
183 T * src =
reinterpret_cast<T*
>(stream.get_block().data) + stream.m_index;
186 memory_size_type count = std::min(stream.block_items()-stream.m_index,
static_cast<memory_size_type
>(end-i));
194 stream.m_index += count;
◆ seek()
template<typename child_t >
Moves the logical offset in the stream.
- Parameters
-
| offset | Where to move the logical offset to. |
| whence | Move the offset relative to what. |
Definition at line 51 of file stream_crtp.h.
52 assert(
self().get_file().is_open());
55 else if (whence == current) {
58 stream_size_type new_index =
static_cast<stream_offset_type
>(
offset+
m_index);
60 if (new_index <
self().get_file().block_items()) {
62 m_index =
static_cast<memory_size_type
>(new_index);
70 throw io_exception(
"Tried to seek out of file");
72 stream_size_type b =
static_cast<stream_size_type
>(
offset) /
self().get_file().block_items();
73 m_index =
static_cast<memory_size_type
>(
offset - b*
self().get_file().block_items());
74 if (b ==
self().get_block().number) {
75 m_nextBlock = std::numeric_limits<stream_size_type>::max();
76 m_nextIndex = std::numeric_limits<memory_size_type>::max();
82 m_index = std::numeric_limits<memory_size_type>::max();
◆ size()
template<typename child_t >
Get the size of the file measured in items.
- Returns
- The number of items in the file.
Definition at line 133 of file stream_crtp.h.
137 const_cast<child_t&
>(
self()).update_vars();
138 return self().get_file().file_size();
◆ update_block()
template<typename child_t >
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.
◆ write_array()
template<typename child_t >
template<typename IT , typename Stream >
| static void tpie::stream_crtp< child_t >::write_array |
( |
Stream & |
stream, |
|
|
const IT & |
start, |
|
|
const IT & |
end |
|
) |
| |
|
inlinestaticprotected |
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.
- Template Parameters
-
| IT | The type of Random Access Iterators used to supply the items. |
- Parameters
-
| start | Iterator to the first item to write. |
| end | Iterator past the last item to write. |
Definition at line 212 of file stream_crtp.h.
213 typedef typename Stream::item_type T;
216 if (stream.m_index >= stream.block_items()) stream.update_block();
218 size_t streamRemaining = end - i;
219 size_t blockRemaining = stream.block_items()-stream.m_index;
221 IT till = (blockRemaining < streamRemaining) ? (i + blockRemaining) : end;
223 T * dest =
reinterpret_cast<T*
>(stream.get_block().data) + stream.m_index;
225 std::copy(i, till, dest);
227 stream.m_index += till - i;
228 stream.write_update();
◆ m_blockStartIndex
template<typename child_t >
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 256 of file stream_crtp.h.
◆ m_index
template<typename child_t >
Item index into the current block, or maxint if we don't have a block.
Definition at line 245 of file stream_crtp.h.
◆ m_nextBlock
template<typename child_t >
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 249 of file stream_crtp.h.
◆ m_nextIndex
template<typename child_t >
After a cross-block seek: Item index into next block.
Otherwise, maxint as with m_nextBlock.
Definition at line 252 of file stream_crtp.h.
The documentation for this class was generated from the following file: