24 #ifndef __TPIE_FILE_STREAM_BASE_H__
25 #define __TPIE_FILE_STREAM_BASE_H__
27 #include <tpie/tpie_export.h>
41 memory_size_type size;
42 stream_size_type number;
53 if (m_open) flush_block();
68 stream_size_type o=offset();
70 m_block.number = std::numeric_limits<stream_size_type>::max();
71 m_nextBlock = std::numeric_limits<stream_size_type>::max();
72 m_nextIndex = std::numeric_limits<memory_size_type>::max();
73 m_index = std::numeric_limits<memory_size_type>::max();
75 m_fileAccessor->truncate(size);
77 m_tempFile->update_recorded_size(m_fileAccessor->byte_size());
78 seek(std::min(o, size));
90 void swap(file_stream_base & other) {
92 swap(m_index, other.m_index);
93 swap(m_nextBlock, other.m_nextBlock);
94 swap(m_nextIndex, other.m_nextIndex);
95 swap(m_blockStartIndex, other.m_blockStartIndex);
96 swap(m_blockItems, other.m_blockItems);
97 swap(m_blockSize, other.m_blockSize);
98 swap(m_size, other.m_size);
99 swap(m_canRead, other.m_canRead);
100 swap(m_canWrite, other.m_canWrite);
101 swap(m_itemSize, other.m_itemSize);
102 swap(m_open, other.m_open);
103 swap(m_fileAccessor, other.m_fileAccessor);
104 swap(m_block.size, other.m_block.size);
105 swap(m_block.number, other.m_block.number);
106 swap(m_block.dirty, other.m_block.dirty);
107 swap(m_block.data, other.m_block.data);
108 swap(m_ownedTempFile, other.m_ownedTempFile);
109 swap(m_tempFile, other.m_tempFile);
112 inline void open_inner(
const std::string & path,
114 memory_size_type userDataSize,
116 p_t::open_inner(path, accessType, userDataSize, cacheHint);
118 m_blockStartIndex = 0;
119 m_nextBlock = std::numeric_limits<stream_size_type>::max();
120 m_nextIndex = std::numeric_limits<memory_size_type>::max();
121 m_index = std::numeric_limits<memory_size_type>::max();
124 m_block.number = std::numeric_limits<stream_size_type>::max();
125 m_block.dirty =
false;
126 m_block.data = tpie_new_array<char>(m_blockItems * m_itemSize);
135 void get_block(stream_size_type block);
144 m_fileAccessor->write_block(m_block.data, m_block.number, m_block.size);
146 m_tempFile->update_recorded_size(m_fileAccessor->byte_size());
148 m_block.dirty =
false;
151 inline void update_vars() {
152 if (m_block.dirty && m_index != std::numeric_limits<memory_size_type>::max()) {
153 assert(m_index <= m_blockItems);
154 m_block.size = std::max(m_block.size, m_index);
155 m_size = std::max(m_size,
static_cast<stream_size_type
>(m_index)+m_blockStartIndex);
159 inline void initialize() {
164 inline void write_update() {
165 m_block.dirty =
true;
172 friend class stream_crtp<file_stream_base>;
173 file_stream_base & get_file() {
return *
this;}
174 const file_stream_base & get_file()
const {
return *
this;}
175 block_t & get_block() {
return m_block;}
176 const block_t & get_block()
const {
return m_block;}
177 void update_block_core();
182 #endif // __TPIE_FILE_STREAM_BASE_H__