OpenNI 1.3.2
XnQueue.h
Go to the documentation of this file.
1 /****************************************************************************
2 * *
3 * OpenNI 1.1 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 //---------------------------------------------------------------------------
36 class XnQueue
37 {
38 public:
42  XnQueue() {}
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 
126 private:
128  XnList m_List;
129 };
130 
136 #define XN_DECLARE_QUEUE_WITH_TRANSLATOR_DECL(decl, Type, ClassName, Translator, base) \
137  class decl ClassName : public base \
138  { \
139  public: \
140  ~ClassName() \
141  { \
142  /* We do this using Pop() to make sure memory is freed. */ \
143  Type dummy; \
144  while (Size() != 0) \
145  Pop(dummy); \
146  } \
147  XnStatus Push(Type const& value) \
148  { \
149  XnValue val = Translator::CreateValueCopy(value); \
150  XnStatus nRetVal = base::Push(val); \
151  if (nRetVal != XN_STATUS_OK) \
152  { \
153  Translator::FreeValue(val); \
154  return (nRetVal); \
155  } \
156  return XN_STATUS_OK; \
157  } \
158  XnStatus Pop(Type& value) \
159  { \
160  XnValue val; \
161  XnStatus nRetVal = base::Pop(val); \
162  if (nRetVal != XN_STATUS_OK) return (nRetVal); \
163  value = Translator::GetFromValue(val); \
164  return XN_STATUS_OK; \
165  } \
166  inline Type const& Top() const { return Translator::GetFromValue(base::Top()); }\
167  inline Type& Top() { return Translator::GetFromValue(base::Top()); } \
168  };
169 
175 #define XN_DECLARE_QUEUE_WITH_TRANSLATOR(Type, ClassName, Translator, base) \
176  XN_DECLARE_QUEUE_WITH_TRANSLATOR_DECL(, Type, ClassName, Translator, base)
177 
182 #define XN_DECLARE_QUEUE_DECL(decl, Type, ClassName) \
183  XN_DECLARE_DEFAULT_VALUE_TRANSLATOR_DECL(decl, Type, XN_DEFAULT_TRANSLATOR_NAME(ClassName)) \
184  XN_DECLARE_QUEUE_WITH_TRANSLATOR_DECL(decl, Type, ClassName, XN_DEFAULT_TRANSLATOR_NAME(ClassName), XnQueue)
185 
189 #define XN_DECLARE_QUEUE(Type, ClassName) \
190  XN_DECLARE_QUEUE_DECL(, Type, ClassName)
191 
192 #endif // _XN_QUEUE_H