24 #ifndef __TPIE_FILE_BASE_H__
25 #define __TPIE_FILE_BASE_H__
33 #include <tpie/file_accessor/win32.h>
35 #include <boost/intrusive/list.hpp>
53 #pragma warning( push )
54 #pragma warning( disable : 4200 )
56 struct block_t :
public boost::intrusive::list_base_hook<> {
57 memory_size_type size;
58 memory_size_type usage;
59 stream_size_type number;
64 #pragma warning( pop )
67 inline void update_size(stream_size_type size) {
68 m_size = std::max(m_size, size);
70 m_tempFile->update_recorded_size(m_fileAccessor->
byte_size());
74 inline stream_size_type size()
const throw() {
95 inline file_base & __file() {assert(m_file != 0);
return *m_file;}
96 inline const file_base & __file()
const {assert(m_file != 0);
return *m_file;}
98 void update_block_core();
100 inline void update_vars() {}
110 inline bool attached()
const {
return 0 != m_file; }
127 inline memory_size_type
block_items()
const {
return __file().m_blockItems;}
151 stream() : m_file(0) {}
160 inline ~stream() {free();}
168 if (
m_block != &__file().m_emptyBlock) __file().free_block(
m_block);
170 m_block = &__file().m_emptyBlock;
180 if (!m_used.empty()) {
181 throw io_exception(
"Tried to truncate a file with one or more open streams");
184 m_fileAccessor->truncate(s);
186 m_tempFile->update_recorded_size(m_fileAccessor->
byte_size());
197 double blockFactor=1.0,
202 block_t * get_block(stream_size_type block);
203 void free_block(block_t * block);
206 static block_t m_emptyBlock;
208 boost::intrusive::list<block_t> m_used;
209 boost::intrusive::list<block_t> m_free;
214 #endif //__TPIE_FILE_BASE_H__
Different hints for OS file caching.
Memory management subsystem.
memory_size_type block_items() const
Fetch number of items per block.
Central file abstraction.
stream_size_type offset() const
Calculate the current offset in the stream.
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...
memory_size_type m_index
Item index into the current block, or maxint if we don't have a block.
void attach_inner(file_base &f)
Attach to the given tpie::file. If necessary, detach first.
void detach_inner()
Detach from a tpie::file.
Declare default file accessor.
Base class of classes that access files.
stream_size_type file_size() const
Get the size of the file measured in items.
void initialize()
Set up block buffers and offsets.
Stream in file. We support multiple streams per file.
This is the type of our block buffers.
void truncate(stream_size_type s)
Truncate file to given size.
void write_update()
Call whenever the current block buffer is modified.
CRTP base of file::stream and file_stream.
bool attached() const
True if we are attached to a tpie::file.
Describes how to acces a file.
block_t * m_block
Current block.
POSIX-style file accessor.
stream_size_type m_blockStartIndex
The file-level item index of the first item in the current block.
~file_base()
file_base destructor.