QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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 { read( v ); return *this; } SIP_SKIP
79 inline const QgsWkbPtr &operator>>( float &r ) const { double v; read( v ); r = v; return *this; } SIP_SKIP
81 inline const QgsWkbPtr &operator>>( qint32 &v ) const { read( v ); return *this; } SIP_SKIP
83 inline const QgsWkbPtr &operator>>( qint64 &r ) const { quint32 v; read( v ); r = v; return *this; } SIP_SKIP
85 inline const QgsWkbPtr &operator>>( quint32 &v ) const { read( v ); return *this; } SIP_SKIP
87 inline const QgsWkbPtr &operator>>( char &v ) const { read( v ); return *this; } SIP_SKIP
89 inline const QgsWkbPtr &operator>>( Qgis::WkbType &v ) const { read( v ); return *this; } SIP_SKIP
90
92 inline QgsWkbPtr &operator<<( double v ) { write( v ); return *this; } SIP_SKIP
94 inline QgsWkbPtr &operator<<( float r ) { double v = r; write( v ); return *this; } SIP_SKIP
96 inline QgsWkbPtr &operator<<( qint32 v ) { write( v ); return *this; } SIP_SKIP
98 inline QgsWkbPtr &operator<<( qint64 r ) { quint32 v = r; write( v ); return *this; } SIP_SKIP
100 inline QgsWkbPtr &operator<<( quint32 v ) { write( v ); return *this; } SIP_SKIP
102 inline QgsWkbPtr &operator<<( char v ) { write( v ); return *this; } SIP_SKIP
104 inline QgsWkbPtr &operator<<( Qgis::WkbType v ) { write( v ); return *this; } SIP_SKIP
106 inline QgsWkbPtr &operator<<( const QByteArray &data ) { write( data ); return *this; } SIP_SKIP
107
108 inline void operator+=( int n ) const { verifyBound( n ); mP += n; } SIP_SKIP
109
110 inline operator unsigned char *() const { return mP; } SIP_SKIP
111
116 inline int size() const { return mEnd - mStart; } SIP_SKIP
117
122 inline int remaining() const { return mEnd - mP; } SIP_SKIP
123
128 inline int writtenSize() const { return mP - mStart; } SIP_SKIP
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 { read( v ); return *this; } SIP_SKIP
176 inline const QgsConstWkbPtr &operator>>( float &r ) const { double v; read( v ); r = v; return *this; } SIP_SKIP
177 inline const QgsConstWkbPtr &operator>>( int &v ) const { read( v ); return *this; } SIP_SKIP
178 inline const QgsConstWkbPtr &operator>>( unsigned int &v ) const { read( v ); return *this; } SIP_SKIP
179 inline const QgsConstWkbPtr &operator>>( char &v ) const { read( v ); return *this; } SIP_SKIP
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 { verifyBound( n ); mP += n; } SIP_SKIP
187 inline void operator-=( int n ) const { mP -= n; } SIP_SKIP
188
189 inline operator const unsigned char *() const { return mP; } SIP_SKIP
190
195 inline int remaining() const { return mEnd - mP; } SIP_SKIP
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 for ( std::size_t i = 0, m = n / 2; i < m; ++i )
203 {
204 std::swap( data[i], data[n - 1 - i] );
205 }
206 }
207};
208
209#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.