CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
stack.h
1
2#ifndef _aspose_system_collections_stack_h_
3#define _aspose_system_collections_stack_h_
4
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"
10
11#include <list>
12#include <iterator>
13
14namespace System {
15namespace Collections {
16namespace Generic {
17
19template<typename T> class Stack;
20
25template<typename T>
26class ASPOSECPP_SHARED_CLASS StackPtr : public SharedPtr<Stack<T> >
27{
28public:
33 StackPtr(const SharedPtr<Stack<T> >& obj) : SharedPtr<Stack<T> >(obj) { }
34};
35
85template<typename T>
86class ASPOSECPP_SHARED_CLASS Stack : public IEnumerable<T>
87{
88 ASPOSE_COLLECTION_POINTER_MODE_CONTROL(T)
89
90public:
92 typedef T ValueType;
93
94private:
96 RTTI_INFO_TEMPLATE_CLASS(System::Collections::Generic::Stack<T>, System::BaseTypesInfo<System::Object>);
97
98public:
100 typedef std::list<T, ASPOSE_COLLECTION_ALLOCATOR_TYPE> stack_t;
101
102protected:
106 typedef typename stack_t::reverse_iterator queueIt_t;
109
110public:
115
120 class Enumerator : public ReverseEnumerator<stack_t>
121 {
122 public:
125 Enumerator(const ThisPtr& data) : ReverseEnumerator<stack_t>(data, data->m_data) { }
127 RTTI_INFO_TEMPLATE_CLASS(Stack<T>::Enumerator, System::BaseTypesInfo<System::Object>);
128 };
129
131 Stack() : ASPOSE_COLLECTION_INIT_ALLOCATOR() {}
135 Stack(int capacity) : ASPOSE_COLLECTION_INIT_ALLOCATOR()
136 {
137 if (capacity < 0)
138 {
139 throw ArgumentOutOfRangeException(u"capacity");
140 }
141 /* do nothing, underlying data structure doesn't support reserve */
142 }
146 Stack(IEnumerablePtr collection) : ASPOSE_COLLECTION_INIT_ALLOCATOR()
147 {
148 AddRange(collection);
149 }
150
154 {
155 return MakeObject<Enumerator>(MakeSharedPtr(this));
156 }
159 virtual int get_Count() const
160 {
161 return ASPOSECPP_CHECKED_CAST(int, m_data.size());
162 }
164 virtual void Clear()
165 {
166 m_data.clear();
167 }
168
172 virtual bool Contains(const T& item) const
173 {
174 return std::find(m_data.begin(), m_data.end(), item) != m_data.end();
175 }
178 void Push(const T& item)
179 {
180 m_data.push_back(item);
181 }
184 T Pop()
185 {
186 if (m_data.empty())
187 throw InvalidOperationException(u"Stack is empty");
188
189 T rv = m_data.back();
190 m_data.pop_back();
191 return rv;
192 }
196 {
197 if (m_data.empty())
198 throw InvalidOperationException(u"Stack is empty");
199
200 return m_data.back();
201 }
202
205 stack_t& data() { return m_data; }
208 const stack_t& data() const { return m_data; }
209
213 {
214 ArrayPtr<T> result = System::MakeObject<Array<T> >(this->get_Count());
215
216 std::copy(m_data.rbegin(), m_data.rend(), result->data().begin());
217
218 return result;
219 }
220
224 void AddRange(IEnumerablePtr collection)
225 {
226 if (!collection)
227 {
228 throw ArgumentNullException(u"collection");
229 }
230
231 IEnumeratorPtr it = collection->GetEnumerator();
232 while (it->MoveNext())
233 {
234 m_data.push_back(it->Current());
235 }
236 }
237
239 System::Details::VirtualizedIteratorBase<T>* virtualizeBeginIterator() override
240 {
241 return new System::Details::NativeIteratorWrapper<T, typename stack_t::reverse_iterator>(m_data.rbegin(), m_data.rend());
242 }
244 System::Details::VirtualizedIteratorBase<T>* virtualizeEndIterator() override
245 {
246 return new System::Details::NativeIteratorWrapper<T, typename stack_t::reverse_iterator>(m_data.rend(), m_data.rend());
247 }
249 System::Details::VirtualizedIteratorBase<T>* virtualizeBeginConstIterator() const override
250 {
251 return new System::Details::NativeConstIteratorWrapper<T, typename stack_t::const_reverse_iterator>(m_data.crbegin(), m_data.crend());
252 }
254 System::Details::VirtualizedIteratorBase<T>* virtualizeEndConstIterator() const override
255 {
256 return new System::Details::NativeConstIteratorWrapper<T, typename stack_t::const_reverse_iterator>(m_data.crend(), m_data.crend());
257 }
258
259protected:
261 ~Stack() override = default;
262
263#ifdef __DBG_FOR_EACH_MEMBER
264public:
267 void DBG_for_each_member(DBG::for_each_member_visitor &visitor) const override
268 {
269 visitor.add_self(this);
270 DBG::for_each_of_Object(this, m_data, visitor);
271 }
272
275 const char* DBG_class_name() const override { return "Stack<T>"; }
276#endif
277
278protected:
279#ifdef ASPOSE_GET_SHARED_MEMBERS
281 DEFINE_GET_SHARED_MEMBERS(m_data)
282#endif
283};
284
285} // namespace Generic
286} // namespace Collections
287} // namespace System
288
289#endif // _aspose_system_collections_stack_h_
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