123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370 |
- #ifndef __TOOLS_DEQUE_CNC_HPP
- #define __TOOLS_DEQUE_CNC_HPP
- #include <ciso646>
- #include <vector>
- #include <deque>
- #include <boost/sort/common/spinlock.hpp>
- namespace boost
- {
- namespace sort
- {
- namespace common
- {
- template<typename T, typename Allocator = std::allocator<T> >
- class deque_cnc
- {
- public:
-
-
-
- typedef std::deque<T, Allocator> deque_t;
- typedef typename deque_t::size_type size_type;
- typedef typename deque_t::difference_type difference_type;
- typedef typename deque_t::value_type value_type;
- typedef typename deque_t::pointer pointer;
- typedef typename deque_t::const_pointer const_pointer;
- typedef typename deque_t::reference reference;
- typedef typename deque_t::const_reference const_reference;
- typedef typename deque_t::allocator_type allocator_type;
- protected:
-
-
-
- deque_t dq;
- mutable spinlock_t spl;
- public:
-
-
-
-
-
-
-
-
-
- explicit inline deque_cnc(void): dq() { };
-
-
-
-
-
- explicit inline deque_cnc(const Allocator &ALLC): dq(ALLC){ };
-
-
-
-
-
- virtual ~deque_cnc(void){ dq.clear(); };
-
-
-
-
-
- void clear(void)
- {
- std::lock_guard < spinlock_t > S(spl);
- dq.clear();
- };
-
-
-
-
-
-
-
- void swap(deque_cnc & A) noexcept
- {
- if (this == &A) return;
- std::lock_guard < spinlock_t > S(spl);
- dq.swap(A.dq);
- };
-
-
-
-
-
-
-
-
-
-
-
- size_type size(void) const noexcept
- {
- std::lock_guard < spinlock_t > S(spl);
- return dq.size();
- };
-
-
-
-
-
-
- size_type max_size(void) const noexcept
- {
- std::lock_guard < spinlock_t > S(spl);
- return (dq.max_size());
- };
-
-
-
-
-
-
-
-
-
-
-
- void shrink_to_fit()
- {
- std::lock_guard < spinlock_t > S(spl);
- dq.shrink_to_fit();
- };
-
-
-
-
-
-
- bool empty(void) const noexcept
- {
- std::lock_guard < spinlock_t > S(spl);
- return (dq.empty());
- };
-
-
-
-
-
-
- void push_back(const value_type & D)
- {
- std::lock_guard < spinlock_t > S(spl);
- dq.push_back(D);
- };
-
-
-
-
-
- template<class ... Args>
- void emplace_back(Args && ... args)
- {
- std::lock_guard < spinlock_t > S(spl);
- dq.emplace_back(std::forward <Args>(args) ...);
- };
-
-
-
-
-
-
-
- template<class Allocator2>
- deque_cnc & push_back(const std::deque<value_type, Allocator2> & D)
- {
- std::lock_guard < spinlock_t > S(spl);
- for (size_type i = 0; i < D.size(); ++i)
- dq.push_back(D[i]);
- return *this;
- };
-
-
-
-
-
-
-
- deque_cnc & push_back(std::deque<value_type, Allocator> && D)
- {
- std::lock_guard < spinlock_t > S(spl);
- for (size_type i = 0; i < D.size(); ++i)
- dq.emplace_back(std::move(D[i]));
- return *this;
- };
-
-
-
-
-
- void pop_back(void)
- {
- std::lock_guard < spinlock_t > S(spl);
- dq.pop_back();
- };
-
-
-
-
-
-
-
-
-
- bool pop_copy_back(value_type & P)
- {
- std::lock_guard < spinlock_t > S(spl);
- if (dq.size() == 0) return false;
- P = dq.back();
- dq.pop_back();
- return true;
- };
-
-
-
-
-
-
-
-
-
- bool pop_move_back(value_type & P)
- {
- std::lock_guard < spinlock_t > S(spl);
- if (dq.size() == 0) return false;
- P = std::move(dq.back());
- dq.pop_back();
- return true;
- };
-
-
-
-
-
- void push_front(const value_type & D)
- {
- std::lock_guard < spinlock_t > S(spl);
- dq.push_front(D);
- };
-
-
-
-
-
- template<class ... Args>
- void emplace_front(Args && ... args)
- {
- std::lock_guard < spinlock_t > S(spl);
- dq.emplace_front(std::forward <Args>(args) ...);
- };
-
-
-
-
-
-
-
- template<class Allocator2>
- deque_cnc & push_front(const std::deque<value_type, Allocator2> & V1)
- {
- std::lock_guard < spinlock_t > S(spl);
- for (size_type i = 0; i < V1.size(); ++i)
- dq.push_front(V1[i]);
- return *this;
- };
-
-
-
-
-
-
-
- deque_cnc & push_front(std::deque<value_type, Allocator> && V1)
- {
- std::lock_guard < spinlock_t > S(spl);
- for (size_type i = 0; i < V1.size(); ++i)
- dq.emplace_front(std::move(V1[i]));
- return *this;
- };
-
-
-
-
-
- void pop_front(void)
- {
- std::lock_guard < spinlock_t > S(spl);
- dq.pop_front();
- };
-
-
-
-
-
-
-
-
-
- bool pop_copy_front(value_type & P)
- {
- std::lock_guard < spinlock_t > S(spl);
- if (dq.size() == 0) return false;
- P = dq.front();
- dq.pop_front();
- return true;
- };
-
-
-
-
-
-
-
-
-
- bool pop_move_front(value_type & P)
- {
- std::lock_guard < spinlock_t > S(spl);
- if (dq.size() == 0) return false;
- P = std::move(dq.front());
- dq.pop_front();
- return true;
- };
- };
- };
- };
- };
- #endif
|