datastreamoperatorwrapper.cpp
1 //------------------------------------------------------------------------------
2 // datastreamoperatorwrapper.h
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2012 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "datastreamoperatorwrapper.h"
24 
25 #include "strings.h"
26 #include <cassert>
27 
28 #define RETTYPE(type) \
29 type tmp; \
30 (*d->s) >> tmp; \
31 return tmp;
32 
33 DClass<DataStreamOperatorWrapper>
34 {
35  public:
36  QDataStream *s;
37 };
38 
39 DPointered(DataStreamOperatorWrapper)
40 
42 {
43  assert(stream != NULL);
44  d->s = stream;
45 }
46 
47 DataStreamOperatorWrapper::~DataStreamOperatorWrapper()
48 {
49 }
50 
52 {
53  return d->s;
54 }
55 
56 const QDataStream* DataStreamOperatorWrapper::dataStream() const
57 {
58  return d->s;
59 }
60 
61 qint8 DataStreamOperatorWrapper::readQInt8()
62 {
63  RETTYPE(qint8);
64 }
65 
66 bool DataStreamOperatorWrapper::readBool()
67 {
68  RETTYPE(bool);
69 }
70 
71 quint8 DataStreamOperatorWrapper::readQUInt8()
72 {
73  RETTYPE(quint8);
74 }
75 
76 quint16 DataStreamOperatorWrapper::readQUInt16()
77 {
78  RETTYPE(quint16);
79 }
80 
81 qint16 DataStreamOperatorWrapper::readQInt16()
82 {
83  RETTYPE(qint16);
84 }
85 
86 quint32 DataStreamOperatorWrapper::readQUInt32()
87 {
88  RETTYPE(quint32);
89 }
90 
91 qint32 DataStreamOperatorWrapper::readQInt32()
92 {
93  RETTYPE(qint32);
94 }
95 
96 quint64 DataStreamOperatorWrapper::readQUInt64()
97 {
98  RETTYPE(quint64);
99 }
100 
101 qint64 DataStreamOperatorWrapper::readQInt64()
102 {
103  RETTYPE(qint64);
104 }
105 
106 float DataStreamOperatorWrapper::readFloat()
107 {
108  RETTYPE(float);
109 }
110 
111 double DataStreamOperatorWrapper::readDouble()
112 {
113  RETTYPE(double);
114 }
115 
116 QByteArray DataStreamOperatorWrapper::readRaw(qint64 length)
117 {
118  return d->s->device()->read(length);
119 }
120 
122 {
123  return d->s->device()->readAll();
124 }
125 
127 {
128  return Strings::readUntilByte(*d->s, stopByte);
129 }
130 
132 {
133  return d->s->device()->size() - d->s->device()->pos();
134 }
135 
137 {
138  return d->s->skipRawData(len);
139 }
qint64 remaining() const
Returns a remaining amount of bytes from the underlying QIODevice.
QByteArray readRawUntilByte(char stopByte)
This method calls Strings::readUntilByte() .
Wraps around QDataStream stream operators to provide cleaner reading interface.
QDataStream * dataStream()
Gets underlying QDataStream.
int skipRawData(int len)
Reads and discards specified amount of data.
static QByteArray readUntilByte(QDataStream &stream, unsigned char stopByte)
Reads raw data from the current position of passed QDataStream until a specified byte is encountered...
Definition: strings.cpp:365
QByteArray readRaw(qint64 length)
Reads specified amount of raw bytes.
QByteArray readRawAll()
Reads all remaining raw bytes.