OpenPose  1.7.0
The first real-time multi-person system to jointly detect human body, hand, facial, and foot keypoints
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  virtual ~Queue();
17 
18  TDatums front() const;
19 
20  private:
21  bool pop(TDatums& tDatums);
22 
23  DELETE_COPY(Queue);
24  };
25 }
26 
27 
28 
29 
30 
31 // Implementation
32 #include <type_traits> // std::is_same
33 namespace op
34 {
35  template<typename TDatums, typename TQueue>
36  Queue<TDatums, TQueue>::Queue(const long long maxSize) :
37  QueueBase<TDatums, TQueue>{maxSize}
38  {
39  // Check TDatums = underlying value type of TQueue
40  typedef typename TQueue::value_type underlyingValueType;
41  static_assert(std::is_same<TDatums, underlyingValueType>::value,
42  "Error: The type of the queue must be the same as the type of the container");
43  }
44 
45  template<typename TDatums, typename TQueue>
47  {
48  }
49 
50  template<typename TDatums, typename TQueue>
52  {
53  try
54  {
55  const std::lock_guard<std::mutex> lock{this->mMutex};
56  return this->mTQueue.front();
57  }
58  catch (const std::exception& e)
59  {
60  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
61  return TDatums{};
62  }
63  }
64 
65  template<typename TDatums, typename TQueue>
66  bool Queue<TDatums, TQueue>::pop(TDatums& tDatums)
67  {
68  try
69  {
70  if (this->mPopIsStopped || this->mTQueue.empty())
71  return false;
72 
73  tDatums = {std::move(this->mTQueue.front())};
74  this->mTQueue.pop();
75  this->mConditionVariable.notify_one();
76  return true;
77  }
78  catch (const std::exception& e)
79  {
80  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
81  return false;
82  }
83  }
84 
86 }
87 
88 #endif // OPENPOSE_THREAD_QUEUE_HPP
virtual ~Queue()
Definition: queue.hpp:46
TDatums front() const
Definition: queue.hpp:51
Queue(const long long maxSize)
Definition: queue.hpp:36
COMPILE_TEMPLATE_DATUM(WPoseTriangulation)
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")