Go to the documentation of this file.
24 #ifndef _TPIE_AMI_STACK_H
25 #define _TPIE_AMI_STACK_H
30 #include <tpie/stream.h>
48 , m_buffer(buffer_size(blockFactor))
61 stack(
const std::string & path,
double blockFactor=1.0)
63 , m_buffer(buffer_size(blockFactor))
69 m_stream.seek(0, file_stream_base::end);
80 , m_buffer(buffer_size(blockFactor))
86 m_stream.seek(0, file_stream_base::end);
105 inline void push(
const T & t) {
106 if (m_buffer.
size() == m_bufferItems) empty_buffer();
107 m_buffer[m_bufferItems++] = t;
114 if (m_bufferItems)
return m_buffer[--m_bufferItems];
115 const T & item =
m_stream.read_back();
123 if (m_bufferItems)
return m_buffer[m_bufferItems-1];
132 stream_size_type
size()
const {
133 return m_stream.offset()+m_bufferItems;
159 size_t m_bufferItems;
161 inline void empty_buffer() {
162 if (m_bufferItems == 0)
return;
168 static memory_size_type buffer_size(
double blockFactor) {
187 m_ulate(m_tempFile) {
200 : m_tempFile(path, true)
201 , m_ulate(m_tempFile)
238 return m_ulate.size();
245 return m_ulate.empty();
288 TP_LOG_WARNING_ID(
"Using AMI_stack<T>::stream_len() is deprecated.");
333 const T & res = m_ulate.pop();
357 const T & res = m_ulate.top();
376 switch (usage_type) {
385 *usage +=
sizeof(*this);
389 tp_assert(0,
"Unknown mem::stream_usage type added.");
401 #endif // _TPIE_AMI_STACK_H
bool empty() const
Returns whether the stack is empty or not.
const T & pop()
Pops one item from the stack.
file_stream< T > m_stream
The stream used to store the items.
err push(const T &t)
Pushes one item onto the stack.
static memory_size_type memory_usage(float blockFactor=1.0)
Compute the memory used by a stack.
@ END_OF_STREAM
An attempt was made to read past the end of a stream or write past the end of a substream.
stack(const std::string &path, stream_type type=READ_WRITE_STREAM)
Initializes the stack by (re-)opening the file given.
const T & top()
Peeks at the topmost item on the stack.
@ STREAM_USAGE_CURRENT
Amount currently in use.
PERSIST_DELETE
Delete the stream from the disk when it is destructed.
A generic array with a fixed size.
iterator begin()
Return an iterator to the beginning of the array.
stream_size_type size() const
Returns the number of items currently on the stack.
TPIE_OS_OFFSET size() const
Returns the number of items currently on the stack.
@ NO_ERROR
No error occurred.
An implementation of an external-memory stack.
@ STREAM_USAGE_BUFFER
Max amount ever used by a buffer.
@ compression_normal
Compress some blocks according to available resources (time, memory).
void set_persistent(bool p)
Set persistence.
persistence persist() const
Returns the persistence status of the (stream underlying the) stack.
#define tp_assert(condition, message)
void persist(persistence p)
Set the persistence status of the (stream underlying the) stack.
void unused(const T &x)
Declare that a variable is unused on purpose.
@ IO_ERROR
A low level I/O error occurred.
err pop(const T **t)
Pops one item from the stack.
err trim()
Truncates the underlying stream to the exact size (rounded up to the next block) of items.
@ access_normal
Neither sequential access nor random access is intended.
~stack()
Closes the underlying stream and truncates it to the logical end of the stack.
stack(temp_file &tempFile, double blockFactor=1.0)
Initialize temporary stack.
bool is_persistent() const
bool is_empty() const
Returns whether the stack is empty or not.
void push(const T &t)
Pushes one item onto the stack.
PERSIST_PERSISTENT
Do not delete the stream from the disk when it is destructed.
@ STREAM_USAGE_MAXIMUM
Max amount that will ever be used.
stack(const std::string &path, double blockFactor=1.0)
Initialize named, nontemporary stack.
@ STREAM_USAGE_SUBSTREAM
Maximum additional amount used by each substream created.
@ STREAM_USAGE_OVERHEAD
Overhead of the object without the buffer.
err main_memory_usage(TPIE_OS_SIZE_T *usage, stream_usage usage_type) const
Compute the memory used by the stack and the aggregated stream.
Class representing a reference to a temporary file.
@ access_read_write
Open a file for reading or writing.
stream_type
AMI stream types passed to constructors.
stack(double blockFactor=1.0)
Initialize anonymous stack.
err
Legacy TPIE error codes.
stack()
Initializes the stack.
An implementation of an external-memory stack compatible with the old AMI interface.
size_type size() const
Return the size of the array.
err peek(const T **t)
Peeks at the topmost item on the stack.
TPIE_OS_OFFSET stream_len() const