TPIE

2362a60
tpie::file_accessor::stream_accessor< file_accessor_t > Class Template Reference

Inherits tpie::file_accessor::stream_accessor_base< file_accessor_t >.

Public Member Functions

virtual memory_size_type read_block (void *data, stream_size_type blockNumber, memory_size_type itemCount) override
 Read the given number of items from the given block into the given buffer. More...
 
virtual void write_block (const void *data, stream_size_type blockNumber, memory_size_type itemCount) override
 Write the given number of items from the given buffer into the given block. More...
 
void open (const std::string &path, bool read, bool write, memory_size_type itemSize, memory_size_type blockSize, memory_size_type maxUserDataSize, cache_hint cacheHint, int compressionFlags)
 Open file for reading and/or writing. More...
 
void close ()
 
memory_size_type read_user_data (void *data, memory_size_type count)
 Read user data into the given buffer. More...
 
void write_user_data (const void *data, memory_size_type count)
 Write user data to the stream. More...
 
stream_size_type size () const
 Number of items in stream. More...
 
const std::string & path () const
 Path of the file currently open. More...
 
memory_size_type user_data_size () const
 Size (in bytes) of the user data. More...
 
memory_size_type max_user_data_size () const
 Maximum size (in bytes) of the user data. More...
 
stream_size_type byte_size () const
 Size (in bytes) of entire stream as laid out on disk after padding the final block to alignment boundary, including the header and user data. More...
 
void truncate (stream_size_type items)
 
void set_last_block_read_offset (stream_size_type n)
 
stream_size_type get_last_block_read_offset ()
 
bool get_compressed ()
 
int get_compression_flags ()
 

Static Public Member Functions

static memory_size_type memory_usage ()
 Return memory usage of this file accessor. More...
 

Protected Member Functions

memory_size_type boundary () const
 Returns the boundary on which we align blocks. More...
 
memory_size_type align_to_boundary (memory_size_type z) const
 Given a memory offset, rounds up to the nearest alignment boundary. More...
 
memory_size_type header_size () const
 The size of header and user data with padding included. More...
 
memory_size_type block_size () const
 
memory_size_type block_items () const
 
memory_size_type item_size () const
 
void set_size (stream_size_type s)
 

Protected Attributes

file_accessor_t m_fileAccessor
 

Detailed Description

template<typename file_accessor_t>
class tpie::file_accessor::stream_accessor< file_accessor_t >

Definition at line 29 of file stream_accessor.h.

Member Function Documentation

template<typename file_accessor_t>
memory_size_type tpie::file_accessor::stream_accessor_base< file_accessor_t >::align_to_boundary ( memory_size_type  z) const
inlineprotectedinherited

Given a memory offset, rounds up to the nearest alignment boundary.

Definition at line 97 of file stream_accessor_base.h.

Referenced by tpie::file_accessor::stream_accessor_base< tpie::file_accessor::posix >::header_size().

97 { return (z+boundary()-1)/boundary()*boundary(); }
memory_size_type boundary() const
Returns the boundary on which we align blocks.
template<typename file_accessor_t>
memory_size_type tpie::file_accessor::stream_accessor_base< file_accessor_t >::boundary ( ) const
inlineprotectedinherited

Returns the boundary on which we align blocks.

Definition at line 91 of file stream_accessor_base.h.

Referenced by tpie::file_accessor::stream_accessor_base< tpie::file_accessor::posix >::align_to_boundary().

91 { return 4096; }
template<typename file_accessor_t>
stream_size_type tpie::file_accessor::stream_accessor_base< file_accessor_t >::byte_size ( ) const
inlineinherited

Size (in bytes) of entire stream as laid out on disk after padding the final block to alignment boundary, including the header and user data.

Definition at line 204 of file stream_accessor_base.h.

Referenced by tpie::file_stream_base::flush_block(), tpie::file_stream_base::truncate(), and tpie::file_base::truncate().

204  {
205  return ((m_size + m_blockItems - 1)/m_blockItems) * m_blockSize + header_size();
206  }
memory_size_type header_size() const
The size of header and user data with padding included.
template<typename file_accessor_t>
memory_size_type tpie::file_accessor::stream_accessor_base< file_accessor_t >::header_size ( ) const
inlineprotectedinherited

The size of header and user data with padding included.

This is the offset at which the first logical block begins.

Definition at line 103 of file stream_accessor_base.h.

Referenced by tpie::file_accessor::stream_accessor_base< tpie::file_accessor::posix >::byte_size(), tpie::file_accessor::stream_accessor< file_accessor_t >::read_block(), and tpie::file_accessor::stream_accessor< file_accessor_t >::write_block().

103 { return align_to_boundary(sizeof(stream_header_t)+m_maxUserDataSize); }
memory_size_type align_to_boundary(memory_size_type z) const
Given a memory offset, rounds up to the nearest alignment boundary.
template<typename file_accessor_t>
memory_size_type tpie::file_accessor::stream_accessor_base< file_accessor_t >::max_user_data_size ( ) const
inlineinherited

Maximum size (in bytes) of the user data.

Definition at line 197 of file stream_accessor_base.h.

Referenced by tpie::file_base_crtp< file_stream_base >::max_user_data_size().

197 {return m_maxUserDataSize;}
template<typename file_accessor_t>
static memory_size_type tpie::file_accessor::stream_accessor_base< file_accessor_t >::memory_usage ( )
inlinestaticinherited

