File indexing completed on 2025-01-30 10:01:07
0001 #ifndef BOOST_THREAD_QUEUE_ADAPTOR_HPP
0002 #define BOOST_THREAD_QUEUE_ADAPTOR_HPP
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <boost/thread/detail/config.hpp>
0015 #include <boost/thread/detail/move.hpp>
0016 #include <boost/thread/concurrent_queues/queue_op_status.hpp>
0017 #include <boost/thread/concurrent_queues/queue_base.hpp>
0018
0019 #include <boost/config/abi_prefix.hpp>
0020
0021 namespace boost
0022 {
0023 namespace concurrent
0024 {
0025 namespace detail
0026 {
0027
0028 template <typename Queue>
0029 class queue_adaptor_copyable_only :
0030 public boost::queue_base<typename Queue::value_type, typename Queue::size_type>
0031 {
0032 Queue queue;
0033 public:
0034 typedef typename Queue::value_type value_type;
0035 typedef typename Queue::size_type size_type;
0036
0037
0038 queue_adaptor_copyable_only() {}
0039
0040
0041 bool empty() const { return queue.empty(); }
0042 bool full() const { return queue.full(); }
0043 size_type size() const { return queue.size(); }
0044 bool closed() const { return queue.closed(); }
0045
0046
0047 void close() { queue.close(); }
0048
0049 void push(const value_type& x) { queue.push(x); }
0050
0051 void pull(value_type& x) { queue.pull(x); };
0052 value_type pull() { return queue.pull(); }
0053
0054 queue_op_status try_push(const value_type& x) { return queue.try_push(x); }
0055 queue_op_status try_pull(value_type& x) { return queue.try_pull(x); }
0056
0057 queue_op_status nonblocking_push(const value_type& x) { return queue.nonblocking_push(x); }
0058 queue_op_status nonblocking_pull(value_type& x) { return queue.nonblocking_pull(x); }
0059
0060 queue_op_status wait_push(const value_type& x) { return queue.wait_push(x); }
0061 queue_op_status wait_pull(value_type& x) { return queue.wait_pull(x); }
0062
0063 };
0064 template <typename Queue>
0065 class queue_adaptor_movable_only :
0066 public boost::queue_base<typename Queue::value_type, typename Queue::size_type>
0067 {
0068 Queue queue;
0069 public:
0070 typedef typename Queue::value_type value_type;
0071 typedef typename Queue::size_type size_type;
0072
0073
0074
0075 queue_adaptor_movable_only() {}
0076
0077
0078 bool empty() const { return queue.empty(); }
0079 bool full() const { return queue.full(); }
0080 size_type size() const { return queue.size(); }
0081 bool closed() const { return queue.closed(); }
0082
0083
0084 void close() { queue.close(); }
0085
0086
0087 void pull(value_type& x) { queue.pull(x); };
0088
0089 value_type pull() { return queue.pull(); }
0090
0091 queue_op_status try_pull(value_type& x) { return queue.try_pull(x); }
0092
0093 queue_op_status nonblocking_pull(value_type& x) { return queue.nonblocking_pull(x); }
0094
0095 queue_op_status wait_pull(value_type& x) { return queue.wait_pull(x); }
0096
0097 void push(BOOST_THREAD_RV_REF(value_type) x) { queue.push(boost::move(x)); }
0098 queue_op_status try_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.try_push(boost::move(x)); }
0099 queue_op_status nonblocking_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.nonblocking_push(boost::move(x)); }
0100 queue_op_status wait_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.wait_push(boost::move(x)); }
0101 };
0102
0103 template <typename Queue>
0104 class queue_adaptor_copyable_and_movable :
0105 public boost::queue_base<typename Queue::value_type, typename Queue::size_type>
0106 {
0107 Queue queue;
0108 public:
0109 typedef typename Queue::value_type value_type;
0110 typedef typename Queue::size_type size_type;
0111
0112
0113
0114 queue_adaptor_copyable_and_movable() {}
0115
0116
0117 bool empty() const { return queue.empty(); }
0118 bool full() const { return queue.full(); }
0119 size_type size() const { return queue.size(); }
0120 bool closed() const { return queue.closed(); }
0121
0122
0123 void close() { queue.close(); }
0124
0125
0126 void push(const value_type& x) { queue.push(x); }
0127
0128 void pull(value_type& x) { queue.pull(x); };
0129
0130 value_type pull() { return queue.pull(); }
0131
0132 queue_op_status try_push(const value_type& x) { return queue.try_push(x); }
0133 queue_op_status try_pull(value_type& x) { return queue.try_pull(x); }
0134
0135 queue_op_status nonblocking_push(const value_type& x) { return queue.nonblocking_push(x); }
0136 queue_op_status nonblocking_pull(value_type& x) { return queue.nonblocking_pull(x); }
0137
0138 queue_op_status wait_push(const value_type& x) { return queue.wait_push(x); }
0139 queue_op_status wait_pull(value_type& x) { return queue.wait_pull(x); }
0140
0141 void push(BOOST_THREAD_RV_REF(value_type) x) { queue.push(boost::move(x)); }
0142 queue_op_status try_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.try_push(boost::move(x)); }
0143 queue_op_status nonblocking_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.nonblocking_push(boost::move(x)); }
0144 queue_op_status wait_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.wait_push(boost::move(x)); }
0145 };
0146
0147
0148 template <class Q, class T,
0149 #if ! defined BOOST_NO_CXX11_RVALUE_REFERENCES
0150 #if defined __GNUC__ && ! defined __clang__
0151 #if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7) || !defined(__GXX_EXPERIMENTAL_CXX0X__)
0152 bool Copyable = is_copy_constructible<T>::value,
0153 bool Movable = true
0154 #else
0155 bool Copyable = std::is_copy_constructible<T>::value && std::is_copy_assignable<T>::value,
0156 bool Movable = std::is_move_constructible<T>::value && std::is_move_assignable<T>::value
0157 #endif
0158 #elif defined _MSC_VER
0159 #if _MSC_VER < 1700
0160 bool Copyable = is_copy_constructible<T>::value,
0161 bool Movable = true
0162 #else
0163 bool Copyable = std::is_copy_constructible<T>::value && std::is_copy_assignable<T>::value,
0164 bool Movable = std::is_move_constructible<T>::value && std::is_move_assignable<T>::value
0165 #endif
0166 #else
0167 bool Copyable = std::is_copy_constructible<T>::value && std::is_copy_assignable<T>::value,
0168 bool Movable = std::is_move_constructible<T>::value && std::is_move_assignable<T>::value
0169 #endif
0170 #else
0171 bool Copyable = is_copy_constructible<T>::value,
0172 bool Movable = has_move_emulation_enabled<T>::value
0173 #endif
0174 >
0175 struct queue_adaptor;
0176
0177 template <class Q, class T>
0178 struct queue_adaptor<Q, T, true, true> {
0179 typedef queue_adaptor_copyable_and_movable<Q> type;
0180 };
0181 template <class Q, class T>
0182 struct queue_adaptor<Q, T, true, false> {
0183 typedef queue_adaptor_copyable_only<Q> type;
0184 };
0185 template <class Q, class T>
0186 struct queue_adaptor<Q, T, false, true> {
0187 typedef queue_adaptor_movable_only<Q> type;
0188 };
0189
0190 }
0191
0192 template <typename Queue>
0193 class queue_adaptor :
0194 public detail::queue_adaptor<Queue, typename Queue::value_type>::type
0195 {
0196 public:
0197 typedef typename Queue::value_type value_type;
0198 typedef typename Queue::size_type size_type;
0199
0200 virtual ~queue_adaptor() {};
0201 };
0202 }
0203 using concurrent::queue_adaptor;
0204
0205 }
0206
0207 #include <boost/config/abi_suffix.hpp>
0208
0209 #endif