QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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 SIP_SKIP { read( v ); return *this; }
79 inline const QgsWkbPtr &operator>>( float &r ) const SIP_SKIP { double v; read( v ); r = v; return *this; }
81 inline const QgsWkbPtr &operator>>( qint32 &v ) const SIP_SKIP { read( v ); return *this; }
83 inline const QgsWkbPtr &operator>>( qint64 &r ) const SIP_SKIP { quint32 v; read( v ); r = v; return *this; }
85 inline const QgsWkbPtr &operator>>( quint32 &v ) const SIP_SKIP { read( v ); return *this; }
87 inline const QgsWkbPtr &operator>>( char &v ) const SIP_SKIP { read( v ); return *this; }
89 inline const QgsWkbPtr &operator>>( Qgis::WkbType &v ) const SIP_SKIP { read( v ); return *this; }
90
92 inline QgsWkbPtr &operator<<( double v ) SIP_SKIP { write( v ); return *this; }
94 inline QgsWkbPtr &operator<<( float r ) SIP_SKIP { double v = r; write( v ); return *this; }
96 inline QgsWkbPtr &operator<<( qint32 v ) SIP_SKIP { write( v ); return *this; }
98 inline QgsWkbPtr &operator<<( qint64 r ) SIP_SKIP { quint32 v = r; write( v ); return *this; }
100 inline QgsWkbPtr &operator<<( quint32 v ) SIP_SKIP { write( v ); return *this; }
102 inline QgsWkbPtr &operator<<( char v ) SIP_SKIP { write( v ); return *this; }
104 inline QgsWkbPtr &operator<<( Qgis::WkbType v ) SIP_SKIP { write( v ); return *this; }
106 inline QgsWkbPtr &operator<<( const QByteArray &data ) SIP_SKIP { write( data ); return *this; }
107
108 inline void operator+=( int n ) const SIP_SKIP { verifyBound( n ); mP += n; }
109
110 inline operator unsigned char *() const SIP_SKIP { return mP; }
111
116 inline int size() const SIP_SKIP { return mEnd - mStart; }
117
122 inline int remaining() const SIP_SKIP { return mEnd - mP; }
123
128 inline int writtenSize() const SIP_SKIP { return mP - mStart; }
129};
130
137class CORE_EXPORT QgsConstWkbPtr
138{
139 protected:
140 mutable unsigned char *mP;
141 unsigned char *mEnd;
142 mutable bool mEndianSwap;
144
149 void verifyBound( int size ) const SIP_SKIP;
150
155 template<typename T> void read( T &v ) const SIP_SKIP
156 {
157 verifyBound( sizeof v );
158 memcpy( &v, mP, sizeof( v ) );
159 mP += sizeof( v );
160 if ( mEndianSwap )
161 endian_swap( v );
162 }
163
164 public:
166 explicit QgsConstWkbPtr( const QByteArray &wkb ) SIP_SKIP;
167 QgsConstWkbPtr( const unsigned char *p SIP_ARRAY, int size SIP_ARRAYSIZE );
168
173 Qgis::WkbType readHeader() const SIP_SKIP;
174
175 inline const QgsConstWkbPtr &operator>>( double &v ) const SIP_SKIP { read( v ); return *this; }
176 inline const QgsConstWkbPtr &operator>>( float &r ) const SIP_SKIP { double v; read( v ); r = v; return *this; }
177 inline const QgsConstWkbPtr &operator>>( int &v ) const SIP_SKIP { read( v ); return *this; }
178 inline const QgsConstWkbPtr &operator>>( unsigned int &v ) const SIP_SKIP { read( v ); return *this; }
179 inline const QgsConstWkbPtr &operator>>( char &v ) const SIP_SKIP { read( v ); return *this; }
180
182 const QgsConstWkbPtr &operator>>( QPointF &point ) const; SIP_SKIP
184 const QgsConstWkbPtr &operator>>( QPolygonF &points ) const; SIP_SKIP
185
186 inline void operator+=( int n ) const SIP_SKIP { verifyBound( n ); mP += n; }
187 inline void operator-=( int n ) const SIP_SKIP { mP -= n; }
188
189 inline operator const unsigned char *() const SIP_SKIP { return mP; }
190
195 inline int remaining() const SIP_SKIP { return mEnd - mP; }
196
197 private:
198 template<typename T> void endian_swap( T &value ) const SIP_SKIP
199 {
200 char *data = reinterpret_cast<char *>( &value );
201 const std::size_t n = sizeof( value );
202 const std::size_t m = n / 2;
203 for ( std::size_t i = 0; i < m; ++i )
204 {
205 std::swap( data[i], data[n - 1 - i] );
206 }
207 }
208};
209
210#endif // QGSWKBPTR_H
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:256
A const WKB pointer.
Definition qgswkbptr.h:138
const QgsConstWkbPtr & operator>>(int &v) const
Definition qgswkbptr.h:177
const QgsConstWkbPtr & operator>>(unsigned int &v) const
Definition qgswkbptr.h:178
int remaining() const
remaining
Definition qgswkbptr.h:195
void read(T &v) const
Read a value.
Definition qgswkbptr.h:155
void operator-=(int n) const
Definition qgswkbptr.h:187
void operator+=(int n) const
Definition qgswkbptr.h:186
unsigned char * mP
Definition qgswkbptr.h:140
Qgis::WkbType mWkbType
Definition qgswkbptr.h:143
const QgsConstWkbPtr & operator>>(float &r) const
Definition qgswkbptr.h:176
const QgsConstWkbPtr & operator>>(char &v) const
Definition qgswkbptr.h:179
unsigned char * mEnd
Definition qgswkbptr.h:141
Defines a QGIS exception class.
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:89
QgsWkbPtr & operator<<(qint64 r)
Writes a longlong as int to the pointer.
Definition qgswkbptr.h:98
const QgsWkbPtr & operator>>(qint32 &v) const
Reads an integer value into a qint32.
Definition qgswkbptr.h:81
const QgsWkbPtr & operator>>(qint64 &r) const
Reads an integer value into a longlong.
Definition qgswkbptr.h:83
QgsWkbPtr & operator<<(Qgis::WkbType v)
Writes a WKB type value to the pointer.
Definition qgswkbptr.h:104
int remaining() const
remaining
Definition qgswkbptr.h:122
const QgsWkbPtr & operator>>(quint32 &v) const
Reads an unsigned integer value.
Definition qgswkbptr.h:85
QgsWkbPtr & operator<<(const QByteArray &data)
Append data from a byte array.
Definition qgswkbptr.h:106
QgsWkbPtr & operator<<(qint32 v)
Writes an int to the pointer.
Definition qgswkbptr.h:96
QgsWkbPtr & operator<<(double v)
Writes a double to the pointer.
Definition qgswkbptr.h:92
int writtenSize() const
writtenSize
Definition qgswkbptr.h:128
int size() const
size
Definition qgswkbptr.h:116
const QgsWkbPtr & operator>>(float &r) const
Definition qgswkbptr.h:79
QgsWkbPtr & operator<<(quint32 v)
Writes an unsigned int to the pointer.
Definition qgswkbptr.h:100
void operator+=(int n) const
Definition qgswkbptr.h:108
const QgsWkbPtr & operator>>(char &v) const
Reads an char value.
Definition qgswkbptr.h:87
QgsWkbPtr & operator<<(float r)
Writes a float to the pointer.
Definition qgswkbptr.h:94
QgsWkbPtr & operator<<(char v)
Writes a char to the pointer.
Definition qgswkbptr.h:102
#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.