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 //---------------------------------------------------------------------------
32 template<class T, class TAlloc = XnLinkedNodeDefaultAllocatorT<T> >
33 class XnStackT : protected XnListT<T, TAlloc>
34 {
35 public:
36  typedef XnListT<T, TAlloc> Base;
37 
38  typedef typename Base::ConstIterator ConstIterator;
39 
40  XnStackT() : Base() {}
41 
42  XnStackT(const XnStackT& other) : Base()
43  {
44  *this = other;
45  }
46 
47  XnStackT& operator=(const XnStackT& other)
48  {
49  Base::operator=(other);
50  // no other members
51  return *this;
52  }
53 
54  ~XnStackT() {}
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_
XnStackT::~XnStackT
~XnStackT()
Definition: XnStackT.h:73
XnStackT
Definition: XnStackT.h:33
XnListT::End
Iterator End()
Definition: XnListT.h:301
XnListT
Definition: XnListT.h:84
XnListT::Remove
XnStatus Remove(ConstIterator where)
Definition: XnListT.h:446
XnStackT::ConstIterator
Base::ConstIterator ConstIterator
Definition: XnStackT.h:57
XnStackT::operator=
XnStackT & operator=(const XnStackT &other)
Definition: XnStackT.h:66
XnStatus
XnUInt32 XnStatus
Definition: XnStatus.h:33
XnStackT::Begin
ConstIterator Begin() const
Definition: XnStackT.h:93
XnStackT::IsEmpty
XnBool IsEmpty() const
Definition: XnStackT.h:75
XnListT::operator=
XnListT & operator=(const XnListT &other)
Definition: XnListT.h:262
XnStackT::XnStackT
XnStackT()
Definition: XnStackT.h:59
XnListT::ConstIterator
Definition: XnListT.h:94
XnListT::IsEmpty
XnBool IsEmpty() const
Definition: XnListT.h:502
XnStackT::Push
XnStatus Push(T const &value)
Definition: XnStackT.h:77
XnListT.h
XnStackT::Top
T const & Top() const
Definition: XnStackT.h:90
XnStackT::Base
XnListT< T, TAlloc > Base
Definition: XnStackT.h:55
XnStackT::Pop
XnStatus Pop(T &value)
Definition: XnStackT.h:79
XnListT::Begin
Iterator Begin()
Definition: XnListT.h:285
XnStackT::End
ConstIterator End() const
Definition: XnStackT.h:94
XnListT::AddFirst
XnStatus AddFirst(T const &value)
Definition: XnListT.h:391