datastreamoperatorwrapper.h
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 #ifndef DOOMSEEKER_DATASTREAMOPERATORWRAPPER_H
24 #define DOOMSEEKER_DATASTREAMOPERATORWRAPPER_H
25 
26 #include <QDataStream>
27 
28 #include "global.h"
29 #include "dptr.h"
30 
36 class MAIN_EXPORT DataStreamOperatorWrapper
37 {
38  public:
39  DataStreamOperatorWrapper(QDataStream* stream);
40  virtual ~DataStreamOperatorWrapper();
41 
45  QDataStream* dataStream();
46 
50  const QDataStream* dataStream() const;
51 
57  bool hasRemaining() const
58  {
59  return remaining() > 0;
60  }
61 
62  qint8 readQInt8();
63  bool readBool();
64  quint8 readQUInt8();
65  quint16 readQUInt16();
66  qint16 readQInt16();
67  quint32 readQUInt32();
68  qint32 readQInt32();
69  quint64 readQUInt64();
70  qint64 readQInt64();
71  float readFloat();
72  double readDouble();
73 
81  QByteArray readRaw(qint64 length);
82 
90  QByteArray readRawAll();
91 
113  QByteArray readRawUntilByte(char stopByte);
114 
123  QByteArray readRawMaxUntilByte(char stopByte, qint64 length);
124 
133  qint64 remaining() const;
134 
142  int skipRawData(int len);
143 
144  private:
146 };
147 
148 #endif
149 
Wraps around QDataStream stream operators to provide cleaner reading interface.
bool hasRemaining() const
Returns true if there is any data remaining in the stream.