19 #ifndef TPIE_FILE_ACCESSOR_STREAM_ACCESSOR_BASE_H
20 #define TPIE_FILE_ACCESSOR_STREAM_ACCESSOR_BASE_H
31 namespace file_accessor {
33 template <
typename file_accessor_t>
43 file_accessor_t m_fileAccessor;
47 stream_size_type m_size;
50 memory_size_type m_userDataSize;
53 memory_size_type m_maxUserDataSize;
56 memory_size_type m_itemSize;
59 memory_size_type m_blockSize;
62 memory_size_type m_blockItems;
65 stream_size_type m_lastBlockReadOffset;
68 int m_compressionFlags;
71 bool m_useCompression;
80 inline void read_header();
85 inline void write_header(
bool clean);
91 inline memory_size_type
boundary()
const {
return 4096; }
105 memory_size_type block_size()
const {
return m_blockSize; }
106 memory_size_type block_items()
const {
return m_blockItems; }
107 memory_size_type item_size()
const {
return m_itemSize; }
109 void set_size(stream_size_type s) { m_size = s; }
112 inline stream_accessor_base()
118 virtual ~stream_accessor_base() {close();}
123 inline void open(
const std::string &
path,
126 memory_size_type itemSize,
127 memory_size_type blockSize,
128 memory_size_type maxUserDataSize,
130 int compressionFlags);
143 virtual memory_size_type
read_block(
void * data, stream_size_type blockNumber, memory_size_type itemCount) = 0;
154 virtual void write_block(
const void * data, stream_size_type blockNumber, memory_size_type itemCount) = 0;
164 inline memory_size_type
read_user_data(
void * data, memory_size_type count);
172 inline void write_user_data(
const void * data, memory_size_type count);
182 inline stream_size_type
size()
const {
return m_size;}
187 inline const std::string &
path()
const {
return m_path;}
205 return ((m_size + m_blockItems - 1)/m_blockItems) * m_blockSize +
header_size();
208 inline void truncate(stream_size_type items);
210 void set_last_block_read_offset(stream_size_type n) { m_lastBlockReadOffset = n; }
211 stream_size_type get_last_block_read_offset() {
return m_lastBlockReadOffset; }
213 bool get_compressed() {
return m_useCompression; }
215 int get_compression_flags() {
return m_compressionFlags; }
221 #include <tpie/file_accessor/stream_accessor_base.inl>
222 #endif // TPIE_FILE_ACCESSOR_STREAM_ACCESSOR_BASE_H
memory_size_type read_user_data(void *data, memory_size_type count)
Read user data into the given buffer.
Different hints for OS file caching.
virtual memory_size_type read_block(void *data, stream_size_type blockNumber, memory_size_type itemCount)=0
Read the given number of items from the given block into the given buffer.
void write_user_data(const void *data, memory_size_type count)
Write user data to the stream.
stream_size_type size() const
Number of items in stream.
memory_size_type header_size() const
The size of header and user data with padding included.
memory_size_type boundary() const
Returns the boundary on which we align blocks.
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...
virtual void write_block(const void *data, stream_size_type blockNumber, memory_size_type itemCount)=0
Write the given number of items from the given buffer into the given block.
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.
memory_size_type user_data_size() const
Size (in bytes) of the user data.
memory_size_type align_to_boundary(memory_size_type z) const
Given a memory offset, rounds up to the nearest alignment boundary.
static memory_size_type memory_usage()
Return memory usage of this file accessor.
memory_size_type max_user_data_size() const
Maximum size (in bytes) of the user data.
const std::string & path() const
Path of the file currently open.