Qt 4.8
Public Functions | Properties | List of all members
QRingBuffer< T > Class Template Reference

#include <qringbuffer_p.h>

Public Functions

void append (const QByteArray &qba)
 
bool canReadLine () const
 
void chop (int bytes)
 
void clear ()
 
const T & dequeue ()
 
void enqueue (const T &x)
 
void free (int bytes)
 
int getChar ()
 
const T & head () const
 
int indexOf (char c) const
 
int indexOf (char c, int maxLength) const
 
bool isEmpty () const
 
bool isEmpty () const
 
int nextDataBlockSize () const
 
QByteArray peek (int maxLength) const
 
void putChar (char c)
 
 QRingBuffer (int growth=4096)
 
 QRingBuffer ()
 
int read (char *data, int maxLength)
 
QByteArray read (int maxLength)
 
QByteArray read ()
 
QByteArray readAll ()
 
int readLine (char *data, int maxLength)
 
const char * readPointer () const
 
const char * readPointerAtPosition (qint64 pos, qint64 &length) const
 
bool reallocate (int capacity)
 
char * reserve (int bytes)
 
int size () const
 
int skip (int length)
 
void truncate (int pos)
 
void ungetChar (char c)
 
 ~QRingBuffer ()
 

Properties

int basicBlockSize
 
QList< QByteArraybuffers
 
int bufferSize
 
int head
 
T * m_array
 
int m_capacity
 
int m_head
 
int m_size
 
int tail
 
int tailBuffer
 

Detailed Description

template<class T>
class QRingBuffer< T >

Definition at line 61 of file qringbuffer_p.h.

Constructors and Destructors

◆ QRingBuffer() [1/2]

template<class T >
QRingBuffer< T >::QRingBuffer ( int  growth = 4096)
inline

Definition at line 64 of file qringbuffer_p.h.

64  : basicBlockSize(growth) {
65  buffers << QByteArray();
66  clear();
67  }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QList< QByteArray > buffers

◆ QRingBuffer() [2/2]

template<class T >
QRingBuffer< T >::QRingBuffer ( )
inline

Definition at line 1246 of file qtriangulator.cpp.

◆ ~QRingBuffer()

template<class T >
QRingBuffer< T >::~QRingBuffer ( )
inline

Definition at line 1247 of file qtriangulator.cpp.

1247 {if (m_array) delete[] m_array;}

Functions

◆ append()

template<class T >
void QRingBuffer< T >::append ( const QByteArray qba)
inline

Definition at line 382 of file qringbuffer_p.h.

Referenced by QNetworkReplyImplPrivate::setup().

382  {
383  buffers[tailBuffer].resize(tail);
384  buffers << qba;
385  ++tailBuffer;
386  tail = qba.length();
387  bufferSize += qba.length();
388  }
QList< QByteArray > buffers

◆ canReadLine()

template<class T >
bool QRingBuffer< T >::canReadLine ( ) const
inline

Definition at line 437 of file qringbuffer_p.h.

Referenced by QProcess::canReadLine().

437  {
438  return indexOf('\n') != -1;
439  }
int indexOf(char c) const

◆ chop()

template<class T >
void QRingBuffer< T >::chop ( int  bytes)
inline

Definition at line 197 of file qringbuffer_p.h.

Referenced by QNetworkReplyImplPrivate::_q_bufferOutgoingData(), QAbstractSocketPrivate::readFromSocket(), and QRingBuffer< T >::truncate().

197  {
198  bufferSize -= bytes;
199  if (bufferSize < 0)
200  bufferSize = 0;
201 
202  for (;;) {
203  // special case: head and tail are in the same buffer
204  if (tailBuffer == 0) {
205  tail -= bytes;
206  if (tail <= head)
207  tail = head = 0;
208  return;
209  }
210 
211  if (bytes <= tail) {
212  tail -= bytes;
213  return;
214  }
215 
216  bytes -= tail;
218 
219  --tailBuffer;
221  }
222 
223  if (isEmpty())
224  clear(); // try to minify/squeeze us
225  }
bool isEmpty() const
const T & head() const
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QList< QByteArray > buffers
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480

