QGIS API Documentation  2.14.0-Essen
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 }
36 
38 {
39  if ( !mP )
40  return QgsWKBTypes::Unknown;
41 
42  char wkbEndian;
43  *this >> wkbEndian;
44  mEndianSwap = wkbEndian != QgsApplication::endian();
45 
46  int wkbType;
47  *this >> wkbType;
48 
49  return static_cast<QgsWKBTypes::Type>( wkbType );
50 }
51 
52 void QgsConstWkbPtr::verifyBound( int size ) const
53 {
54  if ( !mP || mP + size > mEnd )
55  throw QgsWkbException( "wkb access out of bounds" );
56 }
static endian_t endian()
Returns whether this machine uses big or little endian.
QgsWKBTypes::Type readHeader() const
Definition: qgswkbptr.cpp:37
QgsConstWkbPtr(const unsigned char *p, int size)
Definition: qgswkbptr.cpp:30
int size() const
Definition: qgswkbptr.h:81
QgsWkbPtr(unsigned char *p, int size)
Definition: qgswkbptr.cpp:17