queue_views.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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/queue_base.hpp>
  16. #include <boost/config/abi_prefix.hpp>
  17. namespace boost
  18. {
  19. namespace concurrent
  20. {
  21. template <typename Queue>
  22. class queue_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. queue_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(x); }
  38. queue_op_status try_push(const value_type& x) { return queue->try_push(x); }
  39. queue_op_status nonblocking_push(const value_type& x) { return queue->nonblocking_push(x); }
  40. queue_op_status wait_push(const value_type& x) { return queue->wait_push(x); }
  41. void push(BOOST_THREAD_RV_REF(value_type) x) { queue->push(boost::move(x)); }
  42. queue_op_status try_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->try_push(boost::move(x)); }
  43. queue_op_status nonblocking_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->nonblocking_push(boost::move(x)); }
  44. queue_op_status wait_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->wait_push(boost::move(x)); }
  45. };
  46. template <typename Queue>
  47. class queue_front_view
  48. {
  49. Queue* queue;
  50. public:
  51. typedef typename Queue::value_type value_type;
  52. typedef typename Queue::size_type size_type;
  53. // Constructors/Assignment/Destructors
  54. queue_front_view(Queue& q) BOOST_NOEXCEPT : queue(&q) {}
  55. // Observers
  56. bool empty() const { return queue->empty(); }
  57. bool full() const { return queue->full(); }
  58. size_type size() const { return queue->size(); }
  59. bool closed() const { return queue->closed(); }
  60. // Modifiers
  61. void close() { queue->close(); }
  62. void pull(value_type& x) { queue->pull(x); };
  63. // enable_if is_nothrow_copy_movable<value_type>
  64. value_type pull() { return queue->pull(); }
  65. queue_op_status try_pull(value_type& x) { return queue->try_pull(x); }
  66. queue_op_status nonblocking_pull(value_type& x) { return queue->nonblocking_pull(x); }
  67. queue_op_status wait_pull(value_type& x) { return queue->wait_pull(x); }
  68. };
  69. #if ! defined BOOST_NO_CXX11_TEMPLATE_ALIASES
  70. template <class T>
  71. using queue_back = queue_back_view<queue_base<T> > ;
  72. template <class T>
  73. using queue_front = queue_front_view<queue_base<T> > ;
  74. #else
  75. template <class T>
  76. struct queue_back : queue_back_view<queue_base<T> >
  77. {
  78. typedef queue_back_view<queue_base<T> > base_type;
  79. queue_back(queue_base<T>& q) BOOST_NOEXCEPT : base_type(q) {}
  80. };
  81. template <class T>
  82. struct queue_front : queue_front_view<queue_base<T> >
  83. {
  84. typedef queue_front_view<queue_base<T> > base_type;
  85. queue_front(queue_base<T>& q) BOOST_NOEXCEPT : base_type(q) {}
  86. };
  87. #endif
  88. // template <class Queue>
  89. // queue_back_view<Queue> back(Queue & q) { return queue_back_view<Queue>(q); }
  90. // template <class Queue>
  91. // queue_front_view<Queue> front(Queue & q) { return queue_front_view<Queue>(q); }
  92. //#if 0
  93. // template <class T>
  94. // queue_back<T> back(queue_base<T> & q) { return queue_back<T>(q); }
  95. // template <class T>
  96. // queue_front<T> front(queue_base<T> & q) { return queue_front<T>(q); }
  97. //#else
  98. // template <class T>
  99. // typename queue_back<T>::type back(queue_base<T> & q) { return typename queue_back<T>::type(q); }
  100. // template <class T>
  101. // typename queue_front<T>::type front(queue_base<T> & q) { return typename queue_front<T>::type(q); }
  102. //#endif
  103. }
  104. using concurrent::queue_back_view;
  105. using concurrent::queue_front_view;
  106. using concurrent::queue_back;
  107. using concurrent::queue_front;
  108. //using concurrent::back;
  109. //using concurrent::front;
  110. }
  111. #include <boost/config/abi_suffix.hpp>
  112. #endif