QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
qgswkbptr.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgswkbptr.cpp
3 ---------------------
4 begin : May 2015
5 copyright : (C) 2015 by Marco Hugentobler
6 email : marco dot hugentobler at sourcepole dot ch
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#include "qgswkbptr.h"
16#include "qgsapplication.h"
17#include "qgswkbtypes.h"
18
19QgsWkbPtr::QgsWkbPtr( QByteArray &wkb )
20{
21 mP = reinterpret_cast<unsigned char *>( wkb.data() );
22 mStart = mP;
23 mEnd = mP + wkb.length();
24}
25
26QgsWkbPtr::QgsWkbPtr( unsigned char *p, int size )
27{
28 mP = p;
29 mStart = mP;
30 mEnd = mP + size;
31}
32
33void QgsWkbPtr::verifyBound( int size ) const
34{
35 if ( !mP || mP + size > mEnd )
36 throw QgsWkbException( QStringLiteral( "wkb access out of bounds" ) );
37}
38
39QgsConstWkbPtr::QgsConstWkbPtr( const QByteArray &wkb )
40{
41 mP = reinterpret_cast< unsigned char * >( const_cast<char *>( wkb.constData() ) );
42 mEnd = mP + wkb.length();
43 mEndianSwap = false;
45}
46
47QgsConstWkbPtr::QgsConstWkbPtr( const unsigned char *p, int size )
48{
49 mP = const_cast< unsigned char * >( p );
50 mEnd = mP + size;
51 mEndianSwap = false;
53}
54
56{
57 if ( !mP )
59
60 char wkbEndian;
61 *this >> wkbEndian;
62 mEndianSwap = wkbEndian != QgsApplication::endian();
63
64 int wkbType;
65 *this >> wkbType;
66 mWkbType = static_cast<Qgis::WkbType>( wkbType );
67
68 return mWkbType;
69}
70
71void QgsConstWkbPtr::verifyBound( int size ) const
72{
73 if ( !mP || mP + size > mEnd )
74 throw QgsWkbException( QStringLiteral( "wkb access out of bounds" ) );
75}
76
77const QgsConstWkbPtr &QgsConstWkbPtr::operator>>( QPointF &point ) const
78{
79 read( point.rx() );
80 read( point.ry() );
81 return *this;
82}
83
84const QgsConstWkbPtr &QgsConstWkbPtr::operator>>( QPolygonF &points ) const
85{
86 const int skipZM = ( QgsWkbTypes::coordDimensions( mWkbType ) - 2 ) * sizeof( double );
87 Q_ASSERT( skipZM >= 0 );
88
89 unsigned int nPoints;
90 read( nPoints );
91
92 points.resize( nPoints );
93 QPointF *ptr = points.data();
94
95 for ( unsigned int i = 0; i < nPoints; ++i, ++ptr )
96 {
97 read( ptr->rx() );
98 read( ptr->ry() );
99 mP += skipZM;
100 }
101 return *this;
102}
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:256
@ Unknown
Unknown.
static endian_t endian()
Returns whether this machine uses big or little endian.
A const WKB pointer.
Definition qgswkbptr.h:138
QgsConstWkbPtr(const QByteArray &wkb)
Construct WKB pointer from QByteArray.
Definition qgswkbptr.cpp:39
void read(T &v) const
Read a value.
Definition qgswkbptr.h:155
void verifyBound(int size) const
Verify bounds.
Definition qgswkbptr.cpp:71
Qgis::WkbType readHeader() const
readHeader
Definition qgswkbptr.cpp:55
const QgsConstWkbPtr & operator>>(double &v) const
Definition qgswkbptr.h:175
unsigned char * mP
Definition qgswkbptr.h:140
Qgis::WkbType mWkbType
Definition qgswkbptr.h:143
unsigned char * mEnd
Definition qgswkbptr.h:141
Custom exception class for Wkb related exceptions.
Definition qgswkbptr.h:31
int size() const
size
Definition qgswkbptr.h:116
QgsWkbPtr(QByteArray &wkb)
Construct WKB pointer from QByteArray.
Definition qgswkbptr.cpp:19
static int coordDimensions(Qgis::WkbType type)
Returns the coordinate dimension of the geometry type as an integer.