OpenNI 1.5.7
XnCyclicQueueT.h
Go to the documentation of this file.
1 /*****************************************************************************
2 * *
3 * OpenNI 1.x Alpha *
4 * Copyright (C) 2012 PrimeSense Ltd. *
5 * *
6 * This file is part of OpenNI. *
7 * *
8 * Licensed under the Apache License, Version 2.0 (the "License"); *
9 * you may not use this file except in compliance with the License. *
10 * You may obtain a copy of the License at *
11 * *
12 * http://www.apache.org/licenses/LICENSE-2.0 *
13 * *
14 * Unless required by applicable law or agreed to in writing, software *
15 * distributed under the License is distributed on an "AS IS" BASIS, *
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
17 * See the License for the specific language governing permissions and *
18 * limitations under the License. *
19 * *
20 *****************************************************************************/
21 #ifndef _XN_CYCLIC_QUEUE_T_H_
22 #define _XN_CYCLIC_QUEUE_T_H_
23 
24 //---------------------------------------------------------------------------
25 // Includes
26 //---------------------------------------------------------------------------
27 #include "XnQueueT.h"
28 
29 //---------------------------------------------------------------------------
30 // Code
31 //---------------------------------------------------------------------------
32 
33 template<class T, XnUInt32 TDefaultMaxDepth, class TAlloc = XnLinkedNodeDefaultAllocatorT<T> >
34 class XnCyclicQueueT : protected XnQueueT<T, TAlloc>
35 {
36 public:
37  typedef XnQueueT<T, TAlloc> Base;
38 
39  XnCyclicQueueT(XnUInt32 nMaxDepth = TDefaultMaxDepth) : Base(), m_nMaxDepth(nMaxDepth) {}
40 
41  XnCyclicQueueT(const XnCyclicQueueT& other) : Base(other)
42  {
43  *this = other;
44  }
45 
47  {
48  Base::operator=(other);
49  m_nMaxDepth = other.m_nMaxDepth;
50  return *this;
51  }
52 
53  ~XnCyclicQueueT() {}
54 
56  using Base::IsEmpty;
57  using Base::Size;
58 
59  XnStatus SetMaxSize(XnUInt32 nMaxSize)
60  {
61  XnStatus nRetVal = XN_STATUS_OK;
62 
63  while (Size() > nMaxSize)
64  {
65  nRetVal = Remove(this->Begin());
66  XN_IS_STATUS_OK(nRetVal);
67  }
68 
69  m_nMaxDepth = nMaxSize;
70 
71  return (XN_STATUS_OK);
72  }
73 
74  XnStatus Push(T const& value)
75  {
76  XnStatus nRetVal = XN_STATUS_OK;
77  if (Size() == m_nMaxDepth)
78  {
79  nRetVal = Remove(this->Begin());
80  XN_IS_STATUS_OK(nRetVal);
81  }
82 
83  nRetVal = Base::Push(value);
84  XN_IS_STATUS_OK(nRetVal);
85 
86  return (XN_STATUS_OK);
87  }
88 
89  using Base::Pop;
90  using Base::Top;
91  using Base::Begin;
92  using Base::End;
93 
94 protected:
95  XnUInt32 m_nMaxDepth;
96 };
97 
98 
99 #endif // _XN_CYCLIC_QUEUE_T_H_
XnCyclicQueueT::~XnCyclicQueueT
~XnCyclicQueueT()
Definition: XnCyclicQueueT.h:71
XnListT::End
Iterator End()
Definition: XnListT.h:300
XnQueueT::Pop
XnStatus Pop(T &value)
Definition: XnQueueT.h:79
XN_IS_STATUS_OK
#define XN_IS_STATUS_OK(x)
Definition: XnMacros.h:58
XN_STATUS_OK
#define XN_STATUS_OK
Definition: XnStatus.h:35
XnListT::Remove
XnStatus Remove(ConstIterator where)
Definition: XnListT.h:445
XnCyclicQueueT::SetMaxSize
XnStatus SetMaxSize(XnUInt32 nMaxSize)
Definition: XnCyclicQueueT.h:77
XnQueueT::Top
T const & Top() const
Definition: XnQueueT.h:90
XnStatus
XnUInt32 XnStatus
Definition: XnStatus.h:32
XnCyclicQueueT::Base
XnQueueT< T, TAlloc > Base
Definition: XnCyclicQueueT.h:55
XnQueueT
Definition: XnQueueT.h:32
XnCyclicQueueT
Definition: XnCyclicQueueT.h:34
XnCyclicQueueT::operator=
XnCyclicQueueT & operator=(const XnCyclicQueueT &other)
Definition: XnCyclicQueueT.h:64
XnListT::ConstIterator
Definition: XnListT.h:93
XnListT::IsEmpty
XnBool IsEmpty() const
Definition: XnListT.h:501
XnQueueT::operator=
XnQueueT & operator=(const XnQueueT &other)
Definition: XnQueueT.h:62
XnCyclicQueueT::m_nMaxDepth
XnUInt32 m_nMaxDepth
Definition: XnCyclicQueueT.h:113
XnQueueT.h
XnCyclicQueueT::Push
XnStatus Push(T const &value)
Definition: XnCyclicQueueT.h:92
XnListT::Size
XnUInt32 Size() const
Definition: XnListT.h:509
XnQueueT::Push
XnStatus Push(T const &value)
Definition: XnQueueT.h:74
XnCyclicQueueT::XnCyclicQueueT
XnCyclicQueueT(XnUInt32 nMaxDepth=TDefaultMaxDepth)
Definition: XnCyclicQueueT.h:57
XnListT::Begin
Iterator Begin()
Definition: XnListT.h:284