|
|
|
|
| #ifndef _CLI_STACK_
|
| #define _CLI_STACK_
|
| #include <cliext/deque>
|
| #include <cliext/iterator>
|
|
|
| namespace cliext {
|
| namespace impl {
|
|
|
|
|
|
|
| template<typename _Value_t,
|
| typename _Cont_t>
|
| ref class stack_base
|
| : public _STLCLR IStack<_Value_t,
|
| typename _Container_traits<_Cont_t>::generic_container_handle>
|
| {
|
| public:
|
|
|
| typedef stack_base<_Value_t, _Cont_t> _Mytype_t;
|
| typedef _STLCLR IStack<_Value_t,
|
| typename _Container_traits<_Cont_t>::generic_container_handle> _Mycont_it;
|
| typedef cli::array<_Value_t> _Myarray_t;
|
|
|
| typedef int size_type;
|
| typedef int difference_type;
|
| typedef _Value_t value_type;
|
| typedef value_type% reference;
|
| typedef value_type% const_reference;
|
|
|
| typedef _Mycont_it generic_container;
|
| typedef value_type generic_value;
|
|
|
| typedef typename _Dehandle<_Cont_t>::type container_type;
|
|
|
|
|
| stack_base()
|
| : c(gcnew container_type)
|
| {
|
| }
|
|
|
| stack_base% operator=(stack_base% _Right)
|
| {
|
| assign(_Right);
|
| return (*this);
|
| }
|
|
|
| operator _Mycont_it^()
|
| {
|
| return (this);
|
| }
|
|
|
|
|
| stack_base(container_type% _Cont)
|
| : c(gcnew container_type(_Cont))
|
| {
|
| }
|
|
|
|
|
| ~stack_base()
|
| {
|
| delete c;
|
| }
|
|
|
|
|
| property value_type top_item
|
| {
|
| virtual value_type get()
|
| {
|
| return (top());
|
| }
|
|
|
| virtual void set(value_type _Val)
|
| {
|
| top() = _Val;
|
| }
|
| };
|
|
|
| reference top()
|
| {
|
| return (((typename container_type::generic_container^)c)->back());
|
| }
|
|
|
| container_type^ get_container()
|
| {
|
| return (c);
|
| }
|
|
|
|
|
| virtual System::Object^ Clone()
|
| {
|
| return (gcnew stack_base(*c));
|
| }
|
|
|
| _Myarray_t^ to_array()
|
| {
|
| return (c->to_array());
|
| }
|
|
|
|
|
| size_type size()
|
| {
|
| return (c->size());
|
| }
|
|
|
| bool empty()
|
| {
|
| return (size() == 0);
|
| }
|
|
|
|
|
| void push(value_type _Val)
|
| {
|
| c->push_back(_Val);
|
| }
|
|
|
| void pop()
|
| {
|
| c->pop_back();
|
| }
|
|
|
| void assign(_Mytype_t% _Right)
|
| {
|
| *c = _Right.get_container();
|
| }
|
|
|
| _STLCLR_FIELD_ACCESS:
|
|
|
| container_type^ c;
|
|
|
| private:
|
| virtual reference top_virtual() sealed
|
| = _Mycont_it::top
|
| {
|
| return (top());
|
| }
|
|
|
| virtual typename _Container_traits<_Cont_t>::generic_container_handle
|
| get_container_virtual() sealed
|
| = _Mycont_it::get_container
|
| {
|
| return (get_container());
|
| }
|
|
|
|
|
| virtual size_type size_virtual() sealed
|
| = _Mycont_it::size
|
| {
|
| return (size());
|
| }
|
|
|
| virtual bool empty_virtual() sealed
|
| = _Mycont_it::empty
|
| {
|
| return (empty());
|
| }
|
|
|
|
|
| virtual void push_virtual(value_type _Val) sealed
|
| = _Mycont_it::push
|
| {
|
| push(_Val);
|
| }
|
|
|
| virtual void pop_virtual() sealed
|
| = _Mycont_it::pop
|
| {
|
| pop();
|
| }
|
|
|
| virtual void assign_virtual(_Mycont_it^ _Right) sealed
|
| = _Mycont_it::assign
|
| {
|
| assign(*(_Mytype_t^)_Right);
|
| }
|
| };
|
|
|
|
|
|
|
|
|
| template<typename _Value_t,
|
| typename _Cont_t,
|
| bool _Is_ref>
|
| ref class stack_select
|
| : public stack_base<_Value_t, _Cont_t^>
|
| {
|
| public:
|
|
|
| typedef stack_select<_Value_t, _Cont_t, _Is_ref> _Mytype_t;
|
| typedef stack_base<_Value_t, _Cont_t^> _Mybase_t;
|
|
|
| typedef typename _Mybase_t::container_type container_type;
|
|
|
| typedef _Value_t value_type;
|
| typedef value_type% reference;
|
| typedef value_type% const_reference;
|
|
|
|
|
| stack_select()
|
| {
|
| }
|
|
|
| stack_select% operator=(stack_select% _Right)
|
| {
|
| _Mybase_t::operator=(_Right);
|
| return (*this);
|
| }
|
|
|
|
|
| explicit stack_select(container_type% _Cont)
|
| : _Mybase_t(_Cont)
|
| {
|
| }
|
| };
|
|
|
|
|
|
|
|
|
| template<typename _Value_t,
|
| typename _Cont_t>
|
| ref class stack_select<_Value_t, _Cont_t, true>
|
| : public stack_base<_Value_t^, _Cont_t^>
|
| {
|
| public:
|
|
|
| typedef stack_select<_Value_t, _Cont_t, true> _Mytype_t;
|
| typedef stack_base<_Value_t^, _Cont_t^> _Mybase_t;
|
|
|
| typedef typename _Mybase_t::container_type container_type;
|
|
|
| typedef _Value_t value_type;
|
| typedef value_type% reference;
|
| typedef value_type% const_reference;
|
|
|
|
|
| stack_select()
|
| {
|
| }
|
|
|
| stack_select% operator=(stack_select% _Right)
|
| {
|
| _Mybase_t::operator=(_Right);
|
| return (*this);
|
| }
|
|
|
|
|
| explicit stack_select(container_type% _Cont)
|
| : _Mybase_t(_Cont)
|
| {
|
| }
|
|
|
|
|
| property value_type top_item
|
| {
|
| value_type get()
|
| {
|
| return (top());
|
| }
|
|
|
| void set(value_type _Val)
|
| {
|
| top() = _Val;
|
| }
|
| };
|
|
|
| reference top() new
|
| {
|
| return (this->c->back());
|
| }
|
|
|
|
|
| void push(value_type _Val)
|
| {
|
| this->c->push_back(_Val);
|
| }
|
| };
|
| }
|
|
|
|
|
|
|
|
|
| template<typename _Value_t,
|
| typename _Cont_t = cliext::deque<_Value_t> >
|
| ref class stack
|
| : public impl::stack_select<
|
| _Value_t,
|
| typename _Dehandle<_Cont_t>::type,
|
| __is_ref_class(typename _Dehandle<_Value_t>::type)
|
| && !is_handle<_Value_t>::value>
|
|
|
| {
|
| public:
|
|
|
| typedef stack<_Value_t, _Cont_t> _Mytype_t;
|
| typedef impl::stack_select<
|
| _Value_t,
|
| typename _Dehandle<_Cont_t>::type,
|
| __is_ref_class(typename _Dehandle<_Value_t>::type)
|
| && !is_handle<_Value_t>::value> _Mybase_t;
|
|
|
| typedef typename _Mybase_t::container_type container_type;
|
|
|
|
|
| stack()
|
| {
|
| }
|
|
|
| stack(stack% _Right)
|
| : _Mybase_t(*_Right.get_container())
|
| {
|
| }
|
|
|
| stack(stack^ _Right)
|
| : _Mybase_t(*_Right->get_container())
|
| {
|
| }
|
|
|
| stack% operator=(stack% _Right)
|
| {
|
| _Mybase_t::operator=(_Right);
|
| return (*this);
|
| }
|
|
|
| stack% operator=(stack^ _Right)
|
| {
|
| _Mybase_t::operator=(*_Right);
|
| return (*this);
|
| }
|
|
|
|
|
| explicit stack(container_type% _Cont)
|
| : _Mybase_t(_Cont)
|
| {
|
| }
|
|
|
|
|
| virtual System::Object^ Clone() override
|
| {
|
| return (gcnew _Mytype_t(*this));
|
| }
|
| };
|
|
|
|
|
|
|
|
|
| template<typename _Value_t,
|
| typename _Cont_t>
|
| bool operator==(stack<_Value_t, _Cont_t>% _Left,
|
| stack<_Value_t, _Cont_t>% _Right)
|
| {
|
| return (*_Left.get_container() == *_Right.get_container());
|
| }
|
|
|
| template<typename _Value_t,
|
| typename _Cont_t>
|
| bool operator!=(stack<_Value_t, _Cont_t>% _Left,
|
| stack<_Value_t, _Cont_t>% _Right)
|
| {
|
| return (!(_Left == _Right));
|
| }
|
|
|
| template<typename _Value_t,
|
| typename _Cont_t>
|
| bool operator<(stack<_Value_t, _Cont_t>% _Left,
|
| stack<_Value_t, _Cont_t>% _Right)
|
| {
|
| return (*_Left.get_container() < *_Right.get_container());
|
| }
|
|
|
| template<typename _Value_t,
|
| typename _Cont_t>
|
| bool operator>=(stack<_Value_t, _Cont_t>% _Left,
|
| stack<_Value_t, _Cont_t>% _Right)
|
| {
|
| return (!(_Left < _Right));
|
| }
|
|
|
| template<typename _Value_t,
|
| typename _Cont_t>
|
| bool operator>(stack<_Value_t, _Cont_t>% _Left,
|
| stack<_Value_t, _Cont_t>% _Right)
|
| {
|
| return (_Right < _Left);
|
| }
|
|
|
| template<typename _Value_t,
|
| typename _Cont_t>
|
| bool operator<=(stack<_Value_t, _Cont_t>% _Left,
|
| stack<_Value_t, _Cont_t>% _Right)
|
| {
|
| return (!(_Right < _Left));
|
| }
|
| }
|
| #endif
|
|
|