23 #ifndef _TPIE_AMI_STREAM_H
24 #define _TPIE_AMI_STREAM_H
28 #include <tpie/config.h>
118 stream(
const std::string& path_name,
141 stream_offset_type sub_begin,
142 stream_offset_type sub_end,
214 return m_stream.size();
220 inline std::string
name()
const;
225 inline err seek(stream_offset_type offset);
231 inline stream_offset_type
tell()
const {
232 return m_stream.offset();
271 static memory_size_type
memory_usage(memory_size_type count);
349 static inline float block_factor() {
350 #ifndef STREAM_UFS_BLOCK_FACTOR
354 return static_cast<float>(STREAM_UFS_BLOCK_FACTOR)/32;
356 return static_cast<float>(STREAM_UFS_BLOCK_FACTOR)/512;
368 TP_LOG_DEBUG_ID(
"Temporary stream in file: ");
369 TP_LOG_DEBUG_ID( m_temp.
path() );
371 m_stream.open( m_temp );
373 TP_LOG_FATAL_ID(
"Open failed: " << e.what());
388 if (st == APPEND_STREAM) m_stream.seek(0, file_stream_base::end);
390 TP_LOG_FATAL_ID(
"Open failed: " << e.what());
400 stream_offset_type sub_begin,
401 stream_offset_type sub_end,
414 return m_stream.path();
421 m_stream.seek(offset);
423 TP_LOG_WARNING_ID(
"BTE error - seek failed: " << e.what());
433 m_stream.truncate(offset);
435 TP_LOG_WARNING_ID(
"BTE error - truncate failed: " << e.what());
452 switch (usage_type) {
459 *usage = memory_usage(1);
470 if (!m_stream.can_read())
473 *elt = &(
const_cast<T &
>(m_stream.read()));
485 size_type l=(size_t)*len;
486 err e = read_array(mm_space, l);
493 size_type l =
static_cast<size_type
>(std::min(
494 static_cast<stream_size_type>(len),
495 static_cast<stream_size_type>(m_stream.size() - m_stream.offset())));
496 m_stream.read(mm_space, mm_space+l);
502 m_stream.write(mm_space, mm_space+len);
508 static std::string buf;
509 std::stringstream ss;
510 ss <<
"STREAM " << name() <<
" " <<
static_cast<long>(stream_len());
519 #endif // _TPIE_AMI_STREAM_H
Defines the tp_assert macro.
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 write_item(const T &elt)
Writes elt to the stream in the current position.
static memory_size_type memory_usage(memory_size_type count)
Returns the number of bytes that count streams will maximaly consume.
Maximum additional amount used by each substream created.
bool operator!() const
Returns true if the block's status is not BLOCK_STATUS_VALID.
PERSIST_DELETE
Delete the stream from the disk when it is destructed.
Max amount that will ever be used.
std::string name() const
Returns the path name of this stream in newly allocated space.
stream_offset_type tell() const
Returns the current position in the stream measured of items from the beginning of the stream...
persistence persist() const
Set the stram's persistence flag to PERSIST_PERSISTENT, thereby ensuring it is not deleted when destr...
void unused(const T &x)
Declare that a variable is unused on purpose.
err new_substream(stream_type st, stream_offset_type sub_begin, stream_offset_type sub_end, stream< T > **sub_stream)
A substream is a TPIE stream that is part of another TPIE stream.
This file contains a few deprecated definitions for legacy code.
Count the number of open files.
Overhead of the object without the buffer.
std::string & sprint()
Return a string describing the stream.
void set_persistent(bool p)
Set persistence.
Logging functionality and log_level codes for different priorities of log messages.
err read_item(T **elt)
Reads the current item from the stream and advance the "current item" pointer to the next item...
stream()
A new stream of type READ_WRITE_STREAM is constructed on the given device as a file with a randomly g...
file_stream< T > & underlying_stream()
Get the underlying file_stream
err truncate(stream_offset_type offset)
Resize the stream to off items.
void persist(persistence p)
Set the stream's persistence flag to p, which can have one of two values: PERSIST_DELETE or PERSIST_P...
err seek(stream_offset_type offset)
Move the current position to off (measured in terms of items.
stream_offset_type stream_len(void) const
Returns the number of items in the stream.
stream_status
AMI stream status.
const std::string & path()
Get the path of the associated file.
Class representing the existence of a temporary file.
size_t available_streams(void)
Returns the number of globally available streams.
Persistence tags for deprecated TPIE AMI streams.
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)...
stream_type
AMI stream types passed to constructors.
A Stream object stores an ordered collection of objects of type T on external memory.
memory_size_type block_size() const
Get the size of a block in bytes.
memory_size_type available_files()
Return the additional number of files that can be opened before running out of file descriptors...
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 file_stream.
bool is_persistent() const
Simple class acting both as file and a file::stream.
err
Legacy TPIE error codes.
An error occurred at the BTE level.
bool is_valid() const
Returns wether the status of the stream is STREAM_STATUS_VALID.
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.
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.
Max amount ever used by a buffer.
Open a file for reading or writing.
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.