QGIS API Documentation  3.4.15-Madeira (e83d02e274)
qgswkbptr.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgswkbptr.h
3  ---------------------
4  begin : January 2014
5  copyright : (C) 2014 by Juergen E. Fischer
6  email : jef at norbit dot de
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #ifndef QGSWKBPTR_H
16 #define QGSWKBPTR_H
17 
18 #include "qgis_core.h"
19 #include "qgswkbtypes.h"
20 #include "qgsapplication.h"
21 #include "qgis.h"
22 #include "qgsexception.h"
23 #include "qpolygon.h"
24 
30 #ifndef SIP_RUN
31 class CORE_EXPORT QgsWkbException : public QgsException
32 {
33  public:
34  QgsWkbException( QString const &what ) : QgsException( what ) {}
35 };
36 #endif
37 
38 
43 class CORE_EXPORT QgsWkbPtr
44 {
45  mutable unsigned char *mP;
46  unsigned char *mStart;
47  unsigned char *mEnd;
48 
49  void verifyBound( int size ) const;
50 
51  template<typename T> void read( T &v ) const
52  {
53  verifyBound( sizeof v );
54  memcpy( &v, mP, sizeof v );
55  mP += sizeof v;
56  }
57 
58  template<typename T> void write( T &v ) const
59  {
60  verifyBound( sizeof v );
61  memcpy( mP, &v, sizeof v );
62  mP += sizeof v;
63  }
64 
65  void write( const QByteArray &data ) const
66  {
67  verifyBound( data.length() );
68  memcpy( mP, data.constData(), data.length() );
69  mP += data.length();
70  }
71 
72  public:
74  QgsWkbPtr( QByteArray &wkb ) SIP_SKIP;
75 
76  QgsWkbPtr( unsigned char *p SIP_ARRAY, int size SIP_ARRAYSIZE );
77 
78  inline const QgsWkbPtr &operator>>( double &v ) const { read( v ); return *this; } SIP_SKIP
79  inline const QgsWkbPtr &operator>>( float &r ) const { double v; read( v ); r = v; return *this; } SIP_SKIP
80  inline const QgsWkbPtr &operator>>( int &v ) const { read( v ); return *this; } SIP_SKIP
81  inline const QgsWkbPtr &operator>>( unsigned int &v ) const { read( v ); return *this; } SIP_SKIP
82  inline const QgsWkbPtr &operator>>( char &v ) const { read( v ); return *this; } SIP_SKIP
83  inline const QgsWkbPtr &operator>>( QgsWkbTypes::Type &v ) const { read( v ); return *this; } SIP_SKIP
84 
86  inline QgsWkbPtr &operator<<( double v ) { write( v ); return *this; } SIP_SKIP
88  inline QgsWkbPtr &operator<<( float r ) { double v = r; write( v ); return *this; } SIP_SKIP
90  inline QgsWkbPtr &operator<<( int v ) { write( v ); return *this; } SIP_SKIP
92  inline QgsWkbPtr &operator<<( unsigned int v ) { write( v ); return *this; } SIP_SKIP
94  inline QgsWkbPtr &operator<<( char v ) { write( v ); return *this; } SIP_SKIP
96  inline QgsWkbPtr &operator<<( QgsWkbTypes::Type v ) { write( v ); return *this; } SIP_SKIP
98  inline QgsWkbPtr &operator<<( const QByteArray &data ) { write( data ); return *this; } SIP_SKIP
99 
100  inline void operator+=( int n ) { verifyBound( n ); mP += n; } SIP_SKIP
101 
102  inline operator unsigned char *() const { return mP; } SIP_SKIP
103 
108  inline int size() const { return mEnd - mStart; } SIP_SKIP
109 
114  inline int remaining() const { return mEnd - mP; } SIP_SKIP
115 
120  inline int writtenSize() const { return mP - mStart; } SIP_SKIP
121 };
122 
128 class CORE_EXPORT QgsConstWkbPtr
129 {
130  protected:
131  mutable unsigned char *mP;
132  unsigned char *mEnd;
133  mutable bool mEndianSwap;
135 
140  void verifyBound( int size ) const SIP_SKIP;
141 
146  template<typename T> void read( T &v ) const SIP_SKIP
147  {
148  verifyBound( sizeof v );
149  memcpy( &v, mP, sizeof( v ) );
150  mP += sizeof( v );
151  if ( mEndianSwap )
153  }
154 
155  public:
157  explicit QgsConstWkbPtr( const QByteArray &wkb ) SIP_SKIP;
158  QgsConstWkbPtr( const unsigned char *p SIP_ARRAY, int size SIP_ARRAYSIZE );
159 
164  QgsWkbTypes::Type readHeader() const SIP_SKIP;
165 
166  inline const QgsConstWkbPtr &operator>>( double &v ) const { read( v ); return *this; } SIP_SKIP
167  inline const QgsConstWkbPtr &operator>>( float &r ) const { double v; read( v ); r = v; return *this; } SIP_SKIP
168  inline const QgsConstWkbPtr &operator>>( int &v ) const { read( v ); return *this; } SIP_SKIP
169  inline const QgsConstWkbPtr &operator>>( unsigned int &v ) const { read( v ); return *this; } SIP_SKIP
170  inline const QgsConstWkbPtr &operator>>( char &v ) const { read( v ); return *this; } SIP_SKIP
171 
173  virtual const QgsConstWkbPtr &operator>>( QPointF &point ) const; SIP_SKIP
175  virtual const QgsConstWkbPtr &operator>>( QPolygonF &points ) const; SIP_SKIP
176 
177  inline void operator+=( int n ) { verifyBound( n ); mP += n; } SIP_SKIP
178  inline void operator-=( int n ) { mP -= n; } SIP_SKIP
179 
180  inline operator const unsigned char *() const { return mP; } SIP_SKIP
181 
186  inline int remaining() const { return mEnd - mP; } SIP_SKIP
187 };
188 
189 #endif // QGSWKBPTR_H
static void endian_swap(T &value)
Swap the endianness of the specified value.
QgsWkbException(QString const &what)
Definition: qgswkbptr.h:34
int remaining() const
remaining
Definition: qgswkbptr.h:186
unsigned char * mP
Definition: qgswkbptr.h:131
const QgsConstWkbPtr & operator>>(char &v) const
Definition: qgswkbptr.h:170
const QgsConstWkbPtr & operator>>(double &v) const
Definition: qgswkbptr.h:166
QgsWkbPtr & operator<<(const QByteArray &data)
Append data from a byte array.
Definition: qgswkbptr.h:98
const QgsWkbPtr & operator>>(int &v) const
Definition: qgswkbptr.h:80
QgsWkbPtr & operator<<(QgsWkbTypes::Type v)
Writes a WKB type value to the pointer.
Definition: qgswkbptr.h:96
void operator+=(int n)
Definition: qgswkbptr.h:100
QDataStream & operator>>(QDataStream &in, QgsFeature &feature)
Reads a feature from stream in into feature. QGIS version compatibility is not guaranteed.
Definition: qgsfeature.cpp:305
const QgsWkbPtr & operator>>(float &r) const
Definition: qgswkbptr.h:79
QgsWkbPtr & operator<<(unsigned int v)
Writes an unsigned int to the pointer.
Definition: qgswkbptr.h:92
QgsWkbPtr & operator<<(int v)
Writes an int to the pointer.
Definition: qgswkbptr.h:90
const QgsWkbPtr & operator>>(QgsWkbTypes::Type &v) const
Definition: qgswkbptr.h:83
int writtenSize() const
writtenSize
Definition: qgswkbptr.h:120
const QgsConstWkbPtr & operator>>(unsigned int &v) const
Definition: qgswkbptr.h:169
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:68
#define SIP_ARRAYSIZE
Definition: qgis_sip.h:89
#define SIP_SKIP
Definition: qgis_sip.h:119
bool mEndianSwap
Definition: qgswkbptr.h:133
QgsWkbTypes::Type mWkbType
Definition: qgswkbptr.h:134
unsigned char * mEnd
Definition: qgswkbptr.h:132
const QgsWkbPtr & operator>>(double &v) const
Definition: qgswkbptr.h:78
int size() const
size
Definition: qgswkbptr.h:108
const QgsWkbPtr & operator>>(char &v) const
Definition: qgswkbptr.h:82
Custom exception class for Wkb related exceptions.
Definition: qgswkbptr.h:31
QgsWkbPtr & operator<<(float r)
Writes a float to the pointer.
Definition: qgswkbptr.h:88
#define SIP_ARRAY
Definition: qgis_sip.h:84
const QgsConstWkbPtr & operator>>(int &v) const
Definition: qgswkbptr.h:168
QgsWkbPtr & operator<<(char v)
Writes a char to the pointer.
Definition: qgswkbptr.h:94
int remaining() const
remaining
Definition: qgswkbptr.h:114
const QgsWkbPtr & operator>>(unsigned int &v) const
Definition: qgswkbptr.h:81
void operator+=(int n)
Definition: qgswkbptr.h:177
const QgsConstWkbPtr & operator>>(float &r) const
Definition: qgswkbptr.h:167
void operator-=(int n)
Definition: qgswkbptr.h:178
Defines a QGIS exception class.
Definition: qgsexception.h:34
QgsWkbPtr & operator<<(double v)
Writes a double to the pointer.
Definition: qgswkbptr.h:86
void read(T &v) const
Read a value.
Definition: qgswkbptr.h:146