23 #ifndef _TPIE_AMI_STREAM_H
24 #define _TPIE_AMI_STREAM_H
28 #include <tpie/config.h>
46 #include <tpie/file_manager.h>
142 stream_offset_type sub_begin,
143 stream_offset_type sub_end,
215 return m_stream.size();
221 inline std::string
name()
const;
226 inline err seek(stream_offset_type offset);
232 inline stream_offset_type
tell()
const {
233 return m_stream.offset();
272 static memory_size_type
memory_usage(memory_size_type count);
350 static inline float block_factor() {
351 #ifndef STREAM_UFS_BLOCK_FACTOR
355 return static_cast<float>(STREAM_UFS_BLOCK_FACTOR)/32;
357 return static_cast<float>(STREAM_UFS_BLOCK_FACTOR)/512;
369 TP_LOG_DEBUG_ID(
"Temporary stream in file: ");
370 TP_LOG_DEBUG_ID( m_temp.
path() );
372 m_stream.open( m_temp );
375 TP_LOG_FATAL_ID(
"Open failed: " << e.what());
390 if (st == APPEND_STREAM) m_stream.seek(0, file_stream_base::end);
393 TP_LOG_FATAL_ID(
"Open failed: " << e.what());
403 stream_offset_type sub_begin,
404 stream_offset_type sub_end,
417 return m_stream.path();
424 m_stream.seek(offset);
427 TP_LOG_WARNING_ID(
"BTE error - seek failed: " << e.what());
437 m_stream.truncate(offset);
440 TP_LOG_WARNING_ID(
"BTE error - truncate failed: " << e.what());
457 switch (usage_type) {
464 *usage = memory_usage(1);
475 if (!m_stream.can_read())
478 *elt = &(
const_cast<T &
>(m_stream.read()));
490 size_type l=(size_t)*len;
491 err e = read_array(mm_space, l);
498 size_type l =
static_cast<size_type
>(std::min(
499 static_cast<stream_size_type>(len),
500 static_cast<stream_size_type>(m_stream.size() - m_stream.offset())));
501 m_stream.read(mm_space, mm_space+l);
507 m_stream.write(mm_space, mm_space+len);
513 static std::string buf;
514 std::stringstream ss;
515 ss <<
"STREAM " << name() <<
" " <<
static_cast<long>(stream_len());
524 #endif // _TPIE_AMI_STREAM_H
A Stream object stores an ordered collection of objects of type T on external memory.
err main_memory_usage(size_type *usage, stream_usage usage_type) const
This function is used for obtaining the amount of main memory used by an Stream object (in bytes)...
Defines the tp_assert macro.
err truncate(stream_offset_type offset)
Resize the stream to off items.
Maximum additional amount used by each substream created.
void persist(persistence p)
Set the stream's persistence flag to p, which can have one of two values: PERSIST_DELETE or PERSIST_P...
bool operator!() const
Returns true if the block's status is not BLOCK_STATUS_VALID.
stream_offset_type stream_len(void) const
Returns the number of items in the stream.
PERSIST_DELETE
Delete the stream from the disk when it is destructed.
Max amount that will ever be used.
err write_array(const T *mm_space, memory_size_type len)
Writes len items from array |mm_array to the stream, starting in the current position.
std::string name() const
Returns the path name of this stream in newly allocated space.
void unused(const T &x)
Declare that a variable is unused on purpose.
std::string & sprint()
Return a string describing the stream.
This file contains a few deprecated definitions for legacy code.
Overhead of the object without the buffer.
void set_persistent(bool p)
Set persistence.
Logging functionality and log_level codes for different priorities of log messages.
persistence persist() const
Set the stram's persistence flag to PERSIST_PERSISTENT, thereby ensuring it is not deleted when destr...
err new_substream(stream_type st, stream_offset_type sub_begin, stream_offset_type sub_end, stream_old< T > **sub_stream)
A substream is a TPIE stream that is part of another TPIE stream.
memory_size_type chunk_size(void) const
Returns the maximum number of items (of type T) that can be stored in one block.
stream_status status() const
Returns the status of the stream instance; the result is either STREAM_STATUS_VALID or STREAM_STATUS_...
uncompressed_stream< T > & underlying_stream()
Get the underlying uncompressed_stream
stream_status
AMI stream status.
bool is_valid() const
Returns wether the status of the stream is STREAM_STATUS_VALID.
const std::string & path()
Get the path of the associated file.
file_manager & get_file_manager()
Return a reference to the file manager.
Class representing a reference to a temporary file.
Persistence tags for deprecated TPIE AMI streams.
err read_array(T *mm_space, stream_offset_type *len)
Reads *len items from the current position of the stream into the array mm_array. ...
err seek(stream_offset_type offset)
Move the current position to off (measured in terms of items.
size_t available() const noexcept
Return the amount of the resource still available to be assigned.
stream_type
AMI stream types passed to constructors.
stream_offset_type tell() const
Returns the current position in the stream measured of items from the beginning of the stream...
memory_size_type block_size() const
Get the size of a block in bytes.
PERSIST_PERSISTENT
Do not delete the stream from the disk when it is destructed.
static memory_size_type memory_usage(float blockFactor=1.0, bool includeDefaultFileAccessor=true)
Calculate the amount of memory used by a single uncompressed_stream.
Simple class acting both as file and a file::stream.
bool is_persistent() const
stream_old()
A new stream of type READ_WRITE_STREAM is constructed on the given device as a file with a randomly g...
err write_item(const T &elt)
Writes elt to the stream in the current position.
err read_item(T **elt)
Reads the current item from the stream and advance the "current item" pointer to the next item...
err
Legacy TPIE error codes.
size_t available_streams(void)
Returns the number of globally available streams.
An error occurred at the BTE level.
Simple class acting both as a tpie::file and a tpie::file::stream.
An attempt was made to read past the end of a stream or write past the end of a substream.
static memory_size_type memory_usage(memory_size_type count)
Returns the number of bytes that count streams will maximaly consume.
Max amount ever used by a buffer.
Open a file for reading or writing.