|
|
|
|
| #ifndef _CLI_QUEUE_
|
| #define _CLI_QUEUE_
|
| #include <cliext/algorithm>
|
| #include <cliext/deque>
|
| #include <cliext/functional>
|
| #include <cliext/iterator>
|
| #include <cliext/vector>
|
|
|
| namespace cliext {
|
| namespace impl {
|
|
|
|
|
|
|
| template<typename _Value_t,
|
| typename _Cont_t>
|
| ref class queue_base
|
| : public _STLCLR IQueue<_Value_t,
|
| typename _Container_traits<_Cont_t>::generic_container_handle>
|
| {
|
| public:
|
|
|
| typedef queue_base<_Value_t, _Cont_t> _Mytype_t;
|
| typedef _STLCLR IQueue<_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;
|
|
|
|
|
| queue_base()
|
| : c(gcnew container_type)
|
| {
|
| }
|
|
|
| queue_base% operator=(queue_base% _Right)
|
| {
|
| assign(_Right);
|
| return (*this);
|
| }
|
|
|
| operator _Mycont_it^()
|
| {
|
| return (this);
|
| }
|
|
|
|
|
| explicit queue_base(container_type% _Cont)
|
| : c(gcnew container_type(_Cont))
|
| {
|
| }
|
|
|
|
|
| ~queue_base()
|
| {
|
| delete c;
|
| }
|
|
|
|
|
| property value_type front_item
|
| {
|
| value_type get()
|
| {
|
| return (front());
|
| }
|
|
|
| void set(value_type _Val)
|
| {
|
| front() = _Val;
|
| }
|
| };
|
|
|
| property value_type back_item
|
| {
|
| value_type get()
|
| {
|
| return (back());
|
| }
|
|
|
| void set(value_type _Val)
|
| {
|
| back() = _Val;
|
| }
|
| };
|
|
|
| virtual reference front()
|
| {
|
| return (((typename container_type::generic_container^)c)->front());
|
| }
|
|
|
| virtual reference back()
|
| {
|
| return (((typename container_type::generic_container^)c)->back());
|
| }
|
|
|
| virtual container_type^ get_container()
|
| {
|
| return (c);
|
| }
|
|
|
|
|
| virtual System::Object^ Clone()
|
| {
|
| return (gcnew queue_base(*c));
|
| }
|
|
|
| _Myarray_t^ to_array()
|
| {
|
| return (c->to_array());
|
| }
|
|
|
|
|
| virtual size_type size()
|
| {
|
| return (c->size());
|
| }
|
|
|
| virtual bool empty()
|
| {
|
| return (size() == 0);
|
| }
|
|
|
|
|
| virtual void push(value_type _Val)
|
| {
|
| c->push_back(_Val);
|
| }
|
|
|
| virtual void pop()
|
| {
|
| c->pop_front();
|
| }
|
|
|
| virtual void assign(_Mytype_t% _Right)
|
| {
|
| *c = *_Right.get_container();
|
| }
|
|
|
| _STLCLR_FIELD_ACCESS:
|
|
|
| container_type^ c;
|
|
|
| private:
|
| virtual reference front_virtual() sealed
|
| = _Mycont_it::front
|
| {
|
| return (front());
|
| }
|
|
|
| virtual reference back_virtual() sealed
|
| = _Mycont_it::back
|
| {
|
| return (back());
|
| }
|
|
|
| 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 queue_select
|
| : public queue_base<_Value_t, _Cont_t^>
|
| {
|
| public:
|
|
|
| typedef queue_select<_Value_t, _Cont_t, _Is_ref> _Mytype_t;
|
| typedef queue_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;
|
|
|
|
|
| queue_select()
|
| {
|
| }
|
|
|
| queue_select% operator=(queue_select% _Right)
|
| {
|
| _Mybase_t::operator=(_Right);
|
| return (*this);
|
| }
|
|
|
|
|
| explicit queue_select(container_type% _Cont)
|
| : _Mybase_t(_Cont)
|
| {
|
| }
|
| };
|
|
|
|
|
|
|
|
|
| template<typename _Value_t,
|
| typename _Cont_t>
|
| ref class queue_select<_Value_t, _Cont_t, true>
|
| : public queue_base<_Value_t^, _Cont_t^>
|
| {
|
| public:
|
|
|
| typedef queue_select<_Value_t, _Cont_t, true> _Mytype_t;
|
| typedef queue_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;
|
|
|
|
|
| queue_select()
|
| {
|
| }
|
|
|
| queue_select% operator=(queue_select% _Right)
|
| {
|
| _Mybase_t::operator=(_Right);
|
| return (*this);
|
| }
|
|
|
|
|
| explicit queue_select(container_type% _Cont)
|
| : _Mybase_t(_Cont)
|
| {
|
| }
|
|
|
|
|
| property value_type front_item
|
| {
|
| value_type get()
|
| {
|
| return (front());
|
| }
|
|
|
| void set(value_type _Val)
|
| {
|
| front() = _Val;
|
| }
|
| };
|
|
|
| property value_type back_item
|
| {
|
| value_type get()
|
| {
|
| return (back());
|
| }
|
|
|
| void set(value_type _Val)
|
| {
|
| back() = _Val;
|
| }
|
| };
|
|
|
| virtual reference front() new
|
| {
|
| return (this->c->front());
|
| }
|
|
|
| virtual reference back() 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 queue
|
| : public impl::queue_select<
|
| _Value_t,
|
| typename _Dehandle<_Cont_t>::type,
|
| __is_ref_class(typename _Dehandle<_Value_t>::type)
|
| && !is_handle<_Value_t>::value>
|
| {
|
| public:
|
|
|
| typedef queue<_Value_t, _Cont_t> _Mytype_t;
|
| typedef impl::queue_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;
|
|
|
|
|
| queue()
|
| {
|
| }
|
|
|
| queue(queue% _Right)
|
| : _Mybase_t(*_Right.get_container())
|
| {
|
| }
|
|
|
| queue(queue^ _Right)
|
| : _Mybase_t(*_Right->get_container())
|
| {
|
| }
|
|
|
| queue% operator=(queue% _Right)
|
| {
|
| _Mybase_t::operator=(_Right);
|
| return (*this);
|
| }
|
|
|
| queue% operator=(queue^ _Right)
|
| {
|
| _Mybase_t::operator=(*_Right);
|
| return (*this);
|
| }
|
|
|
|
|
| explicit queue(container_type% _Cont)
|
| : _Mybase_t(_Cont)
|
| {
|
| }
|
|
|
|
|
| virtual System::Object^ Clone() override
|
| {
|
| return (gcnew _Mytype_t(*this));
|
| }
|
| };
|
|
|
|
|
|
|
|
|
| template<typename _Value_t,
|
| typename _Cont_t> inline
|
| bool operator==(queue<_Value_t, _Cont_t>% _Left,
|
| queue<_Value_t, _Cont_t>% _Right)
|
| {
|
| return (*_Left.get_container() == *_Right.get_container());
|
| }
|
|
|
| template<typename _Value_t,
|
| typename _Cont_t> inline
|
| bool operator!=(queue<_Value_t, _Cont_t>% _Left,
|
| queue<_Value_t, _Cont_t>% _Right)
|
| {
|
| return (!(_Left == _Right));
|
| }
|
|
|
| template<typename _Value_t,
|
| typename _Cont_t> inline
|
| bool operator<(queue<_Value_t, _Cont_t>% _Left,
|
| queue<_Value_t, _Cont_t>% _Right)
|
| {
|
| return (*_Left.get_container() < *_Right.get_container());
|
| }
|
|
|
| template<typename _Value_t,
|
| typename _Cont_t> inline
|
| bool operator>=(queue<_Value_t, _Cont_t>% _Left,
|
| queue<_Value_t, _Cont_t>% _Right)
|
| {
|
| return (!(_Left < _Right));
|
| }
|
|
|
| template<typename _Value_t,
|
| typename _Cont_t> inline
|
| bool operator>(queue<_Value_t, _Cont_t>% _Left,
|
| queue<_Value_t, _Cont_t>% _Right)
|
| {
|
| return (_Right < _Left);
|
| }
|
|
|
| template<typename _Value_t,
|
| typename _Cont_t> inline
|
| bool operator<=(queue<_Value_t, _Cont_t>% _Left,
|
| queue<_Value_t, _Cont_t>% _Right)
|
| {
|
| return (!(_Right < _Left));
|
| }
|
|
|
|
|
|
|
|
|
| template<typename _Key_t> inline
|
| bool _Queue_compare(_Key_t _Left, _Key_t _Right)
|
| {
|
| return (_Left < _Right);
|
| }
|
|
|
| inline bool _Queue_compare(System::String^ _Left, System::String^ _Right)
|
| {
|
| return (_Left->CompareTo(_Right) < 0);
|
| }
|
|
|
| namespace impl {
|
|
|
|
|
|
|
| template<typename _Value_t,
|
| typename _Cont_t>
|
| ref class priority_queue_base
|
| : public _STLCLR IPriorityQueue<_Value_t,
|
| typename _Container_traits<_Cont_t>::generic_container_handle>
|
| {
|
| public:
|
|
|
| typedef priority_queue_base<_Value_t, _Cont_t> _Mytype_t;
|
| typedef _STLCLR IPriorityQueue<_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;
|
| typedef _STLCLR BinaryDelegate<_Value_t, _Value_t, bool>
|
| value_compare;
|
|
|
|
|
| priority_queue_base()
|
| : comp(gcnew value_compare(&_Queue_compare)),
|
| c(gcnew container_type)
|
| {
|
| }
|
|
|
| priority_queue_base% operator=(priority_queue_base% _Right)
|
| {
|
| assign(_Right);
|
| return (*this);
|
| }
|
|
|
| operator _Mycont_it^()
|
| {
|
| return (this);
|
| }
|
|
|
|
|
| explicit priority_queue_base(value_compare^ _Pred)
|
| : comp(_Pred),
|
| c(gcnew container_type)
|
| {
|
| }
|
|
|
| priority_queue_base(value_compare^ _Pred, container_type% _Cont)
|
| : comp(_Pred),
|
| c(gcnew container_type(_Cont))
|
| {
|
| }
|
|
|
|
|
| ~priority_queue_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)->front());
|
| }
|
|
|
| container_type^ get_container()
|
| {
|
| return (c);
|
| }
|
|
|
| value_compare^ value_comp()
|
| {
|
| return (comp);
|
| }
|
|
|
|
|
| virtual System::Object^ Clone()
|
| {
|
| return (gcnew priority_queue_base(comp, *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);
|
| cliext::push_heap(c->begin(), c->end(), comp);
|
| }
|
|
|
| void pop()
|
| {
|
| cliext::pop_heap(c->begin(), c->end(), comp);
|
| c->pop_back();
|
| }
|
|
|
| void assign(_Mytype_t% _Right)
|
| {
|
| *c = *_Right.get_container();
|
| }
|
|
|
| _STLCLR_FIELD_ACCESS:
|
|
|
| value_compare^ comp;
|
| 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 value_compare^ value_comp_virtual() sealed
|
| = _Mycont_it::value_comp
|
| {
|
| return (value_comp());
|
| }
|
|
|
|
|
| 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 priority_queue_select
|
| : public priority_queue_base<_Value_t, _Cont_t^>
|
| {
|
| public:
|
|
|
| typedef priority_queue_select<_Value_t, _Cont_t, _Is_ref> _Mytype_t;
|
| typedef priority_queue_base<_Value_t, _Cont_t^> _Mybase_t;
|
|
|
| typedef typename _Mybase_t::container_type container_type;
|
| typedef typename _Mybase_t::value_compare value_compare;
|
|
|
| typedef _Value_t value_type;
|
| typedef value_type% reference;
|
| typedef value_type% const_reference;
|
|
|
|
|
| priority_queue_select()
|
| {
|
| }
|
|
|
| priority_queue_select% operator=(priority_queue_select% _Right)
|
| {
|
| _Mybase_t::operator=(_Right);
|
| return (*this);
|
| }
|
|
|
|
|
| priority_queue_select(value_compare^ _Pred)
|
| : _Mybase_t(_Pred)
|
| {
|
| }
|
|
|
| priority_queue_select(value_compare^ _Pred, container_type% _Cont)
|
| : _Mybase_t(_Pred, _Cont)
|
| {
|
| }
|
| };
|
|
|
|
|
|
|
|
|
| template<typename _Value_t,
|
| typename _Cont_t>
|
| ref class priority_queue_select<_Value_t, _Cont_t, true>
|
| : public priority_queue_base<_Value_t^, _Cont_t^>
|
| {
|
| public:
|
|
|
| typedef priority_queue_select<_Value_t, _Cont_t, true> _Mytype_t;
|
| typedef priority_queue_base<_Value_t^, _Cont_t^> _Mybase_t;
|
|
|
| typedef typename _Mybase_t::container_type container_type;
|
| typedef typename _Mybase_t::value_compare value_compare;
|
|
|
| typedef _Value_t value_type;
|
| typedef value_type% reference;
|
| typedef value_type% const_reference;
|
|
|
|
|
| priority_queue_select()
|
| {
|
| }
|
|
|
| priority_queue_select% operator=(priority_queue_select% _Right)
|
| {
|
| _Mybase_t::operator=(_Right);
|
| return (*this);
|
| }
|
|
|
|
|
| priority_queue_select(value_compare^ _Pred)
|
| : _Mybase_t(_Pred)
|
| {
|
| }
|
|
|
| priority_queue_select(value_compare^ _Pred, container_type% _Cont)
|
| : _Mybase_t(_Pred, _Cont)
|
| {
|
| }
|
|
|
|
|
| property value_type top_item
|
| {
|
| value_type get()
|
| {
|
| return (top());
|
| }
|
|
|
| void set(value_type _Val)
|
| {
|
| top() = _Val;
|
| }
|
| };
|
|
|
| virtual reference top() new
|
| {
|
| return (this->c->front());
|
| }
|
|
|
|
|
| void push(value_type _Val)
|
| {
|
| this->c->push_back(_Val);
|
| cliext::push_heap(this->c->begin(), this->c->end(), this->comp);
|
| }
|
| };
|
| }
|
|
|
|
|
|
|
|
|
| template<typename _Value_t,
|
| typename _Cont_t = cliext::vector<_Value_t> >
|
| ref class priority_queue
|
| : public impl::priority_queue_select<
|
| _Value_t,
|
| typename _Dehandle<_Cont_t>::type,
|
| __is_ref_class(typename _Dehandle<_Value_t>::type)
|
| && !is_handle<_Value_t>::value>
|
| {
|
| public:
|
|
|
| typedef priority_queue<_Value_t, _Cont_t> _Mytype_t;
|
| typedef impl::priority_queue_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;
|
| typedef typename _Mybase_t::value_compare value_compare;
|
|
|
|
|
| priority_queue()
|
| {
|
| }
|
|
|
| priority_queue(priority_queue% _Right)
|
| : _Mybase_t(_Right.value_comp(), *_Right.get_container())
|
| {
|
| }
|
|
|
| priority_queue(priority_queue^ _Right)
|
| : _Mybase_t(_Right->value_comp(), *_Right->get_container())
|
| {
|
| }
|
|
|
| priority_queue% operator=(priority_queue% _Right)
|
| {
|
| _Mybase_t::operator=(_Right);
|
| return (*this);
|
| }
|
|
|
| priority_queue% operator=(priority_queue^ _Right)
|
| {
|
| _Mybase_t::operator=(*_Right);
|
| return (*this);
|
| }
|
|
|
|
|
| explicit priority_queue(value_compare^ _Pred)
|
| : _Mybase_t(_Pred)
|
| {
|
| }
|
|
|
| priority_queue(value_compare^ _Pred, container_type% _Cont)
|
| : _Mybase_t(_Pred, _Cont)
|
| {
|
| cliext::make_heap(this->c->begin(), this->c->end(), this->comp);
|
| }
|
|
|
| template<typename _Iter>
|
| priority_queue(_Iter _First, _Iter _Last)
|
| {
|
| this->c->insert(this->c->end(), _First, _Last);
|
| cliext::make_heap(this->c->begin(), this->c->end(), this->comp);
|
| }
|
|
|
| template<typename _Iter>
|
| priority_queue(_Iter _First, _Iter _Last, value_compare^ _Pred)
|
| : _Mybase_t(_Pred)
|
| {
|
| this->c->insert(this->c->end(), _First, _Last);
|
| cliext::make_heap(this->c->begin(), this->c->end(), this->comp);
|
| }
|
|
|
| template<typename _Iter>
|
| priority_queue(_Iter _First, _Iter _Last, value_compare^ _Pred,
|
| container_type% _Cont)
|
| : _Mybase_t(_Pred, _Cont)
|
| {
|
| this->c->insert(this->c->end(), _First, _Last);
|
| cliext::make_heap(this->c->begin(), this->c->end(), this->comp);
|
| }
|
|
|
|
|
| virtual System::Object^ Clone() override
|
| {
|
| return (gcnew _Mytype_t(*this));
|
| }
|
| };
|
| }
|
| #endif
|
|
|