LimitedPriorityQueueSet.h
Go to the documentation of this file.
00001 #ifndef FACE_CONTOUR_DETECTOR_LIMITEDPRIORITYQUEUESET_H_
00002 #define FACE_CONTOUR_DETECTOR_LIMITEDPRIORITYQUEUESET_H_
00003 
00004 #include <functional>
00005 #include <algorithm>
00006 #include <deque>
00007 #include <stddef.h>
00008 #include <cassert>
00009 
00010 namespace face_contour_detector {
00015         template <class T, class Compare = std::less<T> >
00016         class LimitedPriorityQueueSet {
00017         public:
00020                 LimitedPriorityQueueSet(size_t size);
00022                 virtual ~LimitedPriorityQueueSet();
00027                 void Push(const T& item);
00030                 T PopFront();
00033                 const T& Front() const;
00036                 bool Empty() const;
00039                 size_t Size() const;
00040         private:
00041                 std::deque<T> m_deque;
00042                 size_t m_size;
00043                 size_t m_maxSize;
00044         };
00045 
00046         //Implementation
00047 
00048         template <class T, class Compare>
00049         LimitedPriorityQueueSet<T, Compare>::LimitedPriorityQueueSet(size_t maxSize) : m_size(0), m_maxSize(maxSize) {}
00050 
00051         template <class T, class Compare>
00052         LimitedPriorityQueueSet<T, Compare>::~LimitedPriorityQueueSet() {}
00053 
00054         template <class T, class Compare>
00055         void LimitedPriorityQueueSet<T, Compare>::Push(const T& item) {
00056                 typename std::deque<T>::iterator it;
00057                 bool inserted = false;
00058                 Compare compare;
00059                 for (it = m_deque.begin(); it != m_deque.end(); it++) {
00060                         if (compare(item, *it))  {
00061                                 //insert here
00062                                 m_size++;
00063                                 inserted = true;
00064                                 m_deque.insert(it, item);
00065                                 break;
00066                         } else if (!compare(*it, item)) {
00067                                 //already inside
00068                                 inserted = true;
00069                                 break;
00070                         }
00071                 }
00072                 if (!inserted && m_maxSize > m_size) {
00073                         m_deque.push_back(item);
00074                         m_size++;
00075                 } else if (inserted && m_maxSize < m_size) {
00076                         m_deque.pop_back();
00077                         m_size--;
00078                 }
00079                 assert(m_deque.size() == m_size);
00080         }
00081 
00082         template <class T, class Compare>
00083         T LimitedPriorityQueueSet<T, Compare>::PopFront() {
00084                 assert(!Empty());
00085                 T front = this->m_deque.front();
00086                 m_deque.pop_front();
00087                 m_size--;
00088                 return front;
00089         }
00090 
00091         template <class T, class Compare>
00092         const T& LimitedPriorityQueueSet<T, Compare>::Front() const {
00093                 return m_deque.front();
00094         }
00095 
00096         template <class T, class Compare>
00097         bool LimitedPriorityQueueSet<T, Compare>::Empty() const {
00098                 return m_deque.empty();
00099         }
00100 
00101         template <class T, class Compare>
00102         size_t LimitedPriorityQueueSet<T, Compare>::Size() const {
00103                 return m_size;
00104         }
00105 } //namespace face_contour_detector
00106 
00107 
00108 #endif /* FACE_CONTOUR_DETECTOR_LIMITEDPRIORITYQUEUESET_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends


face_contour_detector
Author(s): Fabian Wenzelmann and Julian Schmid
autogenerated on Wed Dec 26 2012 16:18:17