OpenPose  1.7.0
The first real-time multi-person system to jointly detect human body, hand, facial, and foot keypoints
priorityQueue.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_THREAD_PRIORITY_QUEUE_HPP
2 #define OPENPOSE_THREAD_PRIORITY_QUEUE_HPP
3 
4 #include <queue> // std::priority_queue
7 
8 namespace op
9 {
10  template<typename TDatums, typename TQueue = std::priority_queue<TDatums, std::vector<TDatums>, std::greater<TDatums>>>
11  class PriorityQueue : public QueueBase<TDatums, TQueue>
12  {
13  public:
14  explicit PriorityQueue(const long long maxSize = 256);
15 
16  virtual ~PriorityQueue();
17 
18  TDatums front() const;
19 
20  private:
21  bool pop(TDatums& tDatums);
22 
23  DELETE_COPY(PriorityQueue);
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>
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.top();
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 PriorityQueue<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.top())};
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_PRIORITY_QUEUE_HPP
virtual ~PriorityQueue()
TDatums front() const
PriorityQueue(const long long maxSize=256)
COMPILE_TEMPLATE_DATUM(WPoseTriangulation)
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")