QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
17 QgsWkbPtr::QgsWkbPtr( unsigned char *p, int size )
18 {
19  mP = p;
20  mStart = mP;
21  mEnd = mP + size;
22 }
23 
24 void QgsWkbPtr::verifyBound( int size ) const
25 {
26  if ( !mP || mP + size > mEnd )
27  throw QgsWkbException( "wkb access out of bounds" );
28 }
29 
30 QgsConstWkbPtr::QgsConstWkbPtr( const unsigned char *p, int size )
31 {
32  mP = const_cast< unsigned char * >( p );
33  mEnd = mP + size;
34  mEndianSwap = false;
35  mWkbType = QgsWKBTypes::Unknown;
36 }
37 
39 {
40  if ( !mP )
41  return QgsWKBTypes::Unknown;
42 
43  char wkbEndian;
44  *this >> wkbEndian;
45  mEndianSwap = wkbEndian != QgsApplication::endian();
46 
47  int wkbType;
48  *this >> wkbType;
49  mWkbType = static_cast<QgsWKBTypes::Type>( wkbType );
50 
51  return mWkbType;
52 }
53 
55 {
56  if ( !mP || mP + size > mEnd )
57  throw QgsWkbException( "wkb access out of bounds" );
58 }
59 
61 {
62  read( point.rx() );
63  read( point.ry() );
64  return *this;
65 }
66 
68 {
69  int skipZM = ( QgsWKBTypes::coordDimensions( mWkbType ) - 2 ) * sizeof( double );
70  Q_ASSERT( skipZM >= 0 );
71 
72  unsigned int nPoints;
73  read( nPoints );
74 
75  points.resize( nPoints );
76  QPointF* ptr = points.data();
77 
78  for ( unsigned int i = 0; i < nPoints; ++i, ++ptr )
79  {
80  read( ptr->rx() );
81  read( ptr->ry() );
82  mP += skipZM;
83  }
84  return *this;
85 }
static int coordDimensions(Type type)
Returns the coordinate dimension of the geometry type as an integer.
Definition: qgswkbtypes.h:573
static endian_t endian()
Returns whether this machine uses big or little endian.
T * data()
QgsConstWkbPtr(const unsigned char *p, int size)
Definition: qgswkbptr.cpp:30
const QgsConstWkbPtr & operator>>(double &v) const
Definition: qgswkbptr.h:118
void resize(int size)
QgsWkbPtr(unsigned char *p, int size)
Definition: qgswkbptr.cpp:17
qreal & rx()
qreal & ry()
void verifyBound(int size) const
Verify bounds.
Definition: qgswkbptr.cpp:54
int size() const
Definition: qgswkbptr.h:83
QgsWKBTypes::Type readHeader() const
Definition: qgswkbptr.cpp:38