![]() |
OpenNI 1.5.7
|
00001 /***************************************************************************** 00002 * * 00003 * OpenNI 1.x Alpha * 00004 * Copyright (C) 2012 PrimeSense Ltd. * 00005 * * 00006 * This file is part of OpenNI. * 00007 * * 00008 * Licensed under the Apache License, Version 2.0 (the "License"); * 00009 * you may not use this file except in compliance with the License. * 00010 * You may obtain a copy of the License at * 00011 * * 00012 * http://www.apache.org/licenses/LICENSE-2.0 * 00013 * * 00014 * Unless required by applicable law or agreed to in writing, software * 00015 * distributed under the License is distributed on an "AS IS" BASIS, * 00016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 00017 * See the License for the specific language governing permissions and * 00018 * limitations under the License. * 00019 * * 00020 *****************************************************************************/ 00021 #ifndef _XN_CYCLIC_QUEUE_T_H_ 00022 #define _XN_CYCLIC_QUEUE_T_H_ 00023 00024 //--------------------------------------------------------------------------- 00025 // Includes 00026 //--------------------------------------------------------------------------- 00027 #include "XnQueueT.h" 00028 00029 //--------------------------------------------------------------------------- 00030 // Code 00031 //--------------------------------------------------------------------------- 00032 00033 template<class T, XnUInt32 TDefaultMaxDepth, class TAlloc = XnLinkedNodeDefaultAllocatorT<T> > 00034 class XnCyclicQueueT : protected XnQueueT<T, TAlloc> 00035 { 00036 public: 00037 typedef XnQueueT<T, TAlloc> Base; 00038 00039 XnCyclicQueueT(XnUInt32 nMaxDepth = TDefaultMaxDepth) : Base(), m_nMaxDepth(nMaxDepth) {} 00040 00041 XnCyclicQueueT(const XnCyclicQueueT& other) : Base(other) 00042 { 00043 *this = other; 00044 } 00045 00046 XnCyclicQueueT& operator=(const XnCyclicQueueT& other) 00047 { 00048 Base::operator=(other); 00049 m_nMaxDepth = other.m_nMaxDepth; 00050 return *this; 00051 } 00052 00053 ~XnCyclicQueueT() {} 00054 00055 using Base::ConstIterator; 00056 using Base::IsEmpty; 00057 using Base::Size; 00058 00059 XnStatus SetMaxSize(XnUInt32 nMaxSize) 00060 { 00061 XnStatus nRetVal = XN_STATUS_OK; 00062 00063 while (Size() > nMaxSize) 00064 { 00065 nRetVal = Remove(this->Begin()); 00066 XN_IS_STATUS_OK(nRetVal); 00067 } 00068 00069 m_nMaxDepth = nMaxSize; 00070 00071 return (XN_STATUS_OK); 00072 } 00073 00074 XnStatus Push(T const& value) 00075 { 00076 XnStatus nRetVal = XN_STATUS_OK; 00077 if (Size() == m_nMaxDepth) 00078 { 00079 nRetVal = Remove(this->Begin()); 00080 XN_IS_STATUS_OK(nRetVal); 00081 } 00082 00083 nRetVal = Base::Push(value); 00084 XN_IS_STATUS_OK(nRetVal); 00085 00086 return (XN_STATUS_OK); 00087 } 00088 00089 using Base::Pop; 00090 using Base::Top; 00091 using Base::Begin; 00092 using Base::End; 00093 00094 protected: 00095 XnUInt32 m_nMaxDepth; 00096 }; 00097 00098 00099 #endif // _XN_CYCLIC_QUEUE_T_H_