QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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 "qgis.h"
20#include "qgis_sip.h"
21#include "qgsexception.h"
22#include "qpolygon.h"
23
29#ifndef SIP_RUN
30class CORE_EXPORT QgsWkbException : public QgsException
31{
32 public:
33 QgsWkbException( QString const &what ) : QgsException( what ) {}
34};
35#endif
36
37
43class 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#if (!defined(Q_OS_ANDROID) && !defined(Q_PROCESSOR_X86_32)) || (defined(Q_OS_ANDROID) && defined(__aarch64__))
83 inline const QgsWkbPtr &operator>>( qsizetype &r ) const { int v; read( v ); r = v; return *this; } SIP_SKIP
84#endif
86 inline const QgsWkbPtr &operator>>( unsigned int &v ) const { read( v ); return *this; } SIP_SKIP
88 inline const QgsWkbPtr &operator>>( char &v ) const { read( v ); return *this; } SIP_SKIP
90 inline const QgsWkbPtr &operator>>( Qgis::WkbType &v ) const { read( v ); return *this; } SIP_SKIP
91
93 inline QgsWkbPtr &operator<<( double v ) { write( v ); return *this; } SIP_SKIP
95 inline QgsWkbPtr &operator<<( float r ) { double v = r; write( v ); return *this; } SIP_SKIP
97 inline QgsWkbPtr &operator<<( int v ) { write( v ); return *this; } SIP_SKIP
98#if (!defined(Q_OS_ANDROID) && !defined(Q_PROCESSOR_X86_32)) || (defined(Q_OS_ANDROID) && defined(__aarch64__))
100 inline QgsWkbPtr &operator<<( qsizetype r ) { int v = r; write( v ); return *this; } SIP_SKIP
101#endif
103 inline QgsWkbPtr &operator<<( unsigned int v ) { write( v ); return *this; } SIP_SKIP
105 inline QgsWkbPtr &operator<<( char v ) { write( v ); return *this; } SIP_SKIP
107 inline QgsWkbPtr &operator<<( Qgis::WkbType v ) { write( v ); return *this; } SIP_SKIP
109 inline QgsWkbPtr &operator<<( const QByteArray &data ) { write( data ); return *this; } SIP_SKIP
110
111 inline void operator+=( int n ) const { verifyBound( n ); mP += n; } SIP_SKIP
112
113 inline operator unsigned char *() const { return mP; } SIP_SKIP
114
119 inline int size() const { return mEnd - mStart; } SIP_SKIP
120
125 inline int remaining() const { return mEnd - mP; } SIP_SKIP
126
131 inline int writtenSize() const { return mP - mStart; } SIP_SKIP
132};
133
140class CORE_EXPORT QgsConstWkbPtr
141{
142 protected:
143 mutable unsigned char *mP;
144 unsigned char *mEnd;
145 mutable bool mEndianSwap;
147
152 void verifyBound( int size ) const SIP_SKIP;
153
158 template<typename T> void read( T &v ) const SIP_SKIP
159 {
160 verifyBound( sizeof v );
161 memcpy( &v, mP, sizeof( v ) );
162 mP += sizeof( v );
163 if ( mEndianSwap )
164 endian_swap( v );
165 }
166
167 public:
169 explicit QgsConstWkbPtr( const QByteArray &wkb ) SIP_SKIP;
170 QgsConstWkbPtr( const unsigned char *p SIP_ARRAY, int size SIP_ARRAYSIZE );
171
176 Qgis::WkbType readHeader() const SIP_SKIP;
177
178 inline const QgsConstWkbPtr &operator>>( double &v ) const { read( v ); return *this; } SIP_SKIP
179 inline const QgsConstWkbPtr &operator>>( float &r ) const { double v; read( v ); r = v; return *this; } SIP_SKIP
180 inline const QgsConstWkbPtr &operator>>( int &v ) const { read( v ); return *this; } SIP_SKIP
181 inline const QgsConstWkbPtr &operator>>( unsigned int &v ) const { read( v ); return *this; } SIP_SKIP
182 inline const QgsConstWkbPtr &operator>>( char &v ) const { read( v ); return *this; } SIP_SKIP
183
185 const QgsConstWkbPtr &operator>>( QPointF &point ) const; SIP_SKIP
187 const QgsConstWkbPtr &operator>>( QPolygonF &points ) const; SIP_SKIP
188
189 inline void operator+=( int n ) const { verifyBound( n ); mP += n; } SIP_SKIP
190 inline void operator-=( int n ) const { mP -= n; } SIP_SKIP
191
192 inline operator const unsigned char *() const { return mP; } SIP_SKIP
193
198 inline int remaining() const { return mEnd - mP; } SIP_SKIP
199
200 private:
201 template<typename T> void endian_swap( T &value ) const SIP_SKIP
202 {
203 char *data = reinterpret_cast<char *>( &value );
204 const std::size_t n = sizeof( value );
205 for ( std::size_t i = 0, m = n / 2; i < m; ++i )
206 {
207 std::swap( data[i], data[n - 1 - i] );
208 }
209 }
210};
211
212#endif // QGSWKBPTR_H
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition: qgis.h:155
A const WKB pointer.
Definition: qgswkbptr.h:141
const QgsConstWkbPtr & operator>>(int &v) const
Definition: qgswkbptr.h:180
const QgsConstWkbPtr & operator>>(unsigned int &v) const
Definition: qgswkbptr.h:181
int remaining() const
remaining
Definition: qgswkbptr.h:198
void read(T &v) const
Read a value.
Definition: qgswkbptr.h:158
void operator-=(int n) const
Definition: qgswkbptr.h:190
bool mEndianSwap
Definition: qgswkbptr.h:145
void operator+=(int n) const
Definition: qgswkbptr.h:189
unsigned char * mP
Definition: qgswkbptr.h:143
Qgis::WkbType mWkbType
Definition: qgswkbptr.h:146
const QgsConstWkbPtr & operator>>(float &r) const
Definition: qgswkbptr.h:179
const QgsConstWkbPtr & operator>>(char &v) const
Definition: qgswkbptr.h:182
unsigned char * mEnd
Definition: qgswkbptr.h:144
Defines a QGIS exception class.
Definition: qgsexception.h:35
Custom exception class for Wkb related exceptions.
Definition: qgswkbptr.h:31
QgsWkbException(QString const &what)
Definition: qgswkbptr.h:33
WKB pointer handler.
Definition: qgswkbptr.h:44
const QgsWkbPtr & operator>>(double &v) const
Definition: qgswkbptr.h:78
const QgsWkbPtr & operator>>(Qgis::WkbType &v) const
Reads a Qgis::WkbType enum value.
Definition: qgswkbptr.h:90
QgsWkbPtr & operator<<(Qgis::WkbType v)
Writes a WKB type value to the pointer.
Definition: qgswkbptr.h:107
int remaining() const
remaining
Definition: qgswkbptr.h:125
QgsWkbPtr & operator<<(const QByteArray &data)
Append data from a byte array.
Definition: qgswkbptr.h:109
QgsWkbPtr & operator<<(double v)
Writes a double to the pointer.
Definition: qgswkbptr.h:93
int writtenSize() const
writtenSize
Definition: qgswkbptr.h:131
const QgsWkbPtr & operator>>(unsigned int &v) const
Reads an unsigned integer value.
Definition: qgswkbptr.h:86
QgsWkbPtr & operator<<(int v)
Writes an int to the pointer.
Definition: qgswkbptr.h:97
int size() const
size
Definition: qgswkbptr.h:119
const QgsWkbPtr & operator>>(float &r) const
Definition: qgswkbptr.h:79
const QgsWkbPtr & operator>>(qsizetype &r) const
Reads an integer value into a qsizetype.
Definition: qgswkbptr.h:83
void operator+=(int n) const
Definition: qgswkbptr.h:111
const QgsWkbPtr & operator>>(char &v) const
Reads an char value.
Definition: qgswkbptr.h:88
QgsWkbPtr & operator<<(qsizetype r)
Writes a size as int to the pointer.
Definition: qgswkbptr.h:100
QgsWkbPtr & operator<<(unsigned int v)
Writes an unsigned int to the pointer.
Definition: qgswkbptr.h:103
const QgsWkbPtr & operator>>(int &v) const
Definition: qgswkbptr.h:80
QgsWkbPtr & operator<<(float r)
Writes a float to the pointer.
Definition: qgswkbptr.h:95
QgsWkbPtr & operator<<(char v)
Writes a char to the pointer.
Definition: qgswkbptr.h:105
#define SIP_ARRAY
Definition: qgis_sip.h:91
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_ARRAYSIZE
Definition: qgis_sip.h:96
QDataStream & operator>>(QDataStream &in, QgsFeature &feature)
Reads a feature from stream in into feature. QGIS version compatibility is not guaranteed.
Definition: qgsfeature.cpp:433