42 log_fatal() <<
"Open failed: " << e.what() << std::endl;
48 stream(
const std::string & fileName,
51 : m_temp(fileName,
true)
57 if (st == APPEND_STREAM) m_stream.seek(0, file_stream_base::end);
59 log_fatal() <<
"Open failed: " << e.what() << std::endl;
77 bool is_valid()
const {
81 bool operator!()
const {
85 err read_item(T **elt) {
86 if (!m_stream.can_read())
89 *elt = &(
const_cast<T &
>(m_stream.read()));
93 err write_item(
const T &elt) {
97 log_warning() <<
"write_item failed: " << e.what() << std::endl;
103 err read_array(T *mm_space, stream_offset_type *len) {
104 size_type l=(size_t)*len;
105 err e = read_array(mm_space, l);
110 err read_array(T *mm_space, memory_size_type & len) {
111 size_type l =
static_cast<size_type
>(std::min(
112 static_cast<stream_size_type>(len),
113 static_cast<stream_size_type>(m_stream.size() - m_stream.offset())));
114 m_stream.read(mm_space, mm_space+l);
118 err write_array(
const T *mm_space, memory_size_type len) {
120 m_stream.write(mm_space, mm_space+len);
122 log_warning() <<
"write_item failed: " << e.what() << std::endl;
128 stream_offset_type stream_len(
void)
const {
129 return m_stream.size();
132 std::string name()
const {
133 return m_stream.path();
136 err seek(stream_offset_type offset) {
138 m_stream.seek(offset);
140 TP_LOG_WARNING_ID(
"BTE error - seek failed: " << e.what());
147 stream_offset_type tell()
const {
148 return m_stream.offset();
151 err truncate(stream_offset_type offset) {
153 m_stream.truncate(offset);
155 TP_LOG_WARNING_ID(
"BTE error - truncate failed: " << e.what());
162 err main_memory_usage(size_type *usage,
165 switch (usage_type) {
172 *usage = memory_usage(1);
175 *usage = file_stream<T>::memory_usage(block_factor())
176 - file_stream<T>::memory_usage(0.0);
182 static memory_size_type memory_usage(memory_size_type count) {
186 size_t available_streams(
void) {
190 memory_size_type chunk_size(
void)
const {
194 void persist(persistence p) {
198 persistence persist()
const {
202 std::string& sprint() {
203 static std::string buf;
204 std::stringstream ss;
205 ss <<
"STREAM " << name() <<
" " <<
static_cast<long>(stream_len());
223 static inline float block_factor() {
224 #ifndef STREAM_UFS_BLOCK_FACTOR
228 return static_cast<float>(STREAM_UFS_BLOCK_FACTOR)/32;
230 return static_cast<float>(STREAM_UFS_BLOCK_FACTOR)/512;
240 #endif // TPIE_STREAM_H
Sequential access is intended.
memory_size_type get_block_size()
Get the TPIE block size.
Maximum additional amount used by each substream created.
PERSIST_DELETE
Delete the stream from the disk when it is destructed.
Max amount that will ever be used.
void unused(const T &x)
Declare that a variable is unused on purpose.
No written blocks should be compressed.
Overhead of the object without the buffer.
Compressed stream public API.
void set_persistent(bool p)
Set persistence.
stream_status
AMI stream status.
file_manager & get_file_manager()
Return a reference to the file manager.
Class representing a reference to a temporary file.
size_t available() const noexcept
Return the amount of the resource still available to be assigned.
stream_type
AMI stream types passed to constructors.
logstream & log_fatal()
Return logstream for writing fatal log messages.
PERSIST_PERSISTENT
Do not delete the stream from the disk when it is destructed.
bool is_persistent() const
compression_flags
Possible values for the compressionFlags parameter to stream::open.
err
Legacy TPIE error codes.
An error occurred at the BTE level.
logstream & log_warning()
Return logstream for writing warning log messages.
An attempt was made to read past the end of a stream or write past the end of a substream.
Max amount ever used by a buffer.
Open a file for reading or writing.