XnCyclicStackT.h
Go to the documentation of this file.
#ifndef _XN_CYCLIC_STACK_T_H_
#define _XN_CYCLIC_STACK_T_H_
//---------------------------------------------------------------------------
// Includes
//---------------------------------------------------------------------------
#include "XnStackT.h"
//---------------------------------------------------------------------------
// Code
//---------------------------------------------------------------------------
template<class T, XnUInt32 TDefaultMaxDepth, class TAlloc = XnLinkedNodeDefaultAllocatorT<T> >
class XnCyclicStackT : protected XnStackT<T, TAlloc>
{
public:
typedef XnStackT<T, TAlloc> Base;
XnCyclicStackT(XnUInt32 nMaxDepth = TDefaultMaxDepth) : Base(), m_nMaxDepth(nMaxDepth) {}
XnCyclicStackT(const XnCyclicStackT& other) : Base(other)
{
*this = other;
}
XnCyclicStackT& operator=(const XnCyclicStackT& other)
{
Base::operator=(other);
m_nMaxDepth = other.m_nMaxDepth;
return *this;
}
~XnCyclicStackT() {}
using typename Base::ConstIterator;
using Base::Remove;
using Base::IsEmpty;
using Base::Size;
XnStatus SetMaxSize(XnUInt32 nMaxSize)
{
XnStatus nRetVal = XN_STATUS_OK;
while (Size() > nMaxSize)
{
nRetVal = Remove(this->ReverseBegin());
XN_IS_STATUS_OK(nRetVal);
}
m_nMaxDepth = nMaxSize;
return (XN_STATUS_OK);
}
XnStatus Push(T const& value)
{
XnStatus nRetVal = XN_STATUS_OK;
if (Size() == m_nMaxDepth)
{
nRetVal = Remove(this->ReverseBegin());
XN_IS_STATUS_OK(nRetVal);
}
nRetVal = Base::Push(value);
XN_IS_STATUS_OK(nRetVal);
return (XN_STATUS_OK);
}
using Base::Pop;
using Base::Top;
using Base::Begin;
using Base::End;
protected:
XnUInt32 m_nMaxDepth;
};
#endif // _XN_CYCLIC_STACK_T_H_
XN_IS_STATUS_OK
#define XN_IS_STATUS_OK(x)
Definition XnMacros.h:60
XnStackT.h
XnStatus
XnUInt32 XnStatus
Definition XnStatus.h:34
XN_STATUS_OK
#define XN_STATUS_OK
Definition XnStatus.h:37
XnCyclicStackT::XnCyclicStackT
XnCyclicStackT(XnUInt32 nMaxDepth=TDefaultMaxDepth)
Definition XnCyclicStackT.h:19
XnCyclicStackT::Base
XnStackT< T, TAlloc > Base
Definition XnCyclicStackT.h:17
XnCyclicStackT::Push
XnStatus Push(T const &value)
Definition XnCyclicStackT.h:55
XnCyclicStackT::XnCyclicStackT
XnCyclicStackT(const XnCyclicStackT &other)
Definition XnCyclicStackT.h:21
XnCyclicStackT::~XnCyclicStackT
~XnCyclicStackT()
Definition XnCyclicStackT.h:33
XnCyclicStackT::m_nMaxDepth
XnUInt32 m_nMaxDepth
Definition XnCyclicStackT.h:76
XnCyclicStackT::SetMaxSize
XnStatus SetMaxSize(XnUInt32 nMaxSize)
Definition XnCyclicStackT.h:40
XnCyclicStackT::operator=
XnCyclicStackT & operator=(const XnCyclicStackT &other)
Definition XnCyclicStackT.h:26
XnListT< T, TAlloc >::Size
XnUInt32 Size() const
Definition XnListT.h:490
XnListT::ReverseBegin
Iterator ReverseBegin()
Definition XnListT.h:297
XnListT< T, TAlloc >::Remove
XnStatus Remove(ConstIterator where)
Definition XnListT.h:426
XnStackT< T, TAlloc >::Top
T const & Top() const
Definition XnStackT.h:51
XnStackT< T, TAlloc >::operator=
XnStackT & operator=(const XnStackT &other)
Definition XnStackT.h:27
XnStackT< T, TAlloc >::Pop
XnStatus Pop(T &value)
Definition XnStackT.h:40
XnStackT< T, TAlloc >::End
ConstIterator End() const
Definition XnStackT.h:55
XnStackT< T, TAlloc >::Push
XnStatus Push(T const &value)
Definition XnStackT.h:38
XnStackT< T, TAlloc >::Begin
ConstIterator Begin() const
Definition XnStackT.h:54
XnStackT< T, TAlloc >::ConstIterator
Base::ConstIterator ConstIterator
Definition XnStackT.h:18
XnStackT::XnStackT
XnStackT()
Definition XnStackT.h:20
XnStackT< T, TAlloc >::IsEmpty
XnBool IsEmpty() const
Definition XnStackT.h:36