OpenPose 1.0.0rc2 OpenPose: A Real-Time Multi-Person Key-Point Detection And Multi-Threading C++ Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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
5 #include <openpose/core/common.hpp>
6 #include <openpose/thread/queueBase.hpp>
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>
46 Queue<TDatums, TQueue>::~Queue()
47 {
48 }
49
50 template<typename TDatums, typename TQueue>
51 TDatums Queue<TDatums, TQueue>::front() const
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
85 COMPILE_TEMPLATE_DATUM(Queue);
86 }
87
88 #endif // OPENPOSE_THREAD_QUEUE_HPP
op::QueueBase
Definition: queueBase.hpp:12
op::Queue::~Queue
virtual ~Queue()
Definition: queue.hpp:46
common.hpp
op::error
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")
op::Queue::front
TDatums front() const
Definition: queue.hpp:51
queueBase.hpp
op::Queue::Queue
Queue(const long long maxSize)
Definition: queue.hpp:36
op::COMPILE_TEMPLATE_DATUM
COMPILE_TEMPLATE_DATUM(WPoseTriangulation)
op::Queue
Definition: queue.hpp:11