24 #ifndef __TPIE_FILE_BASE_H__
25 #define __TPIE_FILE_BASE_H__
27 #include <tpie/tpie_export.h>
35 #include <tpie/file_accessor/win32.h>
37 #include <boost/intrusive/list.hpp>
56 #pragma warning( push )
57 #pragma warning( disable : 4200 )
59 struct block_t :
public boost::intrusive::list_base_hook<> {
60 memory_size_type size;
61 memory_size_type usage;
62 stream_size_type number;
67 #pragma warning( pop )
70 inline void update_size(stream_size_type size) {
71 m_size = std::max(m_size, size);
73 m_tempFile->update_recorded_size(m_fileAccessor->byte_size());
77 inline stream_size_type size()
const throw() {
96 block_t & get_block() {
return *m_block;}
97 const block_t & get_block()
const {
return *m_block;}
98 inline file_base & get_file() {assert(m_file != 0);
return *m_file;}
99 inline const file_base & get_file()
const {assert(m_file != 0);
return *m_file;}
101 void update_block_core();
103 inline void update_vars() {}
113 inline bool attached()
const {
return 0 != m_file; }
130 inline memory_size_type
block_items()
const {
return get_file().m_blockItems;}
141 m_block->dirty =
true;
142 m_block->size = std::max(m_block->size, m_index);
143 get_file().update_size(
static_cast<stream_size_type
>(m_index)+m_blockStartIndex);
163 inline ~stream() {free();}
171 if (m_block != &get_file().m_emptyBlock) get_file().free_block(m_block);
173 m_block = &get_file().m_emptyBlock;
183 if (!m_used.empty()) {
184 throw io_exception(
"Tried to truncate a file with one or more open streams");
187 m_fileAccessor->truncate(s);
189 m_tempFile->update_recorded_size(m_fileAccessor->byte_size());
200 double blockFactor=1.0,
205 block_t * get_block(stream_size_type block);
206 void free_block(block_t * block);
209 static block_t m_emptyBlock;
211 boost::intrusive::list<block_t> m_used;
212 boost::intrusive::list<block_t> m_free;
217 #endif //__TPIE_FILE_BASE_H__