#ifndef OPENPOSE_THREAD_PRIORITY_QUEUE_HPP #define OPENPOSE_THREAD_PRIORITY_QUEUE_HPP #include // std::priority_queue #include #include namespace op { template, std::greater>> class PriorityQueue : public QueueBase { public: explicit PriorityQueue(const long long maxSize = 256); virtual ~PriorityQueue(); TDatums front() const; private: bool pop(TDatums& tDatums); DELETE_COPY(PriorityQueue); }; } // Implementation #include // std::is_same namespace op { template PriorityQueue::PriorityQueue(const long long maxSize) : QueueBase{maxSize} { // Check TDatums = underlying value type of TQueue typedef typename TQueue::value_type underlyingValueType; static_assert(std::is_same::value, "Error: The type of the queue must be the same as the type of the container"); } template PriorityQueue::~PriorityQueue() { } template TDatums PriorityQueue::front() const { try { const std::lock_guard lock{this->mMutex}; return this->mTQueue.top(); } catch (const std::exception& e) { error(e.what(), __LINE__, __FUNCTION__, __FILE__); return TDatums{}; } } template bool PriorityQueue::pop(TDatums& tDatums) { try { if (this->mPopIsStopped || this->mTQueue.empty()) return false; tDatums = {std::move(this->mTQueue.top())}; this->mTQueue.pop(); this->mConditionVariable.notify_one(); return true; } catch (const std::exception& e) { error(e.what(), __LINE__, __FUNCTION__, __FILE__); return false; } } COMPILE_TEMPLATE_DATUM(PriorityQueue); } #endif // OPENPOSE_THREAD_PRIORITY_QUEUE_HPP