Inherits tpie::file_base_crtp< child_t >, and tpie::stream_crtp< file_stream_base >.
Inherited by tpie::uncompressed_stream< T >.
Classes | |
struct | block_t |
Public Types | |
typedef file_base_crtp < file_stream_base > | p_t |
typedef stream_crtp < file_stream_base > | s_t |
enum | offset_type |
Type describing how we should interpret the offset supplied to seek. More... | |
Public Member Functions | |
void | close () throw (stream_exception) |
Close the file and release resources. More... | |
void | truncate (stream_size_type size) |
Truncate file to given size. More... | |
bool | is_readable () const throw () |
Check if we can read from the file. More... | |
bool | is_writable () const throw () |
Check if we can write to the file. More... | |
memory_size_type | block_size () const |
Get the size of a block in bytes. More... | |
memory_size_type | block_items () const |
Get the number of items per block. More... | |
template<typename TT > | |
void | read_user_data (TT &data) throw (stream_exception) |
Read the user data associated with the file. More... | |
memory_size_type | read_user_data (void *data, memory_size_type count) |
Read variable length user data associated with the file. More... | |
template<typename TT > | |
void | write_user_data (const TT &data) throw (stream_exception) |
Write user data to the stream. More... | |
void | write_user_data (const void *data, memory_size_type count) |
Write variable length user data associated with the file. More... | |
memory_size_type | user_data_size () const |
Get current user data size. More... | |
memory_size_type | max_user_data_size () const |
Get maximum user data size. More... | |
const std::string & | path () const throw () |
The path of the file opened or the empty string. More... | |
void | open (const std::string &path, access_type accessType=access_read_write, memory_size_type userDataSize=0, cache_hint cacheHint=access_sequential) throw (stream_exception) |
Open a file. More... | |
void | open (memory_size_type userDataSize=0, cache_hint cacheHint=access_sequential) throw (stream_exception) |
Open an anonymous temporary file. More... | |
void | open (temp_file &file, access_type accessType=access_read_write, memory_size_type userDataSize=0, cache_hint cacheHint=access_sequential) throw (stream_exception) |
Open a temporary file. More... | |
bool | is_open () const |
Check if file is open. More... | |
stream_size_type | file_size () const throw () |
Get the size of the file measured in items. 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... | |
Static Public Member Functions | |
static memory_size_type | block_size (double blockFactor) throw () |
Calculate the block size in bytes used by a stream. More... | |
static double | calculate_block_factor (memory_size_type blockSize) throw () |
Find the block factor that would result in the given block size measured in bytes. More... | |
static memory_size_type | block_memory_usage (double blockFactor) |
Amount of memory used by a single block given the block factor. More... | |
Protected Member Functions | |
file_stream_base (memory_size_type itemSize, double blockFactor, file_accessor::file_accessor *fileAccessor) | |
void | swap (file_stream_base &other) |
void | open_inner (const std::string &path, access_type accessType, memory_size_type userDataSize, cache_hint cacheHint) throw (stream_exception) |
void | get_block (stream_size_type block) |
Use file_accessor to fetch indicated block number into m_block. More... | |
void | flush_block () |
Write block to disk. More... | |
void | update_vars () |
void | initialize () |
void | write_update () |
template<typename BT > | |
void | read_block (BT &b, stream_size_type block) |
void | get_block_check (stream_size_type block) |
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 |
memory_size_type | m_blockItems |
memory_size_type | m_blockSize |
bool | m_canRead |
bool | m_canWrite |
bool | m_open |
memory_size_type | m_itemSize |
file_accessor::file_accessor * | m_fileAccessor |
tpie::unique_ptr< temp_file > | m_ownedTempFile |
temp_file * | m_tempFile |
stream_size_type | m_size |
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 | file_base_crtp< file_stream_base > |
class | stream_crtp< file_stream_base > |
Definition at line 32 of file file_stream_base.h.
|
inherited |
Type describing how we should interpret the offset supplied to seek.
Definition at line 38 of file stream_crtp.h.
|
inlineinherited |
Get the number of items per block.
Definition at line 105 of file file_base_crtp.h.
|
inlinestaticinherited |
Amount of memory used by a single block given the block factor.
Definition at line 98 of file file_base_crtp.h.
Referenced by tpie::uncompressed_stream< T >::memory_usage().
|
inlinestaticinherited |
Calculate the block size in bytes used by a stream.
We have block_size(calculate_block_factor(b)) ~= b.
blockFactor | Factor of the global block size to use. |
Definition at line 78 of file file_base_crtp.h.
|
inlineinherited |
Get the size of a block in bytes.
Definition at line 112 of file file_base_crtp.h.
Referenced by tpie::file_base_crtp< file_stream_base >::block_memory_usage(), and tpie::file_base_crtp< file_stream_base >::calculate_block_factor().
|
inlinestaticinherited |
Find the block factor that would result in the given block size measured in bytes.
We have calculate_block_factor(block_size(f)) ~= f.
blockSize | The sought block size. |
Definition at line 91 of file file_base_crtp.h.
|
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.
|
inlineinherited |
Check if we can read an item with read_back().
Definition at line 119 of file stream_crtp.h.
|
inline |
Close the file and release resources.
This will close the file and resources used by buffers and such.
Definition at line 51 of file file_stream_base.h.
References tpie::file_base_crtp< file_stream_base >::close(), flush_block(), and tpie::tpie_delete_array().
|
inlineinherited |
Get the size of the file measured in items.
If there are streams of this file that have extended the stream length but have not yet flushed these writes, we might report an incorrect size.
Definition at line 268 of file file_base_crtp.h.
|
inlineprotected |
Write block to disk.
Definition at line 139 of file file_stream_base.h.
References tpie::file_accessor::stream_accessor_base< file_accessor_t >::byte_size(), and tpie::file_accessor::stream_accessor_base< file_accessor_t >::write_block().
Referenced by close(), and truncate().
|
protected |
Use file_accessor to fetch indicated block number into m_block.
|
inlineinherited |
Check if file is open.
Definition at line 256 of file file_base_crtp.h.
|
inlineinherited |
Check if we can read from the file.
Definition at line 56 of file file_base_crtp.h.
|
inlineinherited |
Check if we can write to the file.
Definition at line 65 of file file_base_crtp.h.
Referenced by tpie::uncompressed_stream< T >::write().
|
inlineinherited |
Get maximum user data size.
Definition at line 183 of file file_base_crtp.h.
Referenced by tpie::file_base_crtp< file_stream_base >::write_user_data().
|
inlineinherited |
Calculate the current offset in the stream.
Definition at line 90 of file stream_crtp.h.
Referenced by tpie::uncompressed_stream< T >::peek(), and truncate().
|
inlineinherited |
Open a file.
path | The path of the file to open. |
accessType | The mode of operation. |
userDataSize | The size of the user data we want to store in the file. |
Definition at line 207 of file file_base_crtp.h.
|
inlineinherited |
Open an anonymous temporary file.
The temporary file is deleted when this file is closed.
Definition at line 219 of file file_base_crtp.h.
|
inlineinherited |
Open a temporary file.
The temporary file is not deleted when this file is closed, so several tpie::file objects may use the same temporary file consecutively.
Definition at line 232 of file file_base_crtp.h.
|
inlineinherited |
The path of the file opened or the empty string.
Definition at line 194 of file file_base_crtp.h.
Referenced by tpie::pipelining::serialization_bits::reverser_input_t< T >::begin(), and tpie::pipelining::serialization_bits::buffer_input_t< T >::begin().
|
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::uncompressed_stream< T >::read().
|
inlineinherited |
Read the user data associated with the file.
data | Where to store the user data. |
TT | The type of user data. sizeof(TT) must be less than or equal to the maximum user data size of the stream. TT must be trivially copyable. |
Definition at line 125 of file file_base_crtp.h.
|
inlineinherited |
Read variable length user data associated with the file.
data | The buffer in which to write data. |
count | The size of the buffer. |
Definition at line 138 of file file_base_crtp.h.
|
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.
Referenced by tpie::uncompressed_stream< T >::skip(), tpie::uncompressed_stream< T >::skip_back(), and truncate().
|
inlineinherited |
Get the size of the file measured in items.
Definition at line 132 of file stream_crtp.h.
Referenced by tpie::uncompressed_stream< T >::peek(), and truncate().
|
inline |
Truncate file to given size.
May only be used when no streams are opened to this file.
Note that when using a file_stream the stream will automatically be rewound if it is beyond the new end of the file.
Definition at line 66 of file file_stream_base.h.
References tpie::file_accessor::stream_accessor_base< file_accessor_t >::byte_size(), flush_block(), tpie::stream_crtp< file_stream_base >::m_index, tpie::stream_crtp< file_stream_base >::m_nextBlock, tpie::stream_crtp< file_stream_base >::m_nextIndex, tpie::stream_crtp< file_stream_base >::offset(), tpie::stream_crtp< file_stream_base >::seek(), and tpie::stream_crtp< file_stream_base >::size().
|
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::uncompressed_stream< T >::peek(), and tpie::uncompressed_stream< T >::write().
|
inlineinherited |
Get current user data size.
Definition at line 175 of file file_base_crtp.h.
Referenced by tpie::file_base_crtp< file_stream_base >::read_user_data().
|
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::uncompressed_stream< T >::write().
|
inlineinherited |
Write user data to the stream.
data | The user data to store in the stream. |
TT | The type of user data. sizeof(TT) must be less than or equal to the maximum user data size of the stream. TT must be trivially copyable. |
Definition at line 152 of file file_base_crtp.h.
|
inlineinherited |
Write variable length user data associated with the file.
Throws a stream_exception if the size of the user data exceeds the maximum user data size of the stream.
data | The buffer from which to read data. |
count | The size of the user data. |
Definition at line 167 of file file_base_crtp.h.
|
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.
|
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::uncompressed_stream< T >::peek(), tpie::uncompressed_stream< T >::read(), truncate(), and tpie::uncompressed_stream< T >::write().
|
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.
Referenced by truncate().
|
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.
Referenced by truncate().