Go to the documentation of this file.
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
std::string name() const
Returns the path name of this stream in newly allocated space.
@ END_OF_STREAM
An attempt was made to read past the end of a stream or write past the end of a substream.
Simple class acting both as a tpie::file and a tpie::file::stream.
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 & sprint()
Return a string describing the stream.
void persist(persistence p)
Set the stream's persistence flag to p, which can have one of two values: PERSIST_DELETE or PERSIST_P...
@ STREAM_USAGE_CURRENT
Amount currently in use.
PERSIST_DELETE
Delete the stream from the disk when it is destructed.
const std::string & path()
Get the path of the associated file.
size_t available() const noexcept
Return the amount of the resource still available to be assigned.
uncompressed_stream< T > & underlying_stream()
Get the underlying uncompressed_stream<T>
stream_offset_type stream_len(void) const
Returns the number of items in the stream.
@ NO_ERROR
No error occurred.
@ STREAM_USAGE_BUFFER
Max amount ever used by a buffer.
A Stream<T> 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<T> object (in bytes).
bool operator!() const
Returns true if the block's status is not BLOCK_STATUS_VALID.
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.
@ STREAM_STATUS_INVALID
Stream is invalid.
static constexpr memory_size_type memory_usage(float blockFactor=1.0, bool includeDefaultFileAccessor=true) noexcept
Calculate the amount of memory used by a single uncompressed_stream.
void set_persistent(bool p)
Set persistence.
memory_size_type block_size() const
Get the size of a block in bytes.
@ BTE_ERROR
An error occurred at the BTE level.
void unused(const T &x)
Declare that a variable is unused on purpose.
stream_old()
A new stream of type READ_WRITE_STREAM is constructed on the given device as a file with a randomly g...
stream_offset_type tell() const
Returns the current position in the stream measured of items from the beginning of the stream.
err write_item(const T &elt)
Writes elt to the stream in the current position.
stream_status
AMI stream status.
bool is_valid() const
Returns wether the status of the stream is STREAM_STATUS_VALID.
persistence persist() const
Set the stram's persistence flag to PERSIST_PERSISTENT, thereby ensuring it is not deleted when destr...
size_t available_streams(void)
Returns the number of globally available streams.
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.
static memory_size_type memory_usage(memory_size_type count)
Returns the number of bytes that count streams will maximaly consume.
bool is_persistent() const
stream_status status() const
Returns the status of the stream instance; the result is either STREAM_STATUS_VALID or STREAM_STATUS_...
memory_size_type chunk_size(void) const
Returns the maximum number of items (of type T) that can be stored in one block.
PERSIST_PERSISTENT
Do not delete the stream from the disk when it is destructed.
@ STREAM_USAGE_MAXIMUM
Max amount that will ever be used.
@ STREAM_STATUS_VALID
Stream is valid.
@ STREAM_USAGE_SUBSTREAM
Maximum additional amount used by each substream created.
@ STREAM_USAGE_OVERHEAD
Overhead of the object without the buffer.
Class representing a reference to a temporary file.
@ access_read_write
Open a file for reading or writing.
err truncate(stream_offset_type offset)
Resize the stream to off items.
Simple class acting both as file and a file::stream.
stream_type
AMI stream types passed to constructors.
TPIE_EXPORT file_manager & get_file_manager()
Return a reference to the file manager.
err
Legacy TPIE error codes.
err read_item(T **elt)
Reads the current item from the stream and advance the "current item" pointer to the next item.
@ access_read
Open a file for reading.