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>
54 #pragma warning( push )
55 #pragma warning( disable : 4200 )
57 struct block_t :
public boost::intrusive::list_base_hook<> {
58 memory_size_type size;
59 memory_size_type usage;
60 stream_size_type number;
65 #pragma warning( pop )
68 inline void update_size(stream_size_type size) {
69 m_size = std::max(m_size, size);
71 m_tempFile->update_recorded_size(m_fileAccessor->
byte_size());
75 inline stream_size_type size()
const throw() {
96 inline file_base & get_file() {assert(m_file != 0);
return *m_file;}
97 inline const file_base & get_file()
const {assert(m_file != 0);
return *m_file;}
99 void update_block_core();
101 inline void update_vars() {}
111 inline bool attached()
const {
return 0 != m_file; }
128 inline memory_size_type
block_items()
const {
return get_file().m_blockItems;}
152 stream() : m_file(0) {}
161 inline ~stream() {free();}
169 if (
m_block != &get_file().m_emptyBlock) get_file().free_block(
m_block);
171 m_block = &get_file().m_emptyBlock;
181 if (!m_used.empty()) {
182 throw io_exception(
"Tried to truncate a file with one or more open streams");
185 m_fileAccessor->truncate(s);
187 m_tempFile->update_recorded_size(m_fileAccessor->
byte_size());
198 double blockFactor=1.0,
203 block_t * get_block(stream_size_type block);
204 void free_block(block_t * block);
207 static block_t m_emptyBlock;
209 boost::intrusive::list<block_t> m_used;
210 boost::intrusive::list<block_t> m_free;
215 #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.