Return memory usage of this file accessor.

Definition at line 177 of file stream_accessor_base.h.

Referenced by tpie::file< T >::memory_usage(), and tpie::uncompressed_stream< T >::memory_usage().

177 {return sizeof(stream_accessor_base);}
template<typename file_accessor_t>
void tpie::file_accessor::stream_accessor_base< file_accessor_t >::open ( const std::string &  path,
bool  read,
bool  write,
memory_size_type  itemSize,
memory_size_type  blockSize,
memory_size_type  maxUserDataSize,
cache_hint  cacheHint,
int  compressionFlags 
)
inlineinherited

Open file for reading and/or writing.

template<typename file_accessor_t>
const std::string& tpie::file_accessor::stream_accessor_base< file_accessor_t >::path ( ) const
inlineinherited

Path of the file currently open.

Definition at line 187 of file stream_accessor_base.h.

Referenced by tpie::file_base_crtp< file_stream_base >::path().

187 {return m_path;}
template<typename file_accessor_t >
virtual memory_size_type tpie::file_accessor::stream_accessor< file_accessor_t >::read_block ( void *  data,
stream_size_type  blockNumber,
memory_size_type  itemCount 
)
inlineoverridevirtual

Read the given number of items from the given block into the given buffer.

Parameters
dataBuffer in which to store data. Must be able to hold at least sizeof(T)*itemCount bytes.
blockNumberNumber of block in which to begin reading.
itemCountNumber of items to read from beginning of given block. Must be less than m_blockItems.

Implements tpie::file_accessor::stream_accessor_base< file_accessor_t >.

Definition at line 31 of file stream_accessor.h.

References tpie::file_accessor::stream_accessor_base< file_accessor_t >::header_size(), and tpie::file_accessor::stream_accessor_base< file_accessor_t >::size().

34  {
35  stream_size_type loc = this->header_size() + blockNumber*this->block_size();
36  this->m_fileAccessor.seek_i(loc);
37  stream_size_type offset = blockNumber*this->block_items();
38  if (offset + itemCount > this->size()) itemCount = static_cast<memory_size_type>(this->size() - offset);
39  memory_size_type z=itemCount*this->item_size();
40  this->m_fileAccessor.read_i(data, z);
41  return itemCount;
42  }
stream_size_type size() const
Number of items in stream.
memory_size_type header_size() const
The size of header and user data with padding included.
template<typename file_accessor_t>
memory_size_type tpie::file_accessor::stream_accessor_base< file_accessor_t >::read_user_data ( void *  data,
memory_size_type  count 
)
inlineinherited

Read user data into the given buffer.

Parameters
dataBuffer in which to store user data.
countSize of buffer, in bytes. The method will read at most this number of bytes.
Returns
Number of bytes of user data actually read, in case this is less than count.

Referenced by tpie::file_base_crtp< file_stream_base >::read_user_data().

template<typename file_accessor_t>
stream_size_type tpie::file_accessor::stream_accessor_base< file_accessor_t >::size ( ) const
inlineinherited
template<typename file_accessor_t>
memory_size_type tpie::file_accessor::stream_accessor_base< file_accessor_t >::user_data_size ( ) const
inlineinherited

Size (in bytes) of the user data.

Definition at line 192 of file stream_accessor_base.h.

Referenced by tpie::file_base_crtp< file_stream_base >::user_data_size().

192 {return m_userDataSize;}
template<typename file_accessor_t >
virtual void tpie::file_accessor::stream_accessor< file_accessor_t >::write_block ( const void *  data,
stream_size_type  blockNumber,
memory_size_type  itemCount 
)
inlineoverridevirtual

Write the given number of items from the given buffer into the given block.

Parameters
dataBuffer from which to write data. Must hold at least sizeof(T)*itemCount bytes of data.
blockNumberNumber of block in which to write.
itemCountNumber of items to write to beginning of given block. Must be less than m_blockItems.

Implements tpie::file_accessor::stream_accessor_base< file_accessor_t >.

Definition at line 44 of file stream_accessor.h.

References tpie::file_accessor::stream_accessor_base< file_accessor_t >::header_size(), and tpie::file_accessor::stream_accessor_base< file_accessor_t >::size().

47  {
48  stream_size_type loc = this->header_size() + blockNumber*this->block_size();
49  // Here, we may seek beyond the file size.
50  // However, lseek(2) specifies that the file will be padded with zeroes in this case,
51  // and on Windows, the file is padded with arbitrary garbage (which is ok).
52  this->m_fileAccessor.seek_i(loc);
53  stream_size_type offset = blockNumber*this->block_items();
54  memory_size_type z=itemCount*this->item_size();
55  this->m_fileAccessor.write_i(data, z);
56  if (offset+itemCount > this->size()) this->set_size(offset+itemCount);
57  }
stream_size_type size() const
Number of items in stream.
memory_size_type header_size() const
The size of header and user data with padding included.
template<typename file_accessor_t>
void tpie::file_accessor::stream_accessor_base< file_accessor_t >::write_user_data ( const void *  data,
memory_size_type  count 
)
inlineinherited

Write user data to the stream.

Parameters
dataBuffer from which to write user data.
countNumber of bytes to write. Cannot exceed max_user_data_size().

Referenced by tpie::file_base_crtp< file_stream_base >::write_user_data().


The documentation for this class was generated from the following file: