QGIS API Documentation 3.28.14-Firenze (exported)
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 "qgswkbtypes.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
88 inline const QgsWkbPtr &operator>>( QgsWkbTypes::Type &v ) const { read( v ); return *this; } SIP_SKIP
89
91 inline QgsWkbPtr &operator<<( double v ) { write( v ); return *this; } SIP_SKIP
93 inline QgsWkbPtr &operator<<( float r ) { double v = r; write( v ); return *this; } SIP_SKIP
95 inline QgsWkbPtr &operator<<( qint32 v ) { write( v ); return *this; } SIP_SKIP
97 inline QgsWkbPtr &operator<<( qint64 r ) { quint32 v = r; write( v ); return *this; } SIP_SKIP
99 inline QgsWkbPtr &operator<<( quint32 v ) { write( v ); return *this; } SIP_SKIP
101 inline QgsWkbPtr &operator<<( char v ) { write( v ); return *this; } SIP_SKIP
103 inline QgsWkbPtr &operator<<( QgsWkbTypes::Type v ) { write( v ); return *this; } SIP_SKIP
105 inline QgsWkbPtr &operator<<( const QByteArray &data ) { write( data ); return *this; } SIP_SKIP
106
107 inline void operator+=( int n ) const { verifyBound( n ); mP += n; } SIP_SKIP
108
109 inline operator unsigned char *() const { return mP; } SIP_SKIP
110
115 inline int size() const { return mEnd - mStart; } SIP_SKIP
116
121 inline int remaining() const { return mEnd - mP; } SIP_SKIP
122
127 inline int writtenSize() const { return mP - mStart; } SIP_SKIP
128};
129
136class CORE_EXPORT QgsConstWkbPtr
137{
138 protected:
139 mutable unsigned char *mP;
140 unsigned char *mEnd;
141 mutable bool mEndianSwap;
143
148 void verifyBound( int size ) const SIP_SKIP;
149
154 template<typename T> void read( T &v ) const SIP_SKIP
155 {
156 verifyBound( sizeof v );
157 memcpy( &v, mP, sizeof( v ) );
158 mP += sizeof( v );
159 if ( mEndianSwap )
160 endian_swap( v );
161 }
162
163 public:
165 explicit QgsConstWkbPtr( const QByteArray &wkb ) SIP_SKIP;
166 QgsConstWkbPtr( const unsigned char *p SIP_ARRAY, int size SIP_ARRAYSIZE );
167
172 QgsWkbTypes::Type readHeader() const SIP_SKIP;
173
174 inline const QgsConstWkbPtr &operator>>( double &v ) const { read( v ); return *this; } SIP_SKIP
175 inline const QgsConstWkbPtr &operator>>( float &r ) const { double v; read( v ); r = v; return *this; } SIP_SKIP
176 inline const QgsConstWkbPtr &operator>>( int &v ) const { read( v ); return *this; } SIP_SKIP
177 inline const QgsConstWkbPtr &operator>>( unsigned int &v ) const { read( v ); return *this; } SIP_SKIP
178 inline const QgsConstWkbPtr &operator>>( char &v ) const { read( v ); return *this; } SIP_SKIP
179
181 const QgsConstWkbPtr &operator>>( QPointF &point ) const; SIP_SKIP
183 const QgsConstWkbPtr &operator>>( QPolygonF &points ) const; SIP_SKIP
184
185 inline void operator+=( int n ) const { verifyBound( n ); mP += n; } SIP_SKIP
186 inline void operator-=( int n ) const { mP -= n; } SIP_SKIP
187
188 inline operator const unsigned char *() const { return mP; } SIP_SKIP
189
194 inline int remaining() const { return mEnd - mP; } SIP_SKIP
195
196 private:
197 template<typename T> void endian_swap( T &value ) const SIP_SKIP
198 {
199 char *data = reinterpret_cast<char *>( &value );
200 const std::size_t n = sizeof( value );
201 for ( std::size_t i = 0, m = n / 2; i < m; ++i )
202 {
203 std::swap( data[i], data[n - 1 - i] );
204 }
205 }
206};
207
208#endif // QGSWKBPTR_H
A const WKB pointer.
Definition qgswkbptr.h:137
QgsWkbTypes::Type mWkbType
Definition qgswkbptr.h:142
const QgsConstWkbPtr & operator>>(int &v) const
Definition qgswkbptr.h:176
const QgsConstWkbPtr & operator>>(unsigned int &v) const
Definition qgswkbptr.h:177
int remaining() const
remaining
Definition qgswkbptr.h:194
void read(T &v) const
Read a value.
Definition qgswkbptr.h:154
void operator-=(int n) const
Definition qgswkbptr.h:186
void operator+=(int n) const
Definition qgswkbptr.h:185
unsigned char * mP
Definition qgswkbptr.h:139
const QgsConstWkbPtr & operator>>(float &r) const
Definition qgswkbptr.h:175
const QgsConstWkbPtr & operator>>(char &v) const
Definition qgswkbptr.h:178
unsigned char * mEnd
Definition qgswkbptr.h:140
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
QgsWkbPtr & operator<<(qint64 r)
Writes a longlong as int to the pointer.
Definition qgswkbptr.h:97
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
int remaining() const
remaining
Definition qgswkbptr.h:121
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:105
QgsWkbPtr & operator<<(qint32 v)
Writes an int to the pointer.
Definition qgswkbptr.h:95
QgsWkbPtr & operator<<(double v)
Writes a double to the pointer.
Definition qgswkbptr.h:91
int writtenSize() const
writtenSize
Definition qgswkbptr.h:127
int size() const
size
Definition qgswkbptr.h:115
const QgsWkbPtr & operator>>(float &r) const
Definition qgswkbptr.h:79
QgsWkbPtr & operator<<(quint32 v)
Writes an unsigned int to the pointer.
Definition qgswkbptr.h:99
void operator+=(int n) const
Definition qgswkbptr.h:107
QgsWkbPtr & operator<<(QgsWkbTypes::Type v)
Writes a WKB type value to the pointer.
Definition qgswkbptr.h:103
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:93
const QgsWkbPtr & operator>>(QgsWkbTypes::Type &v) const
Definition qgswkbptr.h:88
QgsWkbPtr & operator<<(char v)
Writes a char to the pointer.
Definition qgswkbptr.h:101
Type
The WKB type describes the number of dimensions a geometry has.
Definition qgswkbtypes.h:70
#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.