42 #ifndef QRINGBUFFER_P_H
43 #define QRINGBUFFER_P_H
56 #include <QtCore/qbytearray.h>
57 #include <QtCore/qlist.h>
97 if(pos -
head < nextDataBlockSizeValue)
99 length = nextDataBlockSizeValue - pos;
111 pos -= nextDataBlockSizeValue;
123 return buffers[
i].constData() + pos;
140 if(bytes < nextBlockSize)
148 bytes -= nextBlockSize;
259 return int(uchar(c));
310 const char * ptr =
buffers.at(
i).data() + start;
311 for(
int j = start;
j < end; ++
j)
324 int remain = qMin(
size(), maxLength);
325 for(
int i = 0; remain &&
i <
buffers.size(); ++
i)
334 if(remain < end - start)
336 end = start + remain;
341 remain -= end - start;
343 const char * ptr =
buffers.at(
i).data() + start;
344 for(
int j = start;
j < end; ++
j)
354 inline int read(
char * data,
int maxLength)
356 int bytesToRead = qMin(
size(), maxLength);
358 while(readSoFar < bytesToRead)
361 int bytesToReadFromThisBlock = qMin(bytesToRead - readSoFar,
nextDataBlockSize());
363 memcpy(data + readSoFar, ptr, bytesToReadFromThisBlock);
364 readSoFar += bytesToReadFromThisBlock;
365 free(bytesToReadFromThisBlock);
370 inline QByteArray
read(
int maxLength)
373 tmp.resize(qMin(maxLength,
size()));
374 read(tmp.data(), tmp.size());
392 QByteArray qba =
buffers.takeFirst();
401 QByteArray qba =
buffers.takeFirst();
429 inline void append(
const QByteArray & qba)
438 inline QByteArray
peek(
int maxLength)
const
440 int bytesToRead = qMin(
size(), maxLength);
444 ret.resize(bytesToRead);
446 for(
int i = 0; readSoFar < bytesToRead &&
i <
buffers.size(); ++
i)
454 const int len = qMin(ret.size() - readSoFar, end - start);
455 memcpy(ret.data() + readSoFar,
buffers.at(
i).constData() + start, len);
458 Q_ASSERT(readSoFar == ret.size());
464 return read(0, length);
471 return read(data, maxLength);
476 while(readSoFar < index + 1 && readSoFar < maxLength - 1)
479 bytesToRead = qMin(bytesToRead, (maxLength - 1) - readSoFar);
480 memcpy(data + readSoFar,
readPointer(), bytesToRead);
481 readSoFar += bytesToRead;
486 data[readSoFar] =
'\0';
503 #endif // QRINGBUFFER_P_H
void chop(int bytes)
Definition: qringbuffer_p.h:214
void truncate(int pos)
Definition: qringbuffer_p.h:208
bool canReadLine() const
Definition: qringbuffer_p.h:490
int head
Definition: qringbuffer_p.h:497
int getChar()
Definition: qringbuffer_p.h:253
char s char s char s s s s s char char c s *s c s s s d c s *s d c d d d d c
Definition: KviIrcNumericCodes.h:391
void putChar(char c)
Definition: qringbuffer_p.h:262
int size() const
Definition: qringbuffer_p.h:282
bool isEmpty() const
Definition: qringbuffer_p.h:248
int tail
Definition: qringbuffer_p.h:497
int nextDataBlockSize() const
Definition: qringbuffer_p.h:68
QByteArray read()
Definition: qringbuffer_p.h:384
void clear()
Definition: qringbuffer_p.h:287
int skip(int length)
Definition: qringbuffer_p.h:462
void ungetChar(char c)
Definition: qringbuffer_p.h:268
#define i
Definition: detector.cpp:73
Definition: qringbuffer_p.h:59
void free(int bytes)
Definition: qringbuffer_p.h:131
int readLine(char *data, int maxLength)
Definition: qringbuffer_p.h:467
int indexOf(char c, int maxLength) const
Definition: qringbuffer_p.h:321
void append(const QByteArray &qba)
Definition: qringbuffer_p.h:429
int read(char *data, int maxLength)
Definition: qringbuffer_p.h:354
QByteArray peek(int maxLength) const
Definition: qringbuffer_p.h:438
const char * readPointerAtPosition(qint64 pos, qint64 &length) const
Definition: qringbuffer_p.h:81
#define j
Definition: detector.cpp:74
int tailBuffer
Definition: qringbuffer_p.h:498
int bufferSize
Definition: qringbuffer_p.h:500
QByteArray read(int maxLength)
Definition: qringbuffer_p.h:370
const char * readPointer() const
Definition: qringbuffer_p.h:73
QList< QByteArray > buffers
Definition: qringbuffer_p.h:496
int basicBlockSize
Definition: qringbuffer_p.h:499
QByteArray readAll()
Definition: qringbuffer_p.h:378
int indexOf(char c) const
Definition: qringbuffer_p.h:298
char * reserve(int bytes)
Definition: qringbuffer_p.h:167
QRingBuffer(int growth=4096)
Definition: qringbuffer_p.h:62