Go to the documentation of this file.
24 #ifndef __TPIE_FILE_BASE_CRTP_H__
25 #define __TPIE_FILE_BASE_CRTP_H__
49 template <
typename child_t>
79 static inline memory_size_type
block_size(
double blockFactor)
throw () {
80 return static_cast<memory_size_type
>(
get_block_size() * blockFactor);
93 return (
double)blockSize / (double)
block_size(1.0);
125 template <
typename TT>
129 m_fileAccessor->
read_user_data(
reinterpret_cast<void*
>(&data),
sizeof(TT));
152 template <
typename TT>
156 m_fileAccessor->
write_user_data(
reinterpret_cast<const void*
>(&data),
sizeof(TT));
195 inline const std::string &
path()
const throw() {
197 return m_fileAccessor->
path();
210 memory_size_type userDataSize=0,
213 self().open_inner(
path, accessType, userDataSize, cacheHint);
220 inline void open(memory_size_type userDataSize=0,
223 m_ownedTempFile.reset(tpie_new<temp_file>());
224 m_tempFile=m_ownedTempFile.get();
235 memory_size_type userDataSize=0,
239 self().open_inner(m_tempFile->
path(), accessType, userDataSize, cacheHint);
248 if (m_open) m_fileAccessor->close();
251 m_ownedTempFile.reset();
274 inline void open_inner(
const std::string &
path,
276 memory_size_type userDataSize,
280 const bool preferCompression =
false;
281 m_fileAccessor->
open(
path, m_canRead, m_canWrite, m_itemSize,
282 m_blockSize, userDataSize, cacheHint,
284 if (m_fileAccessor->get_compressed()) {
285 m_fileAccessor->close();
286 throw stream_exception(
"Tried to open compressed stream as non-compressed");
288 m_size = m_fileAccessor->
size();
293 file_base_crtp(memory_size_type itemSize,
double blockFactor,
294 file_accessor::file_accessor * fileAccessor);
297 template <
typename BT>
298 void read_block(BT & b, stream_size_type block);
299 void get_block_check(stream_size_type block);
301 memory_size_type m_blockItems;
302 memory_size_type m_blockSize;
306 memory_size_type m_itemSize;
307 file_accessor::file_accessor * m_fileAccessor;
309 temp_file * m_tempFile;
310 stream_size_type m_size;
313 child_t &
self() {
return *
static_cast<child_t *
>(
this);}
314 const child_t &
self()
const {
return *
static_cast<const child_t *
>(
this);}
319 #endif // __TPIE_FILE_BASE_CRTP_H__
@ access_write
Open a file for writing only, content is truncated.
Central file abstraction.
memory_size_type max_user_data_size() const
Maximum size (in bytes) of the user data.
memory_size_type max_user_data_size() const
Get maximum user data size.
const std::string & path()
Get the path of the associated file.
bool is_writable() const
Check if we can write to the file.
bool is_readable() const
Check if we can read from the file.
memory_size_type block_items() const
Get the number of items per block.
std::unique_ptr< T, tpie_deleter > unique_ptr
like std::unique_ptr, but delete the object with tpie_delete.
access_type
Type describing how we wish to access a file.
void write_user_data(const void *data, memory_size_type count)
Write variable length user data associated with the file.
static memory_size_type block_size(double blockFactor)
Calculate the block size in bytes used by a stream.
stream_size_type size() const
Number of items in stream.
stream_size_type file_size() const
Get the size of the file measured in items.
const std::string & path() const
Path of the file currently open.
memory_size_type block_size() const
Get the size of a block in bytes.
void write_user_data(const void *data, memory_size_type count)
Write user data to the stream.
void open(const std::string &path, bool read, bool write, memory_size_type itemSize, memory_size_type blockSize, memory_size_type maxUserDataSize, cache_hint cacheHint, int compressionFlags)
Open file for reading and/or writing.
static double calculate_block_factor(memory_size_type blockSize)
Find the block factor that would result in the given block size measured in bytes.
bool is_open() const
Check if file is open.
Base class of classes that access files.
void close()
Close the file.
void read_user_data(TT &data)
Read the user data associated with the file.
const std::string & path() const
The path of the file opened or the empty string.
memory_size_type user_data_size() const
Size (in bytes) of the user data.
void open(const std::string &path, access_type accessType=access_read_write, memory_size_type userDataSize=0, cache_hint cacheHint=access_sequential)
Open a file.
void open(temp_file &file, access_type accessType=access_read_write, memory_size_type userDataSize=0, cache_hint cacheHint=access_sequential)
Open a temporary file.
@ access_sequential
Sequential access is intended.
memory_size_type read_user_data(void *data, memory_size_type count)
Read variable length user data associated with the file.
memory_size_type read_user_data(void *data, memory_size_type count)
Read user data into the given buffer.
TPIE_EXPORT memory_size_type get_block_size()
Get the TPIE block size.
void write_user_data(const TT &data)
Write user data to the stream.
static memory_size_type block_memory_usage(double blockFactor)
Amount of memory used by a single block given the block factor.
memory_size_type user_data_size() const
Get current user data size.
Class representing a reference to a temporary file.
@ access_read_write
Open a file for reading or writing.
void open(memory_size_type userDataSize=0, cache_hint cacheHint=access_sequential)
Open an anonymous temporary file.
@ access_read
Open a file for reading.