Qt 4.8
Public Functions | Private Types | Private Functions | Properties | List of all members
QIODevicePrivateLinearBuffer Class Reference

#include <qiodevice_p.h>

Public Functions

bool canReadLine () const
 
void chop (int size)
 
void clear ()
 
int getChar ()
 
bool isEmpty () const
 
int peek (char *target, int size)
 
 QIODevicePrivateLinearBuffer (int)
 
int read (char *target, int size)
 
QByteArray readAll ()
 
int readLine (char *target, int size)
 
char * reserve (int size)
 
int size () const
 
void skip (int n)
 
void ungetBlock (const char *block, int size)
 
void ungetChar (char c)
 
 ~QIODevicePrivateLinearBuffer ()
 

Private Types

enum  FreeSpacePos { freeSpaceAtStart, freeSpaceAtEnd }
 

Private Functions

void makeSpace (size_t required, FreeSpacePos where)
 

Properties

char * buf
 
size_t capacity
 
char * first
 
int len
 

Detailed Description

Definition at line 72 of file qiodevice_p.h.

Enumerations

◆ FreeSpacePos

Constructors and Destructors

◆ QIODevicePrivateLinearBuffer()

QIODevicePrivateLinearBuffer::QIODevicePrivateLinearBuffer ( int  )
inline

Definition at line 75 of file qiodevice_p.h.

◆ ~QIODevicePrivateLinearBuffer()

QIODevicePrivateLinearBuffer::~QIODevicePrivateLinearBuffer ( )
inline

Definition at line 77 of file qiodevice_p.h.

77  {
78  delete [] buf;
79  }

Functions

◆ canReadLine()

bool QIODevicePrivateLinearBuffer::canReadLine ( ) const
inline

Definition at line 147 of file qiodevice_p.h.

147  {
148  return memchr(first, '\n', len);
149  }

◆ chop()

void QIODevicePrivateLinearBuffer::chop ( int  size)
inline

Definition at line 124 of file qiodevice_p.h.

124  {
125  if (size >= len) {
126  clear();
127  } else {
128  len -= size;
129  }
130  }

◆ clear()

void QIODevicePrivateLinearBuffer::clear ( )
inline

Definition at line 80 of file qiodevice_p.h.

Referenced by chop(), readAll(), and skip().

◆ getChar()

int QIODevicePrivateLinearBuffer::getChar ( )
inline

Definition at line 98 of file qiodevice_p.h.

98  {
99  if (len == 0)
100  return -1;
101  int ch = uchar(*first);
102  len--;
103  first++;
104  return ch;
105  }
unsigned char uchar
Definition: qglobal.h:994

◆ isEmpty()

bool QIODevicePrivateLinearBuffer::isEmpty ( ) const
inline

Definition at line 87 of file qiodevice_p.h.

87  {
88  return len == 0;
89  }

◆ makeSpace()

void QIODevicePrivateLinearBuffer::makeSpace ( size_t  required,
FreeSpacePos  where 
)
inlineprivate

Definition at line 171 of file qiodevice_p.h.

Referenced by reserve(), ungetBlock(), and ungetChar().

171  {
172  size_t newCapacity = qMax(capacity, size_t(QIODEVICE_BUFFERSIZE));
173  while (newCapacity < required)
174  newCapacity *= 2;
175  int moveOffset = (where == freeSpaceAtEnd) ? 0 : newCapacity - len;
176  if (newCapacity > capacity) {
177  // allocate more space
178  char* newBuf = new char[newCapacity];
179  memmove(newBuf + moveOffset, first, len);
180  delete [] buf;
181  buf = newBuf;
182  capacity = newCapacity;
183  } else {
184  // shift any existing data to make space
185  memmove(buf + moveOffset, first, len);
186  }
187  first = buf + moveOffset;
188  }
#define QIODEVICE_BUFFERSIZE
Definition: qiodevice_p.h:68
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217

