Base class containing the implementation details that are independent of the item type. More...
#include <tpie/compressed/stream.h>
Classes | |
| struct | seek_state |
Public Types | |
| typedef file_stream_base::offset_type | offset_type |
Public Member Functions | |
| bool | is_readable () const noexcept |
| bool | is_writable () const noexcept |
| memory_size_type | block_items () const |
| memory_size_type | block_size () const |
| template<typename TT > | |
| void | read_user_data (TT &data) |
| memory_size_type | read_user_data (void *data, memory_size_type count) |
| template<typename TT > | |
| void | write_user_data (const TT &data) |
| void | write_user_data (const void *data, memory_size_type count) |
| memory_size_type | user_data_size () const |
| memory_size_type | max_user_data_size () const |
| const std::string & | path () const |
| void | open (const std::string &path, access_type accessType, memory_size_type userDataSize=0, cache_hint cacheHint=access_sequential, compression_flags compressionFlags=compression_none) |
| Deprecated interface for opening a named stream. More... | |
| void | open (memory_size_type userDataSize, cache_hint cacheHint=access_sequential, compression_flags compressionFlags=compression_none) |
| Deprecated interface for opening an unnamed temporary stream. More... | |
| void | open (temp_file &file, access_type accessType, memory_size_type userDataSize=0, cache_hint cacheHint=access_sequential, compression_flags compressionFlags=compression_none) |
| Deprecated interface for opening a temporary stream. More... | |
| void | open (const std::string &path, compression_flags compressionFlags) |
| Deprecated interface for opening a named stream. More... | |
| void | open (compression_flags compressionFlags) |
| Deprecated interface for opening an unnamed temporary stream. More... | |
| void | open (temp_file &file, compression_flags compressionFlags) |
| Deprecated interface for opening a temporary stream. More... | |
| void | open (const std::string &path, open::type openFlags=open::defaults, memory_size_type userDataSize=0) |
| Open and possibly create a stream. More... | |
| void | open (open::type openFlags=open::defaults, memory_size_type userDataSize=0) |
| Open and create an unnamed temporary stream. More... | |
| void | open (temp_file &file, open::type openFlags=open::defaults, memory_size_type userDataSize=0) |
| Open and possibly create a temporary stream. More... | |
| void | close () |
| bool | is_open () const noexcept |
| stream_size_type | offset () const |
| void | describe (std::ostream &out) |
| For debugging: Describe the internal stream state in a string. More... | |
| std::string | describe () |
| For debugging: Describe the internal stream state in a string. More... | |
| void | seek (stream_offset_type offset, offset_type whence=beginning) |
| Precondition: is_open() Precondition: offset == 0. More... | |
| void | truncate (stream_size_type offset) |
| Truncate to given size. More... | |
| void | truncate (const stream_position &pos) |
| Truncate to given stream position. More... | |
| stream_position | get_position () |
| Store the current stream position such that it may be found later on. More... | |
| void | set_position (const stream_position &pos) |
Seek to a position that was previously recalled with get_position. More... | |
| stream_size_type | size () const |
| stream_size_type | file_size () const |
| bool | can_read () |
| Check if the next call to read() will succeed or not. More... | |
| bool | can_read_back () |
| Check if the next call to read_back() will succeed or not. More... | |
Static Public Attributes | |
| static const file_stream_base::offset_type | beginning = file_stream_base::beginning |
| static const file_stream_base::offset_type | end = file_stream_base::end |
| static const file_stream_base::offset_type | current = file_stream_base::current |
Protected Member Functions | |
| compressed_stream_base (memory_size_type itemSize, double blockFactor) | |
| void | cache_read_writes () |
| Compute number of cheap, unchecked reads/writes we can do from now. More... | |
| void | peak_unlikely () |
| void | read_back_unlikely () |
| void | write_unlikely (const char *item) |
Static Protected Member Functions | |
| static memory_size_type | memory_usage (double blockFactor=1.0) noexcept |
Protected Attributes | |
| memory_size_type | m_cachedReads |
| Number of cheap, unchecked reads we can do next. More... | |
| memory_size_type | m_cachedWrites |
| Number of cheap, unchecked writes we can do next. More... | |
| stream_size_type | m_size |
| Number of logical items in the stream. More... | |
| seek_state::type | m_seekState |
| Buffer manager for this entire stream. More... | |
| stream_size_type | m_offset |
| Offset of next item to read/write, relative to beginning of stream. More... | |
| char * | m_bufferBegin |
| Only when m_buffer.get() != 0: First item in writable buffer. More... | |
| char * | m_bufferEnd |
| Only when m_buffer.get() != 0: End of writable buffer. More... | |
| char * | m_nextItem |
| Next item in buffer to read/write. More... | |
| compressed_stream_base_p * | m_p |
Friends | |
| class | compressed_stream_base_p |
Base class containing the implementation details that are independent of the item type.
|
protected |
Compute number of cheap, unchecked reads/writes we can do from now.
|
inline |
Check if the next call to read() will succeed or not.
|
inline |
| std::string tpie::compressed_stream_base::describe | ( | ) |
For debugging: Describe the internal stream state in a string.
| void tpie::compressed_stream_base::describe | ( | std::ostream & | out | ) |
For debugging: Describe the internal stream state in a string.
| stream_position tpie::compressed_stream_base::get_position | ( | ) |
Store the current stream position such that it may be found later on.
The stream_position object is violated if the stream is eventually truncated to before the current position.
The stream_position objects are plain old data, so they may themselves be written to streams.
Blocks to take the compressor lock.
| void tpie::compressed_stream_base::open | ( | compression_flags | compressionFlags | ) |
Deprecated interface for opening an unnamed temporary stream.
| void tpie::compressed_stream_base::open | ( | const std::string & | path, |
| access_type | accessType, | ||
| memory_size_type | userDataSize = 0, |
||
| cache_hint | cacheHint = access_sequential, |
||
| compression_flags | compressionFlags = compression_none |
||
| ) |
Deprecated interface for opening a named stream.
If compressionFlags is compression_none and the file does not already exist, no compression will be used when writing. If compressionFlags is compression_normal and the file does not already exist, compression will be used when writing. If the file already exists, the compression flags of the existing file are used instead.
| void tpie::compressed_stream_base::open | ( | const std::string & | path, |
| compression_flags | compressionFlags | ||
| ) |
Deprecated interface for opening a named stream.
| void tpie::compressed_stream_base::open | ( | const std::string & | path, |
| open::type | openFlags = open::defaults, |
||
| memory_size_type | userDataSize = 0 |
||
| ) |
Open and possibly create a stream.
The stream is created if it does not exist and opened for reading and writing, but this can be changed with open::read_only or open::write_only; see below.
The flags supplied to openFlags should be a combination of the following from open::type, OR'ed together:
open::read_only Open for reading only, and fail if the stream does not exist.
open::write_only Open for writing only, and truncate the stream if it exists.
open::access_normal By default, POSIX_FADV_SEQUENTIAL is passed to the open syscall to indicate that the OS should optimize for sequential access; this flag disables that flag.
open::access_random Pass POSIX_FADV_RANDOM to the open syscall to make the OS optimize for random access.
open::compression_normal Create the stream in compression mode if it does not already exist, and compress written blocks according to available resources (for instance CPU time and memory).
open::compression_all Create the stream in compression mode if it does not already exist, and compress all written blocks using the preferred compression scheme, which can be set using tpie::the_compressor_thread().set_preferred_compression().
| path | The path to the file to open |
| openFlags | A bit-wise combination of the flags; see above. |
| userDataSize | Required user data capacity in stream header. |
| void tpie::compressed_stream_base::open | ( | memory_size_type | userDataSize, |
| cache_hint | cacheHint = access_sequential, |
||
| compression_flags | compressionFlags = compression_none |
||
| ) |
Deprecated interface for opening an unnamed temporary stream.
| void tpie::compressed_stream_base::open | ( | open::type | openFlags = open::defaults, |
| memory_size_type | userDataSize = 0 |
||
| ) |
Open and create an unnamed temporary stream.
| openFlags | A bit-wise combination of the flags; see above. |
| userDataSize | Required user data capacity in stream header. |
| void tpie::compressed_stream_base::open | ( | temp_file & | file, |
| access_type | accessType, | ||
| memory_size_type | userDataSize = 0, |
||
| cache_hint | cacheHint = access_sequential, |
||
| compression_flags | compressionFlags = compression_none |
||
| ) |
Deprecated interface for opening a temporary stream.
| void tpie::compressed_stream_base::open | ( | temp_file & | file, |
| compression_flags | compressionFlags | ||
| ) |
Deprecated interface for opening a temporary stream.
| void tpie::compressed_stream_base::open | ( | temp_file & | file, |
| open::type | openFlags = open::defaults, |
||
| memory_size_type | userDataSize = 0 |
||
| ) |
Open and possibly create a temporary stream.
| file | The temporary file to open |
| openFlags | A bit-wise combination of the flags; see above. |
| userDataSize | Required user data capacity in stream header. |
| void tpie::compressed_stream_base::seek | ( | stream_offset_type | offset, |
| offset_type | whence = beginning |
||
| ) |
Precondition: is_open() Precondition: offset == 0.
| void tpie::compressed_stream_base::set_position | ( | const stream_position & | pos | ) |
Seek to a position that was previously recalled with get_position.
| void tpie::compressed_stream_base::truncate | ( | const stream_position & | pos | ) |
Truncate to given stream position.
| void tpie::compressed_stream_base::truncate | ( | stream_size_type | offset | ) |
Truncate to given size.
Precondition: compression is disabled or offset is size() or 0. Blocks to take the compressor lock.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
Offset of next item to read/write, relative to beginning of stream.
Invariants:
block_number() in [0, m_streamBlocks] offset in [0, size] block_item_index() in [0, m_blockSize) offset == block_number() * m_blockItems + block_item_index()
block_item_index() <= offset.
If block_number() == m_streamBlocks, we are in a block that has not yet been written to disk.
|
protected |
|
protected |