OpenNI 1.5.4: XnQueue.h Source File

OpenNI

OpenNI 1.5.4
XnQueue.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 *                                                                           *
00003 *  OpenNI 1.x Alpha                                                         *
00004 *  Copyright (C) 2011 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 #ifndef _XN_QUEUE_H
00023 #define _XN_QUEUE_H
00024 
00025 //---------------------------------------------------------------------------
00026 // Includes
00027 //---------------------------------------------------------------------------
00028 #include "XnList.h"
00029 
00030 //---------------------------------------------------------------------------
00031 // Types
00032 //---------------------------------------------------------------------------
00036 class XnQueue
00037 {
00038 public:
00042     XnQueue() {}
00046     virtual ~XnQueue() {}
00047 
00051     virtual XnStatus Init()
00052     {
00053         return (XN_STATUS_OK);
00054     }
00055 
00063     virtual XnStatus Push(XnValue const& value)
00064     {
00065         XnStatus nRetVal = XN_STATUS_OK;
00066 
00067         nRetVal = m_List.AddLast(value);
00068         XN_IS_STATUS_OK(nRetVal);
00069 
00070         return (XN_STATUS_OK);
00071     }
00079     virtual XnStatus Pop(XnValue& value)
00080     {
00081         if (IsEmpty())
00082         {
00083             return XN_STATUS_IS_EMPTY;
00084         }
00085 
00086         value = *(m_List.begin());
00087         return m_List.Remove(m_List.begin());
00088     }
00089 
00095     XnValue const& Top() const
00096     {
00097         return *(m_List.begin());
00098     }
00099 
00105     XnValue& Top()
00106     {
00107         return *(m_List.begin());
00108     }
00109 
00113     XnBool IsEmpty() const
00114     {
00115         return m_List.IsEmpty();
00116     }
00117 
00121     virtual XnUInt32 Size() const
00122     {
00123         return m_List.Size();
00124     }
00125 
00126 private:
00127     XN_DISABLE_COPY_AND_ASSIGN(XnQueue);
00128 
00130     XnList m_List;
00131 };
00132 
00138 #define XN_DECLARE_QUEUE_WITH_TRANSLATOR_DECL(decl, Type, ClassName, Translator, base)  \
00139     class decl ClassName : public base                                                  \
00140     {                                                                                   \
00141     public:                                                                             \
00142         ClassName() {}                                                                  \
00143         ~ClassName()                                                                    \
00144         {                                                                               \
00145             /* We do this using Pop() to make sure memory is freed. */                  \
00146             Type dummy;                                                                 \
00147             while (Size() != 0)                                                         \
00148                 Pop(dummy);                                                             \
00149         }                                                                               \
00150         XnStatus Push(Type const& value)                                                \
00151         {                                                                               \
00152             XnValue val = Translator::CreateValueCopy(value);                           \
00153             XnStatus nRetVal = base::Push(val);                                         \
00154             if (nRetVal != XN_STATUS_OK)                                                \
00155             {                                                                           \
00156                 Translator::FreeValue(val);                                             \
00157                 return (nRetVal);                                                       \
00158             }                                                                           \
00159             return XN_STATUS_OK;                                                        \
00160         }                                                                               \
00161         XnStatus Pop(Type& value)                                                       \
00162         {                                                                               \
00163             XnValue val;                                                                \
00164             XnStatus nRetVal = base::Pop(val);                                          \
00165             if (nRetVal != XN_STATUS_OK) return (nRetVal);                              \
00166             value = Translator::GetFromValue(val);                                      \
00167             Translator::FreeValue(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     private:                                                                            \
00173         XN_DISABLE_COPY_AND_ASSIGN(ClassName);                                          \
00174     };
00175 
00181 #define XN_DECLARE_QUEUE_WITH_TRANSLATOR(Type, ClassName, Translator, base)             \
00182     XN_DECLARE_QUEUE_WITH_TRANSLATOR_DECL(, Type, ClassName, Translator, base)
00183 
00188 #define XN_DECLARE_QUEUE_DECL(decl, Type, ClassName)                                                    \
00189     XN_DECLARE_DEFAULT_VALUE_TRANSLATOR_DECL(decl, Type, XN_DEFAULT_TRANSLATOR_NAME(ClassName))         \
00190     XN_DECLARE_QUEUE_WITH_TRANSLATOR_DECL(decl, Type, ClassName, XN_DEFAULT_TRANSLATOR_NAME(ClassName), XnQueue)
00191 
00195 #define XN_DECLARE_QUEUE(Type, ClassName)       \
00196     XN_DECLARE_QUEUE_DECL(, Type, ClassName)
00197 
00198 #endif // _XN_QUEUE_H
Generated on Wed May 16 2012 10:16:05 for OpenNI 1.5.4 by   doxygen 1.7.5.1