◆ peek()

int QIODevicePrivateLinearBuffer::peek ( char *  target,
int  size 
)
inline

Definition at line 113 of file qiodevice_p.h.

Referenced by QIODevicePrivate::isSequential(), and QSslSocketPrivate::peek().

113  {
114  int r = qMin(size, len);
115  memcpy(target, first, r);
116  return r;
117  }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215

◆ read()

int QIODevicePrivateLinearBuffer::read ( char *  target,
int  size 
)
inline

Definition at line 106 of file qiodevice_p.h.

106  {
107  int r = qMin(size, len);
108  memcpy(target, first, r);
109  len -= r;
110  first += r;
111  return r;
112  }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215

◆ readAll()

QByteArray QIODevicePrivateLinearBuffer::readAll ( )
inline

Definition at line 131 of file qiodevice_p.h.

131  {
132  char* f = first;
133  int l = len;
134  clear();
135  return QByteArray(f, l);
136  }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QFactoryLoader * l

◆ readLine()

int QIODevicePrivateLinearBuffer::readLine ( char *  target,
int  size 
)
inline

Definition at line 137 of file qiodevice_p.h.

137  {
138  int r = qMin(size, len);
139  char* eol = static_cast<char*>(memchr(first, '\n', r));
140  if (eol)
141  r = 1+(eol-first);
142  memcpy(target, first, r);
143  len -= r;
144  first += r;
145  return int(r);
146  }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215

◆ reserve()

char* QIODevicePrivateLinearBuffer::reserve ( int  size)
inline

Definition at line 118 of file qiodevice_p.h.

118  {
120  char* writePtr = first + len;
121  len += size;
122  return writePtr;
123  }
void makeSpace(size_t required, FreeSpacePos where)
Definition: qiodevice_p.h:171

◆ size()

int QIODevicePrivateLinearBuffer::size ( ) const
inline

Definition at line 84 of file qiodevice_p.h.

Referenced by chop(), reserve(), and ungetBlock().

84  {
85  return len;
86  }

◆ skip()

void QIODevicePrivateLinearBuffer::skip ( int  n)
inline

Definition at line 90 of file qiodevice_p.h.

90  {
91  if (n >= len) {
92  clear();
93  } else {
94  len -= n;
95  first += n;
96  }
97  }

◆ ungetBlock()

void QIODevicePrivateLinearBuffer::ungetBlock ( const char *  block,
int  size 
)
inline

Definition at line 159 of file qiodevice_p.h.

159  {
160  if ((first - buf) < size) {
161  // underflow, the existing valid data needs to move to the end of the (potentially bigger) buffer
163  }
164  first -= size;
165  len += size;
166  memcpy(first, block, size);
167  }
void makeSpace(size_t required, FreeSpacePos where)
Definition: qiodevice_p.h:171

◆ ungetChar()

void QIODevicePrivateLinearBuffer::ungetChar ( char  c)
inline

Definition at line 150 of file qiodevice_p.h.

150  {
151  if (first == buf) {
152  // underflow, the existing valid data needs to move to the end of the (potentially bigger) buffer
154  }
155  first--;
156  len++;
157  *first = c;
158  }
unsigned char c[8]
Definition: qnumeric_p.h:62
void makeSpace(size_t required, FreeSpacePos where)
Definition: qiodevice_p.h:171

Properties

◆ buf

char* QIODevicePrivateLinearBuffer::buf
private

Definition at line 196 of file qiodevice_p.h.

Referenced by clear(), makeSpace(), ungetBlock(), ungetChar(), and ~QIODevicePrivateLinearBuffer().

◆ capacity

size_t QIODevicePrivateLinearBuffer::capacity
private

Definition at line 198 of file qiodevice_p.h.

Referenced by makeSpace().

◆ first

char* QIODevicePrivateLinearBuffer::first
private

◆ len

int QIODevicePrivateLinearBuffer::len
private

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