deque_adaptor.hpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #ifndef BOOST_THREAD_CONCURRENT_DEQUE_ADAPTOR_HPP
  2. #define BOOST_THREAD_CONCURRENT_DEQUE_ADAPTOR_HPP
  3. //////////////////////////////////////////////////////////////////////////////
  4. //
  5. // (C) Copyright Vicente J. Botet Escriba 2014. Distributed under the Boost
  6. // Software License, Version 1.0. (See accompanying file
  7. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/thread for documentation.
  10. //
  11. //////////////////////////////////////////////////////////////////////////////
  12. #include <boost/thread/detail/config.hpp>
  13. #include <boost/thread/detail/move.hpp>
  14. #include <boost/thread/concurrent_queues/queue_op_status.hpp>
  15. #include <boost/thread/concurrent_queues/deque_base.hpp>
  16. #include <boost/config/abi_prefix.hpp>
  17. namespace boost
  18. {
  19. namespace concurrent
  20. {
  21. namespace detail
  22. {
  23. template <typename Queue>
  24. class deque_adaptor_copyable_only :
  25. public boost::deque_base<typename Queue::value_type, typename Queue::size_type>
  26. {
  27. Queue queue;
  28. public:
  29. typedef typename Queue::value_type value_type;
  30. typedef typename Queue::size_type size_type;
  31. // Constructors/Assignment/Destructors
  32. deque_adaptor_copyable_only() {}
  33. // Observers
  34. bool empty() const { return queue.empty(); }
  35. bool full() const { return queue.full(); }
  36. size_type size() const { return queue.size(); }
  37. bool closed() const { return queue.closed(); }
  38. // Modifiers
  39. void close() { queue.close(); }
  40. void push_back(const value_type& x) { queue.push_back(x); }
  41. void pull_front(value_type& x) { queue.pull_front(x); };
  42. value_type pull_front() { return queue.pull_front(); }
  43. queue_op_status try_push_back(const value_type& x) { return queue.try_push_back(x); }
  44. queue_op_status try_pull_front(value_type& x) { return queue.try_pull_front(x); }
  45. queue_op_status nonblocking_push_back(const value_type& x) { return queue.nonblocking_push_back(x); }
  46. queue_op_status nonblocking_pull_front(value_type& x) { return queue.nonblocking_pull_front(x); }
  47. queue_op_status wait_push_back(const value_type& x) { return queue.wait_push_back(x); }
  48. queue_op_status wait_pull_front(value_type& x) { return queue.wait_pull_front(x); }
  49. };
  50. template <typename Queue>
  51. class deque_adaptor_movable_only :
  52. public boost::deque_base<typename Queue::value_type, typename Queue::size_type>
  53. {
  54. Queue queue;
  55. public:
  56. typedef typename Queue::value_type value_type;
  57. typedef typename Queue::size_type size_type;
  58. // Constructors/Assignment/Destructors
  59. deque_adaptor_movable_only() {}
  60. // Observers
  61. bool empty() const { return queue.empty(); }
  62. bool full() const { return queue.full(); }
  63. size_type size() const { return queue.size(); }
  64. bool closed() const { return queue.closed(); }
  65. // Modifiers
  66. void close() { queue.close(); }
  67. void pull_front(value_type& x) { queue.pull_front(x); };
  68. // enable_if is_nothrow_copy_movable<value_type>
  69. value_type pull_front() { return queue.pull_front(); }
  70. queue_op_status try_pull_front(value_type& x) { return queue.try_pull_front(x); }
  71. queue_op_status nonblocking_pull_front(value_type& x) { return queue.nonblocking_pull_front(x); }
  72. queue_op_status wait_pull_front(value_type& x) { return queue.wait_pull_front(x); }
  73. void push_back(BOOST_THREAD_RV_REF(value_type) x) { queue.push_back(boost::move(x)); }
  74. queue_op_status try_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.try_push_back(boost::move(x)); }
  75. queue_op_status nonblocking_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.nonblocking_push_back(boost::move(x)); }
  76. queue_op_status wait_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.wait_push_back(boost::move(x)); }
  77. };
  78. template <typename Queue>
  79. class deque_adaptor_copyable_and_movable :
  80. public boost::deque_base<typename Queue::value_type, typename Queue::size_type>
  81. {
  82. Queue queue;
  83. public:
  84. typedef typename Queue::value_type value_type;
  85. typedef typename Queue::size_type size_type;
  86. // Constructors/Assignment/Destructors
  87. deque_adaptor_copyable_and_movable() {}
  88. // Observers
  89. bool empty() const { return queue.empty(); }
  90. bool full() const { return queue.full(); }
  91. size_type size() const { return queue.size(); }
  92. bool closed() const { return queue.closed(); }
  93. // Modifiers
  94. void close() { queue.close(); }
  95. void push_back(const value_type& x) { queue.push_back(x); }
  96. void pull_front(value_type& x) { queue.pull_front(x); };
  97. // enable_if is_nothrow_copy_movable<value_type>
  98. value_type pull_front() { return queue.pull_front(); }
  99. queue_op_status try_push_back(const value_type& x) { return queue.try_push_back(x); }
  100. queue_op_status try_pull_front(value_type& x) { return queue.try_pull_front(x); }
  101. queue_op_status nonblocking_push_back(const value_type& x) { return queue.nonblocking_push_back(x); }
  102. queue_op_status nonblocking_pull_front(value_type& x) { return queue.nonblocking_pull_front(x); }
  103. queue_op_status wait_push_back(const value_type& x) { return queue.wait_push_back(x); }
  104. queue_op_status wait_pull_front(value_type& x) { return queue.wait_pull_front(x); }
  105. void push_back(BOOST_THREAD_RV_REF(value_type) x) { queue.push_back(boost::move(x)); }
  106. queue_op_status try_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.try_push_back(boost::move(x)); }
  107. queue_op_status nonblocking_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.nonblocking_push_back(boost::move(x)); }
  108. queue_op_status wait_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.wait_push_back(boost::move(x)); }
  109. };
  110. template <class Q, class T,
  111. #if ! defined BOOST_NO_CXX11_RVALUE_REFERENCES
  112. #if defined __GNUC__ && ! defined __clang__
  113. #if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7) || !defined(__GXX_EXPERIMENTAL_CXX0X__)
  114. bool Copyable = is_copy_constructible<T>::value,
  115. bool Movable = true
  116. #else
  117. bool Copyable = std::is_copy_constructible<T>::value && std::is_copy_assignable<T>::value,
  118. bool Movable = std::is_move_constructible<T>::value && std::is_move_assignable<T>::value
  119. #endif // __GNUC__
  120. #elif defined _MSC_VER
  121. #if _MSC_VER < 1700
  122. bool Copyable = is_copy_constructible<T>::value,
  123. bool Movable = true
  124. #else
  125. bool Copyable = std::is_copy_constructible<T>::value && std::is_copy_assignable<T>::value,
  126. bool Movable = std::is_move_constructible<T>::value && std::is_move_assignable<T>::value
  127. #endif // _MSC_VER
  128. #else
  129. bool Copyable = std::is_copy_constructible<T>::value && std::is_copy_assignable<T>::value,
  130. bool Movable = std::is_move_constructible<T>::value && std::is_move_assignable<T>::value
  131. #endif
  132. #else
  133. bool Copyable = is_copy_constructible<T>::value,
  134. bool Movable = has_move_emulation_enabled<T>::value
  135. #endif
  136. >
  137. struct deque_adaptor;
  138. template <class Q, class T>
  139. struct deque_adaptor<Q, T, true, true> {
  140. typedef deque_adaptor_copyable_and_movable<Q> type;
  141. };
  142. template <class Q, class T>
  143. struct deque_adaptor<Q, T, true, false> {
  144. typedef deque_adaptor_copyable_only<Q> type;
  145. };
  146. template <class Q, class T>
  147. struct deque_adaptor<Q, T, false, true> {
  148. typedef deque_adaptor_movable_only<Q> type;
  149. };
  150. }
  151. template <typename Queue>
  152. class deque_adaptor :
  153. public detail::deque_adaptor<Queue, typename Queue::value_type>::type
  154. {
  155. public:
  156. typedef typename Queue::value_type value_type;
  157. typedef typename Queue::size_type size_type;
  158. // Constructors/Assignment/Destructors
  159. virtual ~deque_adaptor() {};
  160. };
  161. }
  162. using concurrent::deque_adaptor;
  163. }
  164. #include <boost/config/abi_suffix.hpp>
  165. #endif