19 #ifndef _TPIE_FILE_ACCESSOR_FILE_ACCESSOR_CRTP_H
20 #define _TPIE_FILE_ACCESSOR_FILE_ACCESSOR_CRTP_H
32 namespace file_accessor {
34 template <
typename file_accessor_t>
43 file_accessor_t m_fileAccessor;
46 stream_size_type m_size;
49 memory_size_type m_userDataSize;
52 memory_size_type m_maxUserDataSize;
55 memory_size_type m_itemSize;
58 memory_size_type m_blockSize;
61 memory_size_type m_blockItems;
70 inline void read_header();
75 inline void write_header(
bool clean);
80 inline memory_size_type boundary()
const {
return 4096; }
86 inline memory_size_type align_to_boundary(memory_size_type z)
const {
return (z+boundary()-1)/boundary()*boundary(); }
92 inline memory_size_type header_size()
const {
return align_to_boundary(
sizeof(
stream_header_t)+m_maxUserDataSize); }
105 inline void open(
const std::string &
path,
108 memory_size_type itemSize,
109 memory_size_type blockSize,
110 memory_size_type maxUserDataSize,
124 inline memory_size_type
read_block(
void * data, stream_size_type blockNumber, memory_size_type itemCount);
135 inline void write_block(
const void * data, stream_size_type blockNumber, memory_size_type itemCount);
145 inline memory_size_type
read_user_data(
void * data, memory_size_type count);
153 inline void write_user_data(
const void * data, memory_size_type count);
163 inline stream_size_type
size()
const {
return m_size;}
168 inline const std::string &
path()
const {
return m_path;}
186 return ((m_size + m_blockItems - 1)/m_blockItems) * m_blockSize + header_size();
189 inline void truncate(stream_size_type items);
195 #include <tpie/file_accessor/stream_accessor.inl>
196 #endif //_TPIE_FILE_ACCESSOR_FILE_ACCESSOR_CRTP_H
Different hints for OS file caching.
stream_size_type byte_size() const
Size (in bytes) of entire stream as laid out on disk after padding the final block to alignment bound...
Declare default file accessor.
const std::string & path() const
Path of the file currently open.
stream_size_type size() const
Number of items in stream.
static memory_size_type memory_usage()
Return memory usage of this file accessor.
memory_size_type user_data_size() const
Size (in bytes) of the user data.
void write_user_data(const void *data, memory_size_type count)
Write user data to the stream.
memory_size_type read_block(void *data, stream_size_type blockNumber, memory_size_type itemCount)
Read the given number of items from the given block into the given buffer.
void write_block(const void *data, stream_size_type blockNumber, memory_size_type itemCount)
Write the given number of items from the given buffer into the given block.
memory_size_type read_user_data(void *data, memory_size_type count)
Read user data into the given buffer.
memory_size_type max_user_data_size() const
Maximum size (in bytes) of the user data.
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)
Open file for reading and/or writing.