OpenPose  1.0.0rc2
OpenPose: A Real-Time Multi-Person Key-Point Detection And Multi-Threading C++ Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
queue.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_THREAD_QUEUE_HPP
2 #define OPENPOSE_THREAD_QUEUE_HPP
3 
4 #include <queue> // std::queue
7 
8 namespace op
9 {
10  template<typename TDatums, typename TQueue = std::queue<TDatums>>
11  class Queue : public QueueBase<TDatums, TQueue>
12  {
13  public:
14  explicit Queue(const long long maxSize);
15 
16  TDatums front() const;
17 
18  private:
19  bool pop(TDatums& tDatums);
20 
21  DELETE_COPY(Queue);
22  };
23 }
24 
25 
26 
27 
28 
29 // Implementation
30 #include <type_traits> // std::is_same
31 namespace op
32 {
33  template<typename TDatums, typename TQueue>
34  Queue<TDatums, TQueue>::Queue(const long long maxSize) :
35  QueueBase<TDatums, TQueue>{maxSize}
36  {
37  // Check TDatums = underlying value type of TQueue
38  typedef typename TQueue::value_type underlyingValueType;
39  static_assert(std::is_same<TDatums, underlyingValueType>::value,
40  "Error: The type of the queue must be the same as the type of the container");
41  }
42 
43  template<typename TDatums, typename TQueue>
45  {
46  try
47  {
48  const std::lock_guard<std::mutex> lock{this->mMutex};
49  return this->mTQueue.front();
50  }
51  catch (const std::exception& e)
52  {
53  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
54  return TDatums{};
55  }
56  }
57 
58  template<typename TDatums, typename TQueue>
59  bool Queue<TDatums, TQueue>::pop(TDatums& tDatums)
60  {
61  try
62  {
63  if (this->mPopIsStopped || this->mTQueue.empty())
64  return false;
65 
66  tDatums = {std::move(this->mTQueue.front())};
67  this->mTQueue.pop();
68  this->mConditionVariable.notify_one();
69  return true;
70  }
71  catch (const std::exception& e)
72  {
73  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
74  return false;
75  }
76  }
77 
79 }
80 
81 #endif // OPENPOSE_THREAD_QUEUE_HPP
Definition: queueBase.hpp:12
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")
TDatums front() const
Definition: queue.hpp:44
Queue(const long long maxSize)
Definition: queue.hpp:34
COMPILE_TEMPLATE_DATUM(WPoseTriangulation)
Definition: queue.hpp:11