20 #ifndef TPIE_FILE_ACCESSOR_BYTE_STREAM_ACCESSOR_H
21 #define TPIE_FILE_ACCESSOR_BYTE_STREAM_ACCESSOR_H
28 namespace file_accessor {
30 template <
typename file_accessor_t>
36 memory_size_type )
override
38 throw exception(
"Block operations not supported");
43 memory_size_type )
override
45 throw exception(
"Block operations not supported");
48 void set_size(stream_size_type amt) {
53 return this->
size() == 0;
56 stream_size_type file_size() {
57 return std::max(this->m_fileAccessor.file_size_i(),
58 static_cast<stream_size_type
>(this->header_size()))
62 void truncate_bytes(stream_size_type
size) {
63 this->m_fileAccessor.truncate_i(this->
header_size() + size);
66 void write(
const stream_size_type byteOffset,
const void * data,
const memory_size_type
size) {
67 stream_size_type position = byteOffset + this->
header_size();
68 this->m_fileAccessor.seek_i(position);
69 this->m_fileAccessor.write_i(data,
size);
72 void append(
const void * data, memory_size_type
size) {
73 stream_size_type position = this->m_fileAccessor.file_size_i();
78 this->m_fileAccessor.seek_i(position);
79 this->m_fileAccessor.write_i(data,
size);
82 memory_size_type read(
const stream_size_type byteOffset,
void * data, memory_size_type
size) {
84 = std::max(
static_cast<stream_size_type
>(this->
header_size()),
85 this->m_fileAccessor.file_size_i())
88 if (byteOffset +
size > sz)
89 size = sz - byteOffset;
91 stream_size_type position = this->
header_size() + byteOffset;
93 this->m_fileAccessor.seek_i(position);
94 this->m_fileAccessor.read_i(data,
size);
98 memory_size_type block_items()
const {
99 return p_t::block_items();
102 memory_size_type block_size()
const {
103 return p_t::block_size();
110 #endif // TPIE_FILE_ACCESSOR_BYTE_STREAM_ACCESSOR_H