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