OpenNI 1.5.7
XnQueue.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_QUEUE_H
22 #define _XN_QUEUE_H
23 
24 //---------------------------------------------------------------------------
25 // Includes
26 //---------------------------------------------------------------------------
27 #include "XnList.h"
28 
29 //---------------------------------------------------------------------------
30 // Types
31 //---------------------------------------------------------------------------
35 class XnQueue
36 {
37 public:
41  XnQueue() {}
45  virtual ~XnQueue() {}
46 
50  virtual XnStatus Init()
51  {
52  return (XN_STATUS_OK);
53  }
54 
62  virtual XnStatus Push(XnValue const& value)
63  {
64  XnStatus nRetVal = XN_STATUS_OK;
65 
66  nRetVal = m_List.AddLast(value);
67  XN_IS_STATUS_OK(nRetVal);
68 
69  return (XN_STATUS_OK);
70  }
78  virtual XnStatus Pop(XnValue& value)
79  {
80  if (IsEmpty())
81  {
82  return XN_STATUS_IS_EMPTY;
83  }
84 
85  value = *(m_List.begin());
86  return m_List.Remove(m_List.begin());
87  }
88 
94  XnValue const& Top() const
95  {
96  return *(m_List.begin());
97  }
98 
105  {
106  return *(m_List.begin());
107  }
108 
112  XnBool IsEmpty() const
113  {
114  return m_List.IsEmpty();
115  }
116 
120  virtual XnUInt32 Size() const
121  {
122  return m_List.Size();
123  }
124 
125 private:
126  XN_DISABLE_COPY_AND_ASSIGN(XnQueue);
127 
129  XnList m_List;
130 };
131 
137 #define XN_DECLARE_QUEUE_WITH_TRANSLATOR_DECL(decl, Type, ClassName, Translator, base) \
138  class decl ClassName : public base \
139  { \
140  public: \
141  ClassName() {} \
142  ~ClassName() \
143  { \
144  /* We do this using Pop() to make sure memory is freed. */ \
145  Type dummy; \
146  while (Size() != 0) \
147  Pop(dummy); \
148  } \
149  XnStatus Push(Type const& value) \
150  { \
151  XnValue val = Translator::CreateValueCopy(value); \
152  XnStatus nRetVal = base::Push(val); \
153  if (nRetVal != XN_STATUS_OK) \
154  { \
155  Translator::FreeValue(val); \
156  return (nRetVal); \
157  } \
158  return XN_STATUS_OK; \
159  } \
160  XnStatus Pop(Type& value) \
161  { \
162  XnValue val; \
163  XnStatus nRetVal = base::Pop(val); \
164  if (nRetVal != XN_STATUS_OK) return (nRetVal); \
165  value = Translator::GetFromValue(val); \
166  Translator::FreeValue(val); \
167  return XN_STATUS_OK; \
168  } \
169  inline Type const& Top() const { return Translator::GetFromValue(base::Top()); }\
170  inline Type& Top() { return Translator::GetFromValue(base::Top()); } \
171  private: \
172  XN_DISABLE_COPY_AND_ASSIGN(ClassName); \
173  };
174 
180 #define XN_DECLARE_QUEUE_WITH_TRANSLATOR(Type, ClassName, Translator, base) \
181  XN_DECLARE_QUEUE_WITH_TRANSLATOR_DECL(, Type, ClassName, Translator, base)
182 
187 #define XN_DECLARE_QUEUE_DECL(decl, Type, ClassName) \
188  XN_DECLARE_DEFAULT_VALUE_TRANSLATOR_DECL(decl, Type, XN_DEFAULT_TRANSLATOR_NAME(ClassName)) \
189  XN_DECLARE_QUEUE_WITH_TRANSLATOR_DECL(decl, Type, ClassName, XN_DEFAULT_TRANSLATOR_NAME(ClassName), XnQueue)
190 
194 #define XN_DECLARE_QUEUE(Type, ClassName) \
195  XN_DECLARE_QUEUE_DECL(, Type, ClassName)
196 
197 #endif // _XN_QUEUE_H
Definition: XnList.h:40
#define XN_IS_STATUS_OK(x)
Definition: XnMacros.h:59
XnStatus Remove(ConstIterator where, XnValue &value)
Definition: XnList.h:360
virtual ~XnQueue()
Definition: XnQueue.h:45
#define XN_STATUS_OK
Definition: XnStatus.h:36
virtual XnStatus Pop(XnValue &value)
Definition: XnQueue.h:78
XnBool IsEmpty() const
Definition: XnQueue.h:112
virtual XnUInt32 Size() const
Definition: XnQueue.h:120
XnUInt32 XnStatus
Definition: XnStatus.h:33
virtual XnStatus Init()
Definition: XnQueue.h:50
virtual XnStatus Push(XnValue const &value)
Definition: XnQueue.h:62
Definition: XnQueue.h:35
void * XnValue
Definition: XnDataTypes.h:35
XnValue const & Top() const
Definition: XnQueue.h:94
XnBool IsEmpty() const
Definition: XnList.h:412
XnStatus AddLast(const XnValue &value)
Definition: XnList.h:261
XnUInt32 Size() const
Definition: XnList.h:420
XnValue & Top()
Definition: XnQueue.h:104
Iterator begin()
Definition: XnList.h:432
XnQueue()
Definition: XnQueue.h:41