deque_views.hpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #ifndef BOOST_THREAD_QUEUE_VIEWS_HPP
  2. #define BOOST_THREAD_QUEUE_VIEWS_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. template <typename Queue>
  22. class deque_back_view
  23. {
  24. Queue* queue;
  25. public:
  26. typedef typename Queue::value_type value_type;
  27. typedef typename Queue::size_type size_type;
  28. // Constructors/Assignment/Destructors
  29. deque_back_view(Queue& q) BOOST_NOEXCEPT : queue(&q) {}
  30. // Observers
  31. bool empty() const { return queue->empty(); }
  32. bool full() const { return queue->full(); }
  33. size_type size() const { return queue->size(); }
  34. bool closed() const { return queue->closed(); }
  35. // Modifiers
  36. void close() { queue->close(); }
  37. void push(const value_type& x) { queue->push_back(x); }
  38. void pull(value_type& x) { queue->pull_back(x); }
  39. // enable_if is_nothrow_copy_movable<value_type>
  40. value_type pull() { return queue->pull_back(); }
  41. queue_op_status try_push(const value_type& x) { return queue->try_push_back(x); }
  42. queue_op_status try_pull(value_type& x) { return queue->try_pull_back(x); }
  43. queue_op_status nonblocking_push(const value_type& x) { return queue->nonblocking_push_back(x); }
  44. queue_op_status nonblocking_pull(value_type& x) { return queue->nonblocking_pull_back(x); }
  45. queue_op_status wait_push(const value_type& x) { return queue->wait_push_back(x); }
  46. queue_op_status wait_pull(value_type& x) { return queue->wait_pull_back(x); }
  47. void push(BOOST_THREAD_RV_REF(value_type) x) { queue->push_back(boost::move(x)); }
  48. queue_op_status try_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->try_push_back(boost::move(x)); }
  49. queue_op_status nonblocking_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->nonblocking_push_back(boost::move(x)); }
  50. queue_op_status wait_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->wait_push_back(boost::move(x)); }
  51. };
  52. template <typename Queue>
  53. class deque_front_view
  54. {
  55. Queue* queue;
  56. public:
  57. typedef typename Queue::value_type value_type;
  58. typedef typename Queue::size_type size_type;
  59. // Constructors/Assignment/Destructors
  60. deque_front_view(Queue& q) BOOST_NOEXCEPT : queue(&q) {}
  61. // Observers
  62. bool empty() const { return queue->empty(); }
  63. bool full() const { return queue->full(); }
  64. size_type size() const { return queue->size(); }
  65. bool closed() const { return queue->closed(); }
  66. // Modifiers
  67. void close() { queue->close(); }
  68. void push(const value_type& x) { queue->push_front(x); }
  69. void pull(value_type& x) { queue->pull_front(x); };
  70. // enable_if is_nothrow_copy_movable<value_type>
  71. value_type pull() { return queue->pull_front(); }
  72. queue_op_status try_push(const value_type& x) { return queue->try_push_front(x); }
  73. queue_op_status try_pull(value_type& x) { return queue->try_pull_front(x); }
  74. queue_op_status nonblocking_push(const value_type& x) { return queue->nonblocking_push_front(x); }
  75. queue_op_status nonblocking_pull(value_type& x) { return queue->nonblocking_pull_front(x); }
  76. queue_op_status wait_push(const value_type& x) { return queue->wait_push_front(x); }
  77. queue_op_status wait_pull(value_type& x) { return queue->wait_pull_front(x); }
  78. void push(BOOST_THREAD_RV_REF(value_type) x) { queue->push_front(forward<value_type>(x)); }
  79. queue_op_status try_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->try_push_front(forward<value_type>(x)); }
  80. queue_op_status nonblocking_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->nonblocking_push_front(forward<value_type>(x)); }
  81. queue_op_status wait_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->wait_push_front(forward<value_type>(x)); }
  82. };
  83. #if ! defined BOOST_NO_CXX11_TEMPLATE_ALIASES
  84. template <class T>
  85. using deque_back = deque_back_view<deque_base<T> > ;
  86. template <class T>
  87. using deque_front = deque_front_view<deque_base<T> > ;
  88. #else
  89. template <class T>
  90. struct deque_back : deque_back_view<deque_base<T> >
  91. {
  92. typedef deque_back_view<deque_base<T> > base_type;
  93. deque_back(deque_base<T>& q) BOOST_NOEXCEPT : base_type(q) {}
  94. };
  95. template <class T>
  96. struct deque_front : deque_front_view<deque_base<T> >
  97. {
  98. typedef deque_front_view<deque_base<T> > base_type;
  99. deque_front(deque_base<T>& q) BOOST_NOEXCEPT : base_type(q) {}
  100. };
  101. #endif
  102. // template <class Queue>
  103. // deque_back_view<Queue> back(Queue & q) { return deque_back_view<Queue>(q); }
  104. // template <class Queue>
  105. // deque_front_view<Queue> front(Queue & q) { return deque_front_view<Queue>(q); }
  106. //#if 0
  107. // template <class T>
  108. // deque_back<T> back(deque_base<T> & q) { return deque_back<T>(q); }
  109. // template <class T>
  110. // deque_front<T> front(deque_base<T> & q) { return deque_front<T>(q); }
  111. //#else
  112. // template <class T>
  113. // typename deque_back<T>::type back(deque_base<T> & q) { return typename deque_back<T>::type(q); }
  114. // template <class T>
  115. // typename deque_front<T>::type front(deque_base<T> & q) { return typename deque_front<T>::type(q); }
  116. //#endif
  117. }
  118. using concurrent::deque_back_view;
  119. using concurrent::deque_front_view;
  120. using concurrent::deque_back;
  121. using concurrent::deque_front;
  122. //using concurrent::back;
  123. //using concurrent::front;
  124. }
  125. #include <boost/config/abi_suffix.hpp>
  126. #endif