|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtCore module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef QNONCONTIGUOUSBYTEDEVICE_H |
|
43 #define QNONCONTIGUOUSBYTEDEVICE_H |
|
44 |
|
45 // |
|
46 // W A R N I N G |
|
47 // ------------- |
|
48 // |
|
49 // This file is not part of the Qt API. It exists for the convenience |
|
50 // of a number of Qt sources files. This header file may change from |
|
51 // version to version without notice, or even be removed. |
|
52 // |
|
53 // We mean it. |
|
54 // |
|
55 |
|
56 #include <QtCore/qobject.h> |
|
57 #include <QtCore/qbytearray.h> |
|
58 #include <QtCore/qbuffer.h> |
|
59 #include <QtCore/qiodevice.h> |
|
60 #include "private/qringbuffer_p.h" |
|
61 |
|
62 QT_BEGIN_NAMESPACE |
|
63 |
|
64 class Q_CORE_EXPORT QNonContiguousByteDevice : public QObject |
|
65 { |
|
66 Q_OBJECT |
|
67 public: |
|
68 virtual const char* readPointer(qint64 maximumLength, qint64 &len) = 0; |
|
69 virtual bool advanceReadPointer(qint64 amount) = 0; |
|
70 virtual bool atEnd() = 0; |
|
71 virtual bool reset() = 0; |
|
72 void disableReset(); |
|
73 virtual qint64 size() = 0; |
|
74 |
|
75 virtual ~QNonContiguousByteDevice(); |
|
76 |
|
77 protected: |
|
78 QNonContiguousByteDevice(); |
|
79 |
|
80 |
|
81 bool resetDisabled; |
|
82 Q_SIGNALS: |
|
83 void readyRead(); |
|
84 void readProgress(qint64 current, qint64 total); |
|
85 }; |
|
86 |
|
87 class Q_CORE_EXPORT QNonContiguousByteDeviceFactory |
|
88 { |
|
89 public: |
|
90 static QNonContiguousByteDevice* create(QIODevice *device); |
|
91 static QNonContiguousByteDevice* create(QByteArray *byteArray); |
|
92 static QNonContiguousByteDevice* create(QRingBuffer *ringBuffer); |
|
93 static QIODevice* wrap(QNonContiguousByteDevice* byteDevice); |
|
94 }; |
|
95 |
|
96 // the actual implementations |
|
97 // |
|
98 |
|
99 class QNonContiguousByteDeviceByteArrayImpl : public QNonContiguousByteDevice |
|
100 { |
|
101 public: |
|
102 QNonContiguousByteDeviceByteArrayImpl(QByteArray *ba); |
|
103 ~QNonContiguousByteDeviceByteArrayImpl(); |
|
104 const char* readPointer(qint64 maximumLength, qint64 &len); |
|
105 bool advanceReadPointer(qint64 amount); |
|
106 bool atEnd(); |
|
107 bool reset(); |
|
108 qint64 size(); |
|
109 protected: |
|
110 QByteArray* byteArray; |
|
111 qint64 currentPosition; |
|
112 }; |
|
113 |
|
114 class QNonContiguousByteDeviceRingBufferImpl : public QNonContiguousByteDevice |
|
115 { |
|
116 public: |
|
117 QNonContiguousByteDeviceRingBufferImpl(QRingBuffer *rb); |
|
118 ~QNonContiguousByteDeviceRingBufferImpl(); |
|
119 const char* readPointer(qint64 maximumLength, qint64 &len); |
|
120 bool advanceReadPointer(qint64 amount); |
|
121 bool atEnd(); |
|
122 bool reset(); |
|
123 qint64 size(); |
|
124 protected: |
|
125 QRingBuffer* ringBuffer; |
|
126 qint64 currentPosition; |
|
127 }; |
|
128 |
|
129 |
|
130 class QNonContiguousByteDeviceIoDeviceImpl : public QNonContiguousByteDevice |
|
131 { |
|
132 public: |
|
133 QNonContiguousByteDeviceIoDeviceImpl(QIODevice *d); |
|
134 ~QNonContiguousByteDeviceIoDeviceImpl(); |
|
135 const char* readPointer(qint64 maximumLength, qint64 &len); |
|
136 bool advanceReadPointer(qint64 amount); |
|
137 bool atEnd(); |
|
138 bool reset(); |
|
139 qint64 size(); |
|
140 protected: |
|
141 QIODevice* device; |
|
142 QByteArray* currentReadBuffer; |
|
143 qint64 currentReadBufferSize; |
|
144 qint64 currentReadBufferAmount; |
|
145 qint64 currentReadBufferPosition; |
|
146 qint64 totalAdvancements; |
|
147 bool eof; |
|
148 qint64 initialPosition; |
|
149 }; |
|
150 |
|
151 class QNonContiguousByteDeviceBufferImpl : public QNonContiguousByteDevice |
|
152 { |
|
153 public: |
|
154 QNonContiguousByteDeviceBufferImpl(QBuffer *b); |
|
155 ~QNonContiguousByteDeviceBufferImpl(); |
|
156 const char* readPointer(qint64 maximumLength, qint64 &len); |
|
157 bool advanceReadPointer(qint64 amount); |
|
158 bool atEnd(); |
|
159 bool reset(); |
|
160 qint64 size(); |
|
161 protected: |
|
162 QBuffer* buffer; |
|
163 QByteArray byteArray; |
|
164 QNonContiguousByteDeviceByteArrayImpl* arrayImpl; |
|
165 }; |
|
166 |
|
167 // ... and the reverse thing |
|
168 class QByteDeviceWrappingIoDevice : public QIODevice |
|
169 { |
|
170 public: |
|
171 QByteDeviceWrappingIoDevice (QNonContiguousByteDevice *bd); |
|
172 ~QByteDeviceWrappingIoDevice (); |
|
173 virtual bool isSequential () const; |
|
174 virtual bool atEnd () const; |
|
175 virtual bool reset (); |
|
176 virtual qint64 size () const; |
|
177 protected: |
|
178 virtual qint64 readData ( char * data, qint64 maxSize ); |
|
179 virtual qint64 writeData ( const char * data, qint64 maxSize ); |
|
180 |
|
181 QNonContiguousByteDevice *byteDevice; |
|
182 }; |
|
183 |
|
184 QT_END_NAMESPACE |
|
185 |
|
186 #endif |