Home | nevrax.com |
|
buf_fifo.hGo to the documentation of this file.00001 00007 /* Copyright, 2001 Nevrax Ltd. 00008 * 00009 * This file is part of NEVRAX NEL. 00010 * NEVRAX NEL is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2, or (at your option) 00013 * any later version. 00014 00015 * NEVRAX NEL is distributed in the hope that it will be useful, but 00016 * WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 * General Public License for more details. 00019 00020 * You should have received a copy of the GNU General Public License 00021 * along with NEVRAX NEL; see the file COPYING. If not, write to the 00022 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 00023 * MA 02111-1307, USA. 00024 */ 00025 00026 #ifndef NL_BUF_FIFO_H 00027 #define NL_BUF_FIFO_H 00028 00029 #include "nel/misc/types_nl.h" 00030 00031 #include <vector> 00032 00033 #include "nel/misc/time_nl.h" 00034 #include "nel/misc/mem_stream.h" 00035 00036 00037 namespace NLMISC { 00038 00039 00064 class CBufFIFO 00065 { 00066 public: 00067 00068 CBufFIFO (); 00069 ~CBufFIFO (); 00070 00072 void push (const std::vector<uint8> &buffer) { push (&buffer[0], buffer.size()); } 00073 00074 void push (const NLMISC::CMemStream &buffer) { push (buffer.buffer(), buffer.length()); } 00075 00076 void push (const uint8 *buffer, uint32 size); 00077 00079 void push (const std::vector<uint8> &buffer1, const std::vector<uint8> &buffer2); 00080 00082 void front (std::vector<uint8> &buffer); 00083 00084 void front (NLMISC::CMemStream &buffer); 00085 00086 void front (uint8 *&buffer, uint32 &size); 00087 00090 uint8 frontLast (); 00091 00092 00094 void pop (); 00095 00097 void resize (uint32 size); 00098 00100 bool empty () { return _Empty; } 00101 00102 00104 void clear (); 00105 00107 uint32 size (); 00108 00110 void display (); 00111 00113 void displayStats (); 00114 00115 private: 00116 00117 typedef uint32 TFifoSize; 00118 00119 // pointer to the big buffer 00120 uint8 *_Buffer; 00121 // size of the big buffer 00122 uint32 _BufferSize; 00123 00124 // true if the bufffer is empty 00125 bool _Empty; 00126 00127 // head of the FIFO 00128 uint8 *_Head; 00129 // tail of the FIFO 00130 uint8 *_Tail; 00131 // pointer to the rewinder of the FIFO 00132 uint8 *_Rewinder; 00133 00134 // return true if we can put size bytes on the buffer 00135 // return false if we have to resize 00136 bool canFit (uint32 size); 00137 00138 00139 // statisics of the FIFO 00140 uint32 _BiggestBlock; 00141 uint32 _SmallestBlock; 00142 uint32 _BiggestBuffer; 00143 uint32 _SmallestBuffer; 00144 uint32 _Pushed ; 00145 uint32 _Fronted; 00146 uint32 _Resized; 00147 TTicks _PushedTime; 00148 TTicks _FrontedTime; 00149 TTicks _ResizedTime; 00150 }; 00151 00152 00153 } // NLMISC 00154 00155 00156 #endif // NL_BUF_FIFO_H 00157 00158 /* End of buf_fifo.h */ |