OpenNI 1.0.0

XnQueue.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 *                                                                            *
00003 *  OpenNI 1.0 Alpha                                                          *
00004 *  Copyright (C) 2010 PrimeSense Ltd.                                        *
00005 *                                                                            *
00006 *  This file is part of OpenNI.                                              *
00007 *                                                                            *
00008 *  OpenNI is free software: you can redistribute it and/or modify            *
00009 *  it under the terms of the GNU Lesser General Public License as published  *
00010 *  by the Free Software Foundation, either version 3 of the License, or      *
00011 *  (at your option) any later version.                                       *
00012 *                                                                            *
00013 *  OpenNI is distributed in the hope that it will be useful,                 *
00014 *  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00015 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the              *
00016 *  GNU Lesser General Public License for more details.                       *
00017 *                                                                            *
00018 *  You should have received a copy of the GNU Lesser General Public License  *
00019 *  along with OpenNI. If not, see <http://www.gnu.org/licenses/>.            *
00020 *                                                                            *
00021 *****************************************************************************/
00022 
00023 
00024 
00025 
00026 #ifndef _XN_QUEUE_H
00027 #define _XN_QUEUE_H
00028 
00029 //---------------------------------------------------------------------------
00030 // Includes
00031 //---------------------------------------------------------------------------
00032 #include "XnList.h"
00033 
00034 //---------------------------------------------------------------------------
00035 // Types
00036 //---------------------------------------------------------------------------
00040 class XnQueue
00041 {
00042 public:
00046     XnQueue() {}
00050     virtual ~XnQueue() {}
00051 
00055     virtual XnStatus Init()
00056     {
00057         return (XN_STATUS_OK);
00058     }
00059 
00067     virtual XnStatus Push(XnValue const& value)
00068     {
00069         XnStatus nRetVal = XN_STATUS_OK;
00070 
00071         nRetVal = m_List.AddLast(value);
00072         XN_IS_STATUS_OK(nRetVal);
00073 
00074         return (XN_STATUS_OK);
00075     }
00083     virtual XnStatus Pop(XnValue& value)
00084     {
00085         if (IsEmpty())
00086         {
00087             return XN_STATUS_IS_EMPTY;
00088         }
00089 
00090         value = *(m_List.begin());
00091         return m_List.Remove(m_List.begin());
00092     }
00093 
00099     XnValue const& Top() const
00100     {
00101         return *(m_List.begin());
00102     }
00103 
00109     XnValue& Top()
00110     {
00111         return *(m_List.begin());
00112     }
00113 
00117     XnBool IsEmpty() const
00118     {
00119         return m_List.IsEmpty();
00120     }
00121 
00125     virtual XnUInt32 Size() const
00126     {
00127         return m_List.Size();
00128     }
00129 
00130 private:
00132     XnList m_List;
00133 };
00134 
00140 #define XN_DECLARE_QUEUE_WITH_TRANSLATOR_DECL(decl, Type, ClassName, Translator, base)  \
00141     class decl ClassName : public base                                                  \
00142     {                                                                                   \
00143     public:                                                                             \
00144         ~ClassName()                                                                    \
00145         {                                                                               \
00146             /* We do this using Pop() to make sure memory is freed. */                  \
00147             Type dummy;                                                                 \
00148             while (Size() != 0)                                                         \
00149                 Pop(dummy);                                                             \
00150         }                                                                               \
00151         XnStatus Push(Type const& value)                                                \
00152         {                                                                               \
00153             XnValue val = Translator::CreateValueCopy(value);                           \
00154             XnStatus nRetVal = base::Push(val);                                         \
00155             if (nRetVal != XN_STATUS_OK)                                                \
00156             {                                                                           \
00157                 Translator::FreeValue(val);                                             \
00158                 return (nRetVal);                                                       \
00159             }                                                                           \
00160             return XN_STATUS_OK;                                                        \
00161         }                                                                               \
00162         XnStatus Pop(Type& value)                                                       \
00163         {                                                                               \
00164             XnValue val;                                                                \
00165             XnStatus nRetVal = base::Pop(val);                                          \
00166             if (nRetVal != XN_STATUS_OK) return (nRetVal);                              \
00167             value = Translator::GetFromValue(val);                                      \
00168             return XN_STATUS_OK;                                                        \
00169         }                                                                               \
00170         inline Type const& Top() const { return Translator::GetFromValue(base::Top()); }\
00171         inline Type& Top() { return Translator::GetFromValue(base::Top()); }            \
00172     };
00173 
00179 #define XN_DECLARE_QUEUE_WITH_TRANSLATOR(Type, ClassName, Translator, base)             \
00180     XN_DECLARE_QUEUE_WITH_TRANSLATOR_DECL(, Type, ClassName, Translator, base)
00181 
00186 #define XN_DECLARE_QUEUE_DECL(decl, Type, ClassName)                                                    \
00187     XN_DECLARE_DEFAULT_VALUE_TRANSLATOR_DECL(decl, Type, XN_DEFAULT_TRANSLATOR_NAME(ClassName))         \
00188     XN_DECLARE_QUEUE_WITH_TRANSLATOR_DECL(decl, Type, ClassName, XN_DEFAULT_TRANSLATOR_NAME(ClassName), XnQueue)
00189 
00193 #define XN_DECLARE_QUEUE(Type, ClassName)       \
00194     XN_DECLARE_QUEUE_DECL(, Type, ClassName)
00195 
00196 #endif // _XN_QUEUE_H