Base class of classes that access files. More...
#include <tpie/file_base_crtp.h>
Inherited by tpie::file_stream_base.
Public Member Functions | |
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_items () const |
Get the number of items per block. More... | |
memory_size_type | block_size () const |
Get the size of a block in bytes. 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... | |
void | close () throw (stream_exception) |
Close the 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... | |
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 | |
void | open_inner (const std::string &path, access_type accessType, memory_size_type userDataSize, cache_hint cacheHint) throw (stream_exception) |
file_base_crtp (memory_size_type itemSize, double blockFactor, file_accessor::file_accessor *fileAccessor) | |
template<typename BT > | |
void | read_block (BT &b, stream_size_type block) |
void | get_block_check (stream_size_type block) |
Protected Attributes | |
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 |
Base class of classes that access files.
Inheriting classes may wish to override open_inner() and close(), e.g. to initialize and deinitialize block buffers. open_inner() in the inheriting class will not be called twice in a row without an intervening call to close(). The default implementation of open_inner() passes the open on to the file accessor and sets some attributes.
Definition at line 49 of file file_base_crtp.h.
|
inline |
Get the number of items per block.
Definition at line 105 of file file_base_crtp.h.
|
inlinestatic |
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().
|
inlinestatic |
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.
|
inline |
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().
|
inlinestatic |
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.
|
inline |
Close the file.
Note all streams into the file must be freed before you call close.
Definition at line 246 of file file_base_crtp.h.
Referenced by tpie::file_base_crtp< file_stream_base >::open().
|
inline |
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.
|
inline |
Check if file is open.
Definition at line 256 of file file_base_crtp.h.
|
inline |
Check if we can read from the file.
Definition at line 56 of file file_base_crtp.h.
|
inline |
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().
|
inline |
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().
|
inline |
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.
|
inline |
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.
|
inline |
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.
|
inline |
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().
|
inline |
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.
|
inline |
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.
|
inline |
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().
|
inline |
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.
|
inline |
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.