2#ifndef _aspose_system_collections_stack_h_
3#define _aspose_system_collections_stack_h_
5#include "system/object.h"
6#include "system/array.h"
7#include "system/collections/base_enumerator.h"
8#include "system/collections/icollection.h"
9#include "system/cycles_detection.h"
15namespace Collections {
19template<
typename T>
class Stack;
88 ASPOSE_COLLECTION_POINTER_MODE_CONTROL(T)
100 typedef std::list<T, ASPOSE_COLLECTION_ALLOCATOR_TYPE>
stack_t;
131 Stack() : ASPOSE_COLLECTION_INIT_ALLOCATOR() {}
135 Stack(
int capacity) : ASPOSE_COLLECTION_INIT_ALLOCATOR()
139 throw ArgumentOutOfRangeException(u
"capacity");
148 AddRange(collection);
161 return ASPOSECPP_CHECKED_CAST(
int, m_data.size());
174 return std::find(m_data.begin(), m_data.end(), item) != m_data.end();
180 m_data.push_back(item);
187 throw InvalidOperationException(u
"Stack is empty");
189 T rv = m_data.back();
198 throw InvalidOperationException(u
"Stack is empty");
200 return m_data.back();
214 ArrayPtr<T> result = System::MakeObject<Array<T> >(this->get_Count());
216 std::copy(m_data.rbegin(), m_data.rend(), result->data().
begin());
228 throw ArgumentNullException(u
"collection");
232 while (it->MoveNext())
234 m_data.push_back(it->Current());
241 return new System::Details::NativeIteratorWrapper<T, typename stack_t::reverse_iterator>(m_data.rbegin(), m_data.rend());
246 return new System::Details::NativeIteratorWrapper<T, typename stack_t::reverse_iterator>(m_data.rend(), m_data.rend());
251 return new System::Details::NativeConstIteratorWrapper<T, typename stack_t::const_reverse_iterator>(m_data.crbegin(), m_data.crend());
256 return new System::Details::NativeConstIteratorWrapper<T, typename stack_t::const_reverse_iterator>(m_data.crend(), m_data.crend());
263#ifdef __DBG_FOR_EACH_MEMBER
267 void DBG_for_each_member(DBG::for_each_member_visitor &visitor)
const override
269 visitor.add_self(
this);
270 DBG::for_each_of_Object(
this, m_data, visitor);
275 const char* DBG_class_name()
const override {
return "Stack<T>"; }
279#ifdef ASPOSE_GET_SHARED_MEMBERS
281 DEFINE_GET_SHARED_MEMBERS(m_data)
Interface of object providing enumerator on contained elements.
Definition: ienumerable.h:25
Enumerator that reverse-iterates through container. Objects of this class should only be allocated us...
Definition: base_enumerator.h:172
Enumerator to iterate through stack. Objects of this class should only be allocated using System::Mak...
Definition: stack.h:121
RTTI_INFO_TEMPLATE_CLASS(Stack< T >::Enumerator, System::BaseTypesInfo< System::Object >)
RTTI information.
Enumerator(const ThisPtr &data)
Constructs enumerator iterating through given stack.
Definition: stack.h:125
Stack class forward declaration.
Definition: stack.h:87
stack_t::reverse_iterator queueIt_t
Iterator type.
Definition: stack.h:106
T ValueType
Value type.
Definition: stack.h:92
System::Details::VirtualizedIteratorBase< T > * virtualizeEndIterator() override
Gets the implementation of end iterator for the current container.
Definition: stack.h:244
T Peek()
Gets element from stack top, but keeps it in stack.
Definition: stack.h:195
T Pop()
Gets element from top of the stack.
Definition: stack.h:184
System::Details::VirtualizedIteratorBase< T > * virtualizeBeginIterator() override
Gets the implementation of begin iterator for the current container.
Definition: stack.h:239
SharedPtr< IEnumerable< T > > IEnumerablePtr
Collection containing elements of same type.
Definition: stack.h:112
System::Details::VirtualizedIteratorBase< T > * virtualizeBeginConstIterator() const override
Gets the implementation of begin const iterator for the current container.
Definition: stack.h:249
const stack_t & data() const
Internal data structure accessor.
Definition: stack.h:208
virtual int get_Count() const
Gets number of elements in stack.
Definition: stack.h:159
~Stack() override=default
Destructor.
stack_t m_data
Underlying data structure.
Definition: stack.h:108
void Push(const T &item)
Puts element of top of the stack.
Definition: stack.h:178
std::list< T, ASPOSE_COLLECTION_ALLOCATOR_TYPE > stack_t
Underlying data type.
Definition: stack.h:100
IEnumeratorPtr GetEnumerator() override
Gets enumerator to iterate through current stack.
Definition: stack.h:153
SharedPtr< Stack< T > > ThisPtr
Pointer type.
Definition: stack.h:104
virtual bool Contains(const T &item) const
Checks if specific item is present in container; uses operator == for comparison.
Definition: stack.h:172
void AddRange(IEnumerablePtr collection)
Puts elements into stack.
Definition: stack.h:224
virtual ArrayPtr< T > ToArray()
Converts stack to array.
Definition: stack.h:212
SharedPtr< IEnumerator< T > > IEnumeratorPtr
Enumerator type.
Definition: stack.h:114
stack_t & data()
Internal data structure accessor.
Definition: stack.h:205
Stack(IEnumerablePtr collection)
Copy constructor.
Definition: stack.h:146
Stack()
Constructs empty stack.
Definition: stack.h:131
virtual void Clear()
Deletes all elements from stack.
Definition: stack.h:164
System::Details::VirtualizedIteratorBase< T > * virtualizeEndConstIterator() const override
Gets the implementation of end const iterator for the current container.
Definition: stack.h:254
Stack(int capacity)
Constructs empty stack.
Definition: stack.h:135
Stack pointer. This type is a pointer to manage other object's deletion. It should be allocated on st...
Definition: stack.h:27
StackPtr(const SharedPtr< Stack< T > > &obj)
Constructs pointer referencing specific stack.
Definition: stack.h:33
StackPtr()
Constructs null pointer.
Definition: stack.h:30
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
auto begin() -> decltype(std::declval< Q >().begin())
Accessor for begin() method of an underling collection. Only compiles if SmartPtr_ is specialization ...
Definition: smart_ptr.h:830
Definition: db_command.h:9
SmartPtr< X > MakeSharedPtr(X *p)
Converts raw pointer to smart pointer.
Definition: smart_ptr.h:1650