OpenNI 1.5.4
XnStack.h
Go to the documentation of this file.
1 /****************************************************************************
2 * *
3 * OpenNI 1.x Alpha *
4 * Copyright (C) 2011 PrimeSense Ltd. *
5 * *
6 * This file is part of OpenNI. *
7 * *
8 * OpenNI is free software: you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published *
10 * by the Free Software Foundation, either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * OpenNI is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with OpenNI. If not, see <http://www.gnu.org/licenses/>. *
20 * *
21 ****************************************************************************/
22 #ifndef _XN_STACK_H
23 #define _XN_STACK_H
24 
25 //---------------------------------------------------------------------------
26 // Includes
27 //---------------------------------------------------------------------------
28 #include "XnList.h"
29 
30 //---------------------------------------------------------------------------
31 // Types
32 //---------------------------------------------------------------------------
36 class XnStack
37 {
38 public:
42  XnStack() {}
46  ~XnStack() {}
47 
55  XnStatus Push(XnValue const& value)
56  {
57  return m_List.AddFirst(value);
58  }
59 
67  XnStatus Pop(XnValue& value)
68  {
69  if (IsEmpty())
70  {
71  return XN_STATUS_IS_EMPTY;
72  }
73 
74  value = *(m_List.begin());
75  return m_List.Remove(m_List.begin());
76  }
77 
83  XnValue const& Top() const
84  {
85  return *(m_List.begin());
86  }
87 
93  XnValue& Top()
94  {
95  return *(m_List.begin());
96  }
97 
101  XnBool IsEmpty() const
102  {
103  return m_List.IsEmpty();
104  }
105 
109  XnUInt32 Size() const
110  {
111  return m_List.Size();
112  }
113 
114 private:
115  XN_DISABLE_COPY_AND_ASSIGN(XnStack);
116 
118  XnList m_List;
119 };
120 
125 #define XN_DECLARE_STACK_WITH_TRANSLATOR_DECL(decl, Type, ClassName, Translator) \
126  /* Note: we use queue declaration, as this is the same interface. */ \
127  XN_DECLARE_QUEUE_WITH_TRANSLATOR_DECL(decl, Type, ClassName, Translator, XnStack)
128 
133 #define XN_DECLARE_STACK_WITH_TRANSLATOR(Type, ClassName, Translator) \
134  XN_DECLARE_STACK_WITH_TRANSLATOR_DECL(, ClassName, Translator)
135 
140 #define XN_DECLARE_STACK_DECL(decl, Type, ClassName) \
141  XN_DECLARE_DEFAULT_VALUE_TRANSLATOR_DECL(decl, Type, XN_DEFAULT_TRANSLATOR_NAME(ClassName)) \
142  XN_DECLARE_STACK_WITH_TRANSLATOR_DECL(decl, Type, ClassName, XN_DEFAULT_TRANSLATOR_NAME(ClassName))
143 
147 #define XN_DECLARE_STACK(Type, ClassName) \
148  XN_DECLARE_STACK_DECL(, Type, ClassName)
149 
150 
151 #endif // _XN_STACK_H
XnList::Remove
XnStatus Remove(ConstIterator where, XnValue &value)
Definition: XnList.h:379
XnStack::Pop
XnStatus Pop(XnValue &value)
Definition: XnStack.h:85
XnStack
Definition: XnStack.h:35
XnList.h
XnStatus
XnUInt32 XnStatus
Definition: XnStatus.h:33
XnStack::Size
XnUInt32 Size() const
Definition: XnStack.h:127
XnList::begin
Iterator begin()
Definition: XnList.h:451
XnList::IsEmpty
XnBool IsEmpty() const
Definition: XnList.h:431
XnStack::IsEmpty
XnBool IsEmpty() const
Definition: XnStack.h:119
XnStack::~XnStack
~XnStack()
Definition: XnStack.h:64
XnList::AddFirst
XnStatus AddFirst(const XnValue &value)
Definition: XnList.h:268
XnStack::XnStack
XnStack()
Definition: XnStack.h:60
XnStack::Push
XnStatus Push(XnValue const &value)
Definition: XnStack.h:73
XnList
Definition: XnList.h:40
XnList::Size
XnUInt32 Size() const
Definition: XnList.h:439
XnStack::Top
XnValue const & Top() const
Definition: XnStack.h:101
XnValue
void * XnValue
Definition: XnDataTypes.h:36