OpenNI 1.5.4
XnCyclicQueueT.h
Go to the documentation of this file.
1 #ifndef _XN_CYCLIC_QUEUE_T_H_
2 #define _XN_CYCLIC_QUEUE_T_H_
3 
4 //---------------------------------------------------------------------------
5 // Includes
6 //---------------------------------------------------------------------------
7 #include "XnQueueT.h"
8 
9 //---------------------------------------------------------------------------
10 // Code
11 //---------------------------------------------------------------------------
12 
13 template<class T, XnUInt32 TDefaultMaxDepth, class TAlloc = XnLinkedNodeDefaultAllocatorT<T> >
14 class XnCyclicQueueT : protected XnQueueT<T, TAlloc>
15 {
16 public:
18 
19  XnCyclicQueueT(XnUInt32 nMaxDepth = TDefaultMaxDepth) : Base(), m_nMaxDepth(nMaxDepth) {}
20 
21  XnCyclicQueueT(const XnCyclicQueueT& other) : Base(other)
22  {
23  *this = other;
24  }
25 
27  {
28  Base::operator=(other);
29  m_nMaxDepth = other.m_nMaxDepth;
30  return *this;
31  }
32 
34 
35  using Base::ConstIterator;
36  using Base::IsEmpty;
37  using Base::Size;
38 
39  XnStatus SetMaxSize(XnUInt32 nMaxSize)
40  {
41  XnStatus nRetVal = XN_STATUS_OK;
42 
43  while (Size() > nMaxSize)
44  {
45  nRetVal = Remove(this->Begin());
46  XN_IS_STATUS_OK(nRetVal);
47  }
48 
49  m_nMaxDepth = nMaxSize;
50 
51  return (XN_STATUS_OK);
52  }
53 
54  XnStatus Push(T const& value)
55  {
56  XnStatus nRetVal = XN_STATUS_OK;
57  if (Size() == m_nMaxDepth)
58  {
59  nRetVal = Remove(this->Begin());
60  XN_IS_STATUS_OK(nRetVal);
61  }
62 
63  nRetVal = Base::Push(value);
64  XN_IS_STATUS_OK(nRetVal);
65 
66  return (XN_STATUS_OK);
67  }
68 
69  using Base::Pop;
70  using Base::Top;
71  using Base::Begin;
72  using Base::End;
73 
74 protected:
75  XnUInt32 m_nMaxDepth;
76 };
77 
78 
79 #endif // _XN_CYCLIC_QUEUE_T_H_
Definition: XnQueueT.h:13
T const & Top() const
Definition: XnQueueT.h:53
#define XN_IS_STATUS_OK(x)
Definition: XnMacros.h:60
XnStatus Pop(T &value)
Definition: XnQueueT.h:42
XnBool IsEmpty() const
Definition: XnListT.h:482
#define XN_STATUS_OK
Definition: XnStatus.h:37
Definition: XnListT.h:74
XnUInt32 XnStatus
Definition: XnStatus.h:34
XnUInt32 Size() const
Definition: XnListT.h:490
Definition: XnCyclicQueueT.h:14
XnCyclicQueueT & operator=(const XnCyclicQueueT &other)
Definition: XnCyclicQueueT.h:26
XnCyclicQueueT(const XnCyclicQueueT &other)
Definition: XnCyclicQueueT.h:21
Iterator Begin()
Definition: XnListT.h:265
~XnCyclicQueueT()
Definition: XnCyclicQueueT.h:33
XnStatus Push(T const &value)
Definition: XnCyclicQueueT.h:54
XnStatus SetMaxSize(XnUInt32 nMaxSize)
Definition: XnCyclicQueueT.h:39
XnQueueT< T, TAlloc > Base
Definition: XnCyclicQueueT.h:17
XnStatus Remove(ConstIterator where)
Definition: XnListT.h:426
Iterator End()
Definition: XnListT.h:281
XnQueueT & operator=(const XnQueueT &other)
Definition: XnQueueT.h:25
XnUInt32 m_nMaxDepth
Definition: XnCyclicQueueT.h:75
XnStatus Push(T const &value)
Definition: XnQueueT.h:37
XnCyclicQueueT(XnUInt32 nMaxDepth=TDefaultMaxDepth)
Definition: XnCyclicQueueT.h:19