OpenNI 1.5.7
XnStackT.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_STACK_T_H_
22#define _XN_STACK_T_H_
23
24//---------------------------------------------------------------------------
25// Includes
26//---------------------------------------------------------------------------
27#include "XnListT.h"
28
29//---------------------------------------------------------------------------
30// Code
31//---------------------------------------------------------------------------
32template<class T, class TAlloc = XnLinkedNodeDefaultAllocatorT<T> >
33class XnStackT : protected XnListT<T, TAlloc>
34{
35public:
37
39
40 XnStackT() : Base() {}
41
42 XnStackT(const XnStackT& other) : Base()
43 {
44 *this = other;
45 }
46
48 {
49 Base::operator=(other);
50 // no other members
51 return *this;
52 }
53
55
56 XnBool IsEmpty() const { return Base::IsEmpty(); }
57
58 XnStatus Push(T const& value) { return Base::AddFirst(value); }
59
60 XnStatus Pop(T& value)
61 {
62 ConstIterator it = Begin();
63 if (it == End())
64 {
65 return XN_STATUS_IS_EMPTY;
66 }
67 value = *it;
68 return Base::Remove(it);
69 }
70
71 T const& Top() const { return *Begin(); }
72 T& Top() { return *Begin(); }
73
74 ConstIterator Begin() const { return Base::Begin(); }
75 ConstIterator End() const { return Base::End(); }
76};
77
78#endif // _XN_STACK_T_H_
XnUInt32 XnStatus
Definition: XnStatus.h:33
Definition: XnListT.h:95
Definition: XnListT.h:85
XnStatus AddFirst(T const &value)
Definition: XnListT.h:391
XnListT & operator=(const XnListT &other)
Definition: XnListT.h:262
Iterator End()
Definition: XnListT.h:301
Iterator Begin()
Definition: XnListT.h:285
XnStatus Remove(ConstIterator where)
Definition: XnListT.h:446
XnBool IsEmpty() const
Definition: XnListT.h:502
Definition: XnStackT.h:34
T const & Top() const
Definition: XnStackT.h:71
XnStackT(const XnStackT &other)
Definition: XnStackT.h:42
XnListT< T, TAlloc > Base
Definition: XnStackT.h:36
XnStackT & operator=(const XnStackT &other)
Definition: XnStackT.h:47
XnStatus Pop(T &value)
Definition: XnStackT.h:60
T & Top()
Definition: XnStackT.h:72
~XnStackT()
Definition: XnStackT.h:54
ConstIterator End() const
Definition: XnStackT.h:75
XnStatus Push(T const &value)
Definition: XnStackT.h:58
ConstIterator Begin() const
Definition: XnStackT.h:74
Base::ConstIterator ConstIterator
Definition: XnStackT.h:38
XnStackT()
Definition: XnStackT.h:40
XnBool IsEmpty() const
Definition: XnStackT.h:56