Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qiodevice_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QIODEVICE_P_H
5#define QIODEVICE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of QIODevice. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "QtCore/qbytearray.h"
19#include "QtCore/qiodevice.h"
20#include "QtCore/qobjectdefs.h"
21#include "QtCore/qstring.h"
22#include "QtCore/qvarlengtharray.h"
23#include "private/qringbuffer_p.h"
24#ifndef QT_NO_QOBJECT
25#include "private/qobject_p.h"
26#endif
27
29
30#ifndef QIODEVICE_BUFFERSIZE
31#define QIODEVICE_BUFFERSIZE 16384
32#endif
33
34Q_CORE_EXPORT int qt_subtract_from_timeout(int timeout, int elapsed);
35
36class Q_CORE_EXPORT QIODevicePrivate
37#ifndef QT_NO_QOBJECT
38 : public QObjectPrivate
39#endif
40{
41 Q_DECLARE_PUBLIC(QIODevice)
42 Q_DISABLE_COPY_MOVE(QIODevicePrivate)
43
44public:
46 virtual ~QIODevicePrivate();
47
48 // The size of this class is a subject of the library hook data.
49 // When adding a new member, do not make gaps and be aware
50 // about the padding. Accordingly, adjust offsets in
51 // tests/auto/other/toolsupport and bump the TypeInformationVersion
52 // field in src/corelib/global/qhooks.cpp, to notify the developers.
54 qint64 devicePos = 0;
55 qint64 transactionPos = 0;
56
58 {
59 QRingBuffer *m_buf;
60 inline QRingBufferRef() : m_buf(nullptr) { }
61 friend class QIODevicePrivate;
62 public:
63 // wrap functions from QRingBuffer
64 inline void setChunkSize(int size) { Q_ASSERT(m_buf); m_buf->setChunkSize(size); }
65 inline int chunkSize() const { Q_ASSERT(m_buf); return m_buf->chunkSize(); }
66 inline qint64 nextDataBlockSize() const { return (m_buf ? m_buf->nextDataBlockSize() : Q_INT64_C(0)); }
67 inline const char *readPointer() const { return (m_buf ? m_buf->readPointer() : nullptr); }
68 inline const char *readPointerAtPosition(qint64 pos, qint64 &length) const { Q_ASSERT(m_buf); return m_buf->readPointerAtPosition(pos, length); }
69 inline void free(qint64 bytes) { Q_ASSERT(m_buf); m_buf->free(bytes); }
70 inline char *reserve(qint64 bytes) { Q_ASSERT(m_buf); return m_buf->reserve(bytes); }
71 inline char *reserveFront(qint64 bytes) { Q_ASSERT(m_buf); return m_buf->reserveFront(bytes); }
72 inline void truncate(qint64 pos) { Q_ASSERT(m_buf); m_buf->truncate(pos); }
73 inline void chop(qint64 bytes) { Q_ASSERT(m_buf); m_buf->chop(bytes); }
74 inline bool isEmpty() const { return !m_buf || m_buf->isEmpty(); }
75 inline int getChar() { return (m_buf ? m_buf->getChar() : -1); }
76 inline void putChar(char c) { Q_ASSERT(m_buf); m_buf->putChar(c); }
77 inline void ungetChar(char c) { Q_ASSERT(m_buf); m_buf->ungetChar(c); }
78 inline qint64 size() const { return (m_buf ? m_buf->size() : Q_INT64_C(0)); }
79 inline void clear() { if (m_buf) m_buf->clear(); }
80 inline qint64 indexOf(char c) const { return (m_buf ? m_buf->indexOf(c, m_buf->size()) : Q_INT64_C(-1)); }
81 inline qint64 indexOf(char c, qint64 maxLength, qint64 pos = 0) const { return (m_buf ? m_buf->indexOf(c, maxLength, pos) : Q_INT64_C(-1)); }
82 inline qint64 read(char *data, qint64 maxLength) { return (m_buf ? m_buf->read(data, maxLength) : Q_INT64_C(0)); }
83 inline QByteArray read() { return (m_buf ? m_buf->read() : QByteArray()); }
84 inline qint64 peek(char *data, qint64 maxLength, qint64 pos = 0) const { return (m_buf ? m_buf->peek(data, maxLength, pos) : Q_INT64_C(0)); }
85 inline void append(const char *data, qint64 size) { Q_ASSERT(m_buf); m_buf->append(data, size); }
86 inline void append(const QByteArray &qba) { Q_ASSERT(m_buf); m_buf->append(qba); }
87 inline qint64 skip(qint64 length) { return (m_buf ? m_buf->skip(length) : Q_INT64_C(0)); }
88 inline qint64 readLine(char *data, qint64 maxLength) { return (m_buf ? m_buf->readLine(data, maxLength) : Q_INT64_C(-1)); }
89 inline bool canReadLine() const { return m_buf && m_buf->canReadLine(); }
90 };
91
94 const QByteArray *currentWriteChunk = nullptr;
95 int readChannelCount = 0;
96 int writeChannelCount = 0;
97 int currentReadChannel = 0;
98 int currentWriteChannel = 0;
99 int readBufferChunkSize = QIODEVICE_BUFFERSIZE;
100 int writeBufferChunkSize = 0;
101
102 QVarLengthArray<QRingBuffer, 2> readBuffers;
103 QVarLengthArray<QRingBuffer, 1> writeBuffers;
105 QIODevice::OpenMode openMode = QIODevice::NotOpen;
106
107 bool transactionStarted = false;
108 bool baseReadLineDataCalled = false;
109
110 virtual bool putCharHelper(char c);
111
115 RandomAccess
116 };
117 mutable AccessMode accessMode = Unset;
118 inline bool isSequential() const
119 {
120 if (accessMode == Unset)
121 accessMode = q_func()->isSequential() ? Sequential : RandomAccess;
122 return accessMode == Sequential;
123 }
124
125 inline bool isBufferEmpty() const
126 {
127 return buffer.isEmpty() || (transactionStarted && isSequential()
128 && transactionPos == buffer.size());
129 }
130 bool allWriteBuffersEmpty() const;
131
132 void seekBuffer(qint64 newPos);
133
135 {
136 buffer.m_buf = (channel < readBuffers.size() ? &readBuffers[channel] : nullptr);
137 currentReadChannel = channel;
138 }
140 {
141 writeBuffer.m_buf = (channel < writeBuffers.size() ? &writeBuffers[channel] : nullptr);
142 currentWriteChannel = channel;
143 }
144 void setReadChannelCount(int count);
145 void setWriteChannelCount(int count);
146
147 qint64 read(char *data, qint64 maxSize, bool peeking = false);
148 qint64 readLine(char *data, qint64 maxSize);
149 virtual qint64 peek(char *data, qint64 maxSize);
150 virtual QByteArray peek(qint64 maxSize);
151 qint64 skipByReading(qint64 maxSize);
152 void write(const char *data, qint64 size);
153
154 inline bool isWriteChunkCached(const char *data, qint64 size) const
155 {
156 return currentWriteChunk != nullptr
157 && currentWriteChunk->constData() == data
158 && currentWriteChunk->size() == size;
159 }
160
161#ifdef QT_NO_QOBJECT
162 QIODevice *q_ptr = nullptr;
163#endif
164};
165
167
168#endif // QIODEVICE_P_H
IOBluetoothL2CAPChannel * channel
\inmodule QtCore
Definition qbytearray.h:57
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
Definition qbytearray.h:494
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
Definition qbytearray.h:124
char * reserve(qint64 bytes)
Definition qiodevice_p.h:70
qint64 read(char *data, qint64 maxLength)
Definition qiodevice_p.h:82
char * reserveFront(qint64 bytes)
Definition qiodevice_p.h:71
void append(const QByteArray &qba)
Definition qiodevice_p.h:86
qint64 indexOf(char c) const
Definition qiodevice_p.h:80
qint64 indexOf(char c, qint64 maxLength, qint64 pos=0) const
Definition qiodevice_p.h:81
qint64 readLine(char *data, qint64 maxLength)
Definition qiodevice_p.h:88
qint64 peek(char *data, qint64 maxLength, qint64 pos=0) const
Definition qiodevice_p.h:84
qint64 skip(qint64 length)
Definition qiodevice_p.h:87
const char * readPointerAtPosition(qint64 pos, qint64 &length) const
Definition qiodevice_p.h:68
void append(const char *data, qint64 size)
Definition qiodevice_p.h:85
const char * readPointer() const
Definition qiodevice_p.h:67
void setCurrentWriteChannel(int channel)
QVarLengthArray< QRingBuffer, 1 > writeBuffers
bool isBufferEmpty() const
bool isSequential() const
QVarLengthArray< QRingBuffer, 2 > readBuffers
void setCurrentReadChannel(int channel)
bool isWriteChunkCached(const char *data, qint64 size) const
QRingBufferRef buffer
Definition qiodevice_p.h:92
QRingBufferRef writeBuffer
Definition qiodevice_p.h:93
\inmodule QtCore \reentrant
Definition qiodevice.h:34
bool isEmpty() const
Q_CORE_EXPORT void free(qint64 bytes)
qint64 size() const
Q_CORE_EXPORT qint64 peek(char *data, qint64 maxLength, qint64 pos=0) const
Q_CORE_EXPORT qint64 readLine(char *data, qint64 maxLength)
const char * readPointer() const
Q_CORE_EXPORT const char * readPointerAtPosition(qint64 pos, qint64 &length) const
qint64 skip(qint64 length)
Q_CORE_EXPORT void chop(qint64 bytes)
Q_CORE_EXPORT char * reserve(qint64 bytes)
bool canReadLine() const
void setChunkSize(int size)
void truncate(qint64 pos)
Q_CORE_EXPORT void append(const char *data, qint64 size)
Q_CORE_EXPORT char * reserveFront(qint64 bytes)
qint64 indexOf(char c) const
Q_CORE_EXPORT void clear()
qint64 nextDataBlockSize() const
Q_CORE_EXPORT qint64 read(char *data, qint64 maxLength)
int chunkSize() const
void ungetChar(char c)
void putChar(char c)
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
#define QIODEVICE_BUFFERSIZE
Definition qiodevice_p.h:31
Q_CORE_EXPORT int qt_subtract_from_timeout(int timeout, int elapsed)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei length
GLenum GLenum GLsizei count
GLbitfield GLuint64 timeout
[4]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint buffer
const GLubyte * c
GLsizei maxLength
GLuint writeBuffer
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
static double elapsed(qint64 after, qint64 before)
long long qint64
Definition qtypes.h:60
unsigned char quint8
Definition qtypes.h:46
#define Q_INT64_C(c)
Definition qtypes.h:57
ReturnedValue read(const char *data)
gzip write("uncompressed data")