OpenNI 1.5.4
XnQueue.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_QUEUE_H
23#define _XN_QUEUE_H
24
25//---------------------------------------------------------------------------
26// Includes
27//---------------------------------------------------------------------------
28#include "XnList.h"
29
30//---------------------------------------------------------------------------
31// Types
32//---------------------------------------------------------------------------
37{
38public:
46 virtual ~XnQueue() {}
47
51 virtual XnStatus Init()
52 {
53 return (XN_STATUS_OK);
54 }
55
63 virtual XnStatus Push(XnValue const& value)
64 {
65 XnStatus nRetVal = XN_STATUS_OK;
66
67 nRetVal = m_List.AddLast(value);
68 XN_IS_STATUS_OK(nRetVal);
69
70 return (XN_STATUS_OK);
71 }
79 virtual XnStatus Pop(XnValue& value)
80 {
81 if (IsEmpty())
82 {
83 return XN_STATUS_IS_EMPTY;
84 }
85
86 value = *(m_List.begin());
87 return m_List.Remove(m_List.begin());
88 }
89
95 XnValue const& Top() const
96 {
97 return *(m_List.begin());
98 }
99
106 {
107 return *(m_List.begin());
108 }
109
113 XnBool IsEmpty() const
114 {
115 return m_List.IsEmpty();
116 }
117
121 virtual XnUInt32 Size() const
122 {
123 return m_List.Size();
124 }
125
126private:
128
130 XnList m_List;
131};
132
138#define XN_DECLARE_QUEUE_WITH_TRANSLATOR_DECL(decl, Type, ClassName, Translator, base) \
139 class decl ClassName : public base \
140 { \
141 public: \
142 ClassName() {} \
143 ~ClassName() \
144 { \
145 /* We do this using Pop() to make sure memory is freed. */ \
146 Type dummy; \
147 while (Size() != 0) \
148 Pop(dummy); \
149 } \
150 XnStatus Push(Type const& value) \
151 { \
152 XnValue val = Translator::CreateValueCopy(value); \
153 XnStatus nRetVal = base::Push(val); \
154 if (nRetVal != XN_STATUS_OK) \
155 { \
156 Translator::FreeValue(val); \
157 return (nRetVal); \
158 } \
159 return XN_STATUS_OK; \
160 } \
161 XnStatus Pop(Type& value) \
162 { \
163 XnValue val; \
164 XnStatus nRetVal = base::Pop(val); \
165 if (nRetVal != XN_STATUS_OK) return (nRetVal); \
166 value = Translator::GetFromValue(val); \
167 Translator::FreeValue(val); \
168 return XN_STATUS_OK; \
169 } \
170 inline Type const& Top() const { return Translator::GetFromValue(base::Top()); }\
171 inline Type& Top() { return Translator::GetFromValue(base::Top()); } \
172 private: \
173 XN_DISABLE_COPY_AND_ASSIGN(ClassName); \
174 };
175
181#define XN_DECLARE_QUEUE_WITH_TRANSLATOR(Type, ClassName, Translator, base) \
182 XN_DECLARE_QUEUE_WITH_TRANSLATOR_DECL(, Type, ClassName, Translator, base)
183
188#define XN_DECLARE_QUEUE_DECL(decl, Type, ClassName) \
189 XN_DECLARE_DEFAULT_VALUE_TRANSLATOR_DECL(decl, Type, XN_DEFAULT_TRANSLATOR_NAME(ClassName)) \
190 XN_DECLARE_QUEUE_WITH_TRANSLATOR_DECL(decl, Type, ClassName, XN_DEFAULT_TRANSLATOR_NAME(ClassName), XnQueue)
191
195#define XN_DECLARE_QUEUE(Type, ClassName) \
196 XN_DECLARE_QUEUE_DECL(, Type, ClassName)
197
198#endif // _XN_QUEUE_H
void * XnValue
Definition XnDataTypes.h:36
#define XN_IS_STATUS_OK(x)
Definition XnMacros.h:60
#define XN_DISABLE_COPY_AND_ASSIGN(TypeName)
Definition XnMacros.h:119
XnUInt32 XnStatus
Definition XnStatus.h:34
#define XN_STATUS_OK
Definition XnStatus.h:37
Definition XnList.h:42
XnStatus AddLast(const XnValue &value)
Definition XnList.h:262
XnUInt32 Size() const
Definition XnList.h:421
XnStatus Remove(ConstIterator where, XnValue &value)
Definition XnList.h:361
Iterator begin()
Definition XnList.h:433
XnBool IsEmpty() const
Definition XnList.h:413
Definition XnQueue.h:37
XnBool IsEmpty() const
Definition XnQueue.h:113
XnValue const & Top() const
Definition XnQueue.h:95
virtual XnStatus Pop(XnValue &value)
Definition XnQueue.h:79
XnValue & Top()
Definition XnQueue.h:105
XnQueue()
Definition XnQueue.h:42
virtual ~XnQueue()
Definition XnQueue.h:46
virtual XnUInt32 Size() const
Definition XnQueue.h:121
virtual XnStatus Push(XnValue const &value)
Definition XnQueue.h:63
virtual XnStatus Init()
Definition XnQueue.h:51