◆ clear()

template<class T >
void QRingBuffer< T >::clear ( )
inline

Definition at line 260 of file qringbuffer_p.h.

Referenced by QRingBuffer< T >::chop(), QSslSocketPrivate::createPlainSocket(), QRingBuffer< T >::free(), QSslSocketPrivate::init(), and QRingBuffer< T >::QRingBuffer().

260  {
261  buffers.erase(buffers.begin() + 1, buffers.end());
262  buffers[0].resize(0);
263  buffers[0].squeeze();
264 
265  head = tail = 0;
266  tailBuffer = 0;
267  bufferSize = 0;
268  }
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
const T & head() const
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
iterator erase(iterator pos)
Removes the item associated with the iterator pos from the list, and returns an iterator to the next ...
Definition: qlist.h:464
QList< QByteArray > buffers

◆ dequeue()

template<class T >
const T & QRingBuffer< T >::dequeue ( )
inline

Definition at line 1285 of file qtriangulator.cpp.

1286 {
1287  Q_ASSERT(m_size > 0);
1288  Q_ASSERT(m_array);
1290  int index = m_head;
1291  if (++m_head >= m_capacity)
1292  m_head -= m_capacity;
1293  --m_size;
1294  return m_array[index];
1295 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
quint16 index

◆ enqueue()

template<class T >
void QRingBuffer< T >::enqueue ( const T &  x)
inline

Definition at line 1298 of file qtriangulator.cpp.

1299 {
1300  if (m_size == m_capacity)
1301  reallocate(qMax(2 * m_capacity, 64));
1302  int index = m_head + m_size;
1303  if (index >= m_capacity)
1304  index -= m_capacity;
1305  m_array[index] = x;
1306  ++m_size;
1307 }
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
bool reallocate(int capacity)
quint16 index

◆ free()

template<class T >
void QRingBuffer< T >::free ( int  bytes)
inline

Definition at line 123 of file qringbuffer_p.h.

Referenced by _qfile_writeData(), QAbstractSocketPrivate::flush(), QRingBuffer< T >::getChar(), QRingBuffer< T >::read(), QProcess::readData(), QRingBuffer< T >::readLine(), and QSslSocketBackendPrivate::transmit().

123  {
124  bufferSize -= bytes;
125  if (bufferSize < 0)
126  bufferSize = 0;
127 
128  for (;;) {
129  int nextBlockSize = nextDataBlockSize();
130  if (bytes < nextBlockSize) {
131  head += bytes;
132  if (head == tail && tailBuffer == 0)
133  head = tail = 0;
134  break;
135  }
136 
137  bytes -= nextBlockSize;
138  if (buffers.count() == 1) {
139  if (buffers.at(0).size() != basicBlockSize)
140  buffers[0].resize(basicBlockSize);
141  head = tail = 0;
142  tailBuffer = 0;
143  break;
144  }
145 
146  buffers.removeAt(0);
147  --tailBuffer;
148  head = 0;
149  }
150 
151  if (isEmpty())
152  clear(); // try to minify/squeeze us
153  }
int nextDataBlockSize() const
Definition: qringbuffer_p.h:69
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
bool isEmpty() const
const T & head() const
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QList< QByteArray > buffers
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480

◆ getChar()

template<class T >
int QRingBuffer< T >::getChar ( )
inline

Definition at line 231 of file qringbuffer_p.h.

Referenced by QProcess::readData().

231  {
232  if (isEmpty())
233  return -1;
234  char c = *readPointer();
235  free(1);
236  return int(uchar(c));
237  }
unsigned char c[8]
Definition: qnumeric_p.h:62
const char * readPointer() const
Definition: qringbuffer_p.h:73
bool isEmpty() const
unsigned char uchar
Definition: qglobal.h:994
void free(int bytes)

◆ head()

template<class T >
const T& QRingBuffer< T >::head ( ) const
inline

◆ indexOf() [1/2]

template<class T >
int QRingBuffer< T >::indexOf ( char  c) const
inline

Definition at line 270 of file qringbuffer_p.h.

Referenced by QRingBuffer< T >::canReadLine(), and QRingBuffer< T >::readLine().

270  {
271  int index = 0;
272  for (int i = 0; i < buffers.size(); ++i) {
273  int start = 0;
274  int end = buffers.at(i).size();
275 
276  if (i == 0)
277  start = head;
278  if (i == tailBuffer)
279  end = tail;
280  const char *ptr = buffers.at(i).data() + start;
281  for (int j = start; j < end; ++j) {
282  if (*ptr++ == c)
283  return index;
284  ++index;
285  }
286  }
287  return -1;
288  }
unsigned char c[8]
Definition: qnumeric_p.h:62
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
const T & head() const
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
const T * ptr(const T &t)
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
quint16 index
QList< QByteArray > buffers
static const KeyPair *const end

◆ indexOf() [2/2]

template<class T >
int QRingBuffer< T >::indexOf ( char  c,
int  maxLength 
) const
inline

Definition at line 290 of file qringbuffer_p.h.

290  {
291  int index = 0;
292  int remain = qMin(size(), maxLength);
293  for (int i = 0; remain && i < buffers.size(); ++i) {
294  int start = 0;
295  int end = buffers.at(i).size();
296 
297  if (i == 0)
298  start = head;
299  if (i == tailBuffer)
300  end = tail;
301  if (remain < end - start) {
302  end = start + remain;
303  remain = 0;
304  } else {
305  remain -= end - start;
306  }
307  const char *ptr = buffers.at(i).data() + start;
308  for (int j = start; j < end; ++j) {
309  if (*ptr++ == c)
310  return index;
311  ++index;
312  }
313  }
314  return -1;
315  }
unsigned char c[8]
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
const T & head() const
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
const T * ptr(const T &t)
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
quint16 index
QList< QByteArray > buffers
static const KeyPair *const end
int size() const

◆ isEmpty() [1/2]

template<class T >
bool QRingBuffer< T >::isEmpty ( ) const
inline

◆ isEmpty() [2/2]

template<class T >
bool QRingBuffer< T >::isEmpty ( ) const
inline

Definition at line 1252 of file qtriangulator.cpp.

1252 {return m_size == 0;}

◆ nextDataBlockSize()

template<class T >
int QRingBuffer< T >::nextDataBlockSize ( ) const
inline

Definition at line 69 of file qringbuffer_p.h.

Referenced by _qfile_writeData(), QAbstractSocketPrivate::flush(), QRingBuffer< T >::free(), QRingBuffer< T >::read(), QProcess::readData(), QRingBuffer< T >::readLine(), QRingBuffer< T >::readPointerAtPosition(), and QSslSocketBackendPrivate::transmit().

69  {
70  return (tailBuffer == 0 ? tail : buffers.first().size()) - head;
71  }
const T & head() const
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QList< QByteArray > buffers

◆ peek()

template<class T >
QByteArray QRingBuffer< T >::peek ( int  maxLength) const
inline

Definition at line 390 of file qringbuffer_p.h.

390  {
391  int bytesToRead = qMin(size(), maxLength);
392  if(maxLength <= 0)
393  return QByteArray();
394  QByteArray ret;
395  ret.resize(bytesToRead);
396  int readSoFar = 0;
397  for (int i = 0; readSoFar < bytesToRead && i < buffers.size(); ++i) {
398  int start = 0;
399  int end = buffers.at(i).size();
400  if (i == 0)
401  start = head;
402  if (i == tailBuffer)
403  end = tail;
404  const int len = qMin(ret.size()-readSoFar, end-start);
405  memcpy(ret.data()+readSoFar, buffers.at(i).constData()+start, len);
406  readSoFar += len;
407  }
408  Q_ASSERT(readSoFar == ret.size());
409  return ret;
410  }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const T & head() const
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
void resize(int size)
Sets the size of the byte array to size bytes.
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QList< QByteArray > buffers
static const KeyPair *const end
int size() const

◆ putChar()

template<class T >
void QRingBuffer< T >::putChar ( char  c)
inline

Definition at line 239 of file qringbuffer_p.h.

239  {
240  char *ptr = reserve(1);
241  *ptr = c;
242  }
unsigned char c[8]
Definition: qnumeric_p.h:62
char * reserve(int bytes)
const T * ptr(const T &t)

◆ read() [1/3]

template<class T >
int QRingBuffer< T >::read ( char *  data,
int  maxLength 
)
inline

Definition at line 317 of file qringbuffer_p.h.

317  {
318  int bytesToRead = qMin(size(), maxLength);
319  int readSoFar = 0;
320  while (readSoFar < bytesToRead) {
321  const char *ptr = readPointer();
322  int bytesToReadFromThisBlock = qMin(bytesToRead - readSoFar, nextDataBlockSize());
323  if (data)
324  memcpy(data + readSoFar, ptr, bytesToReadFromThisBlock);
325  readSoFar += bytesToReadFromThisBlock;
326  free(bytesToReadFromThisBlock);
327  }
328  return readSoFar;
329  }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
const char * readPointer() const
Definition: qringbuffer_p.h:73
int nextDataBlockSize() const
Definition: qringbuffer_p.h:69
static const char * data(const QByteArray &arr)
const T * ptr(const T &t)
void free(int bytes)
int size() const

◆ read() [2/3]

template<class T >
QByteArray QRingBuffer< T >::read ( int  maxLength)
inline

Definition at line 331 of file qringbuffer_p.h.

331  {
332  QByteArray tmp;
333  tmp.resize(qMin(maxLength, size()));
334  read(tmp.data(), tmp.size());
335  return tmp;
336  }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QByteArray read()
void resize(int size)
Sets the size of the byte array to size bytes.
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
int size() const

◆ read() [3/3]

template<class T >
QByteArray QRingBuffer< T >::read ( )
inline

Definition at line 343 of file qringbuffer_p.h.

Referenced by QRingBuffer< T >::read(), QRingBuffer< T >::readAll(), QRingBuffer< T >::readLine(), and QRingBuffer< T >::skip().

343  {
344  if (bufferSize == 0)
345  return QByteArray();
346 
347  // multiple buffers, just take the first one
348  if (head == 0 && tailBuffer != 0) {
349  QByteArray qba = buffers.takeFirst();
350  --tailBuffer;
351  bufferSize -= qba.length();
352  return qba;
353  }
354 
355  // one buffer with good value for head. Just take it.
356  if (head == 0 && tailBuffer == 0) {
357  QByteArray qba = buffers.takeFirst();
358  qba.resize(tail);
359  buffers << QByteArray();
360  bufferSize = 0;
361  tail = 0;
362  return qba;
363  }
364 
365  // Bad case: We have to memcpy.
366  // We can avoid by initializing the QRingBuffer with basicBlockSize of 0
367  // and only using this read() function.
370  head = 0;
371  if (tailBuffer == 0) {
372  buffers << QByteArray();
373  tail = 0;
374  } else {
375  --tailBuffer;
376  }
377  bufferSize -= qba.length();
378  return qba;
379  }
const char * readPointer() const
Definition: qringbuffer_p.h:73
int nextDataBlockSize() const
Definition: qringbuffer_p.h:69
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const T & head() const
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
void removeFirst()
Removes the first item in the list.
Definition: qlist.h:286
int length() const
Same as size().
Definition: qbytearray.h:356
void resize(int size)
Sets the size of the byte array to size bytes.
QList< QByteArray > buffers

◆ readAll()

template<class T >
QByteArray QRingBuffer< T >::readAll ( )
inline

Definition at line 338 of file qringbuffer_p.h.

338  {
339  return read(size());
340  }
QByteArray read()
int size() const

◆ readLine()

template<class T >
int QRingBuffer< T >::readLine ( char *  data,
int  maxLength 
)
inline

Definition at line 416 of file qringbuffer_p.h.

416  {
417  int index = indexOf('\n');
418  if (index == -1)
419  return read(data, maxLength);
420  if (maxLength <= 0)
421  return -1;
422 
423  int readSoFar = 0;
424  while (readSoFar < index + 1 && readSoFar < maxLength - 1) {
425  int bytesToRead = qMin((index + 1) - readSoFar, nextDataBlockSize());
426  bytesToRead = qMin(bytesToRead, (maxLength - 1) - readSoFar);
427  memcpy(data + readSoFar, readPointer(), bytesToRead);
428  readSoFar += bytesToRead;
429  free(bytesToRead);
430  }
431 
432  // Terminate it.
433  data[readSoFar] = '\0';
434  return readSoFar;
435  }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
const char * readPointer() const
Definition: qringbuffer_p.h:73
int nextDataBlockSize() const
Definition: qringbuffer_p.h:69
static const char * data(const QByteArray &arr)
void free(int bytes)
QByteArray read()
quint16 index
int indexOf(char c) const

◆ readPointer()

template<class T >
const char* QRingBuffer< T >::readPointer ( ) const
inline

Definition at line 73 of file qringbuffer_p.h.

Referenced by _qfile_writeData(), QAbstractSocketPrivate::flush(), QRingBuffer< T >::getChar(), QRingBuffer< T >::read(), QProcess::readData(), QRingBuffer< T >::readLine(), and QSslSocketBackendPrivate::transmit().

73  {
74  return buffers.isEmpty() ? 0 : (buffers.first().constData() + head);
75  }
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
const T & head() const
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QList< QByteArray > buffers

◆ readPointerAtPosition()

template<class T >
const char* QRingBuffer< T >::readPointerAtPosition ( qint64  pos,
qint64 length 
) const
inline

Definition at line 80 of file qringbuffer_p.h.

Referenced by QNonContiguousByteDeviceRingBufferImpl::readPointer().

80  {
81  if (buffers.isEmpty()) {
82  length = 0;
83  return 0;
84  }
85 
86  if (pos >= bufferSize) {
87  length = 0;
88  return 0;
89  }
90 
91  // special case: it is in the first buffer
92  int nextDataBlockSizeValue = nextDataBlockSize();
93  if (pos - head < nextDataBlockSizeValue) {
94  length = nextDataBlockSizeValue - pos;
95  return buffers.at(0).constData() + head + pos;
96  }
97 
98  // special case: we only had one buffer and tried to read over it
99  if (buffers.length() == 1) {
100  length = 0;
101  return 0;
102  }
103 
104  // skip the first
105  pos -= nextDataBlockSizeValue;
106 
107  // normal case: it is somewhere in the second to the-one-before-the-tailBuffer
108  for (int i = 1; i < tailBuffer; i++) {
109  if (pos >= buffers[i].size()) {
110  pos -= buffers[i].size();
111  continue;
112  }
113 
114  length = buffers[i].length() - pos;
115  return buffers[i].constData() + pos;
116  }
117 
118  // it is in the tail buffer
119  length = tail - pos;
120  return buffers[tailBuffer].constData() + pos;
121  }
int nextDataBlockSize() const
Definition: qringbuffer_p.h:69
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
const T & head() const
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int length() const
This function is identical to count().
Definition: qlist.h:281
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QList< QByteArray > buffers
int size() const

◆ reallocate()

template<class T >
bool QRingBuffer< T >::reallocate ( int  capacity)

Definition at line 1261 of file qtriangulator.cpp.

1262 {
1263  T *oldArray = m_array;
1264  m_array = new T[capacity];
1265  if (m_array) {
1266  if (oldArray) {
1267  if (m_head + m_size > m_capacity) {
1268  memcpy(m_array, oldArray + m_head, (m_capacity - m_head) * sizeof(T));
1269  memcpy(m_array + (m_capacity - m_head), oldArray, (m_head + m_size - m_capacity) * sizeof(T));
1270  } else {
1271  memcpy(m_array, oldArray + m_head, m_size * sizeof(T));
1272  }
1273  delete[] oldArray;
1274  }
1275  m_capacity = capacity;
1276  m_head = 0;
1277  return true;
1278  } else {
1279  m_array = oldArray;
1280  return false;
1281  }
1282 }

◆ reserve()

template<class T >
char* QRingBuffer< T >::reserve ( int  bytes)
inline

Definition at line 155 of file qringbuffer_p.h.

Referenced by QNetworkReplyImplPrivate::_q_bufferOutgoingData(), QHttpPrivate::_q_slotReadyRead(), QRingBuffer< T >::putChar(), QAbstractSocketPrivate::readFromSocket(), QLocalSocketPrivate::startAsyncRead(), and QSslSocketBackendPrivate::transmit().

155  {
156  // if this is a fresh empty QRingBuffer
157  if (bufferSize == 0) {
158  buffers[0].resize(qMax(basicBlockSize, bytes));
159  bufferSize += bytes;
160  tail = bytes;
161  return buffers[tailBuffer].data();
162  }
163 
164  bufferSize += bytes;
165 
166  // if there is already enough space, simply return.
167  if (tail + bytes <= buffers.at(tailBuffer).size()) {
168  char *writePtr = buffers[tailBuffer].data() + tail;
169  tail += bytes;
170  return writePtr;
171  }
172 
173  // if our buffer isn't half full yet, simply resize it.
174  if (tail < buffers.at(tailBuffer).size() / 2) {
175  buffers[tailBuffer].resize(tail + bytes);
176  char *writePtr = buffers[tailBuffer].data() + tail;
177  tail += bytes;
178  return writePtr;
179  }
180 
181  // shrink this buffer to its current size
182  buffers[tailBuffer].resize(tail);
183 
184  // create a new QByteArray with the right size
185  buffers << QByteArray();
186  ++tailBuffer;
187  buffers[tailBuffer].resize(qMax(basicBlockSize, bytes));
188  tail = bytes;
189  return buffers[tailBuffer].data();
190  }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QList< QByteArray > buffers

◆ size()

template<class T >
int QRingBuffer< T >::size ( ) const
inline

◆ skip()

template<class T >
int QRingBuffer< T >::skip ( int  length)
inline

Definition at line 412 of file qringbuffer_p.h.

412  {
413  return read(0, length);
414  }
QByteArray read()

◆ truncate()

template<class T >
void QRingBuffer< T >::truncate ( int  pos)
inline

Definition at line 192 of file qringbuffer_p.h.

Referenced by QLocalSocketPrivate::completeAsyncRead().

192  {
193  if (pos < size())
194  chop(size() - pos);
195  }
void chop(int bytes)
int size() const

◆ ungetChar()

template<class T >
void QRingBuffer< T >::ungetChar ( char  c)
inline

Definition at line 244 of file qringbuffer_p.h.

244  {
245  --head;
246  if (head < 0) {
248  buffers[0].resize(basicBlockSize);
249  head = basicBlockSize - 1;
250  ++tailBuffer;
251  }
252  buffers[0][head] = c;
253  ++bufferSize;
254  }
unsigned char c[8]
Definition: qnumeric_p.h:62
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const T & head() const
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
QList< QByteArray > buffers

Properties

◆ basicBlockSize

template<class T >
int QRingBuffer< T >::basicBlockSize
private

◆ buffers

template<class T >
QList<QByteArray> QRingBuffer< T >::buffers
private

◆ bufferSize

template<class T >
int QRingBuffer< T >::bufferSize
private

◆ head

template<class T >
int QRingBuffer< T >::head
private

Definition at line 443 of file qringbuffer_p.h.

◆ m_array

template<class T >
T* QRingBuffer< T >::m_array
private

Definition at line 1254 of file qtriangulator.cpp.

◆ m_capacity

template<class T >
int QRingBuffer< T >::m_capacity
private

Definition at line 1257 of file qtriangulator.cpp.

◆ m_head

template<class T >
int QRingBuffer< T >::m_head
private

Definition at line 1255 of file qtriangulator.cpp.

◆ m_size

template<class T >
int QRingBuffer< T >::m_size
private

Definition at line 1256 of file qtriangulator.cpp.

◆ tail

template<class T >
int QRingBuffer< T >::tail
private

◆ tailBuffer

template<class T >
int QRingBuffer< T >::tailBuffer
private

The documentation for this class was generated from the following files: