5 // Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_DETAIL_OP_QUEUE_HPP
12 #define BOOST_ASIO_DETAIL_OP_QUEUE_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/noncopyable.hpp>
20 #include <boost/asio/detail/push_options.hpp>
26 template <typename Operation>
32 template <typename Operation>
33 static Operation* next(Operation* o)
35 return static_cast<Operation*>(o->next_);
38 template <typename Operation1, typename Operation2>
39 static void next(Operation1*& o1, Operation2* o2)
44 template <typename Operation>
45 static void destroy(Operation* o)
50 template <typename Operation>
51 static Operation*& front(op_queue<Operation>& q)
56 template <typename Operation>
57 static Operation*& back(op_queue<Operation>& q)
63 template <typename Operation>
75 // Destructor destroys all operations.
78 while (Operation* op = front_)
81 op_queue_access::destroy(op);
85 // Get the operation at the front of the queue.
91 // Pop an operation from the front of the queue.
96 Operation* tmp = front_;
97 front_ = op_queue_access::next(front_);
100 op_queue_access::next(tmp, static_cast<Operation*>(0));
104 // Push an operation on to the back of the queue.
105 void push(Operation* h)
107 op_queue_access::next(h, static_cast<Operation*>(0));
110 op_queue_access::next(back_, h);
119 // Push all operations from another queue on to the back of the queue. The
120 // source queue may contain operations of a derived type.
121 template <typename OtherOperation>
122 void push(op_queue<OtherOperation>& q)
124 if (Operation* other_front = op_queue_access::front(q))
127 op_queue_access::next(back_, other_front);
129 front_ = other_front;
130 back_ = op_queue_access::back(q);
131 op_queue_access::front(q) = 0;
132 op_queue_access::back(q) = 0;
136 // Whether the queue is empty.
143 friend class op_queue_access;
145 // The front of the queue.
148 // The back of the queue.
152 } // namespace detail
156 #include <boost/asio/detail/pop_options.hpp>
158 #endif // BOOST_ASIO_DETAIL_OP_QUEUE_HPP