QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 "qgswkbtypes.h"
19 #include "qgsapplication.h"
20 #include "qgis.h"
21 #include "qgsexception.h"
22 #include "qpolygon.h"
23 
27 class CORE_EXPORT QgsWkbException : public QgsException
28 {
29  public:
30  QgsWkbException( QString const &what ) : QgsException( what ) {}
31 };
32 
33 
39 class CORE_EXPORT QgsWkbPtr
40 {
41  mutable unsigned char *mP;
42  unsigned char *mStart;
43  unsigned char *mEnd;
44 
45  void verifyBound( int size ) const;
46 
47  template<typename T> void read( T& v ) const
48  {
49  verifyBound( sizeof v );
50  memcpy( &v, mP, sizeof v );
51  mP += sizeof v;
52  }
53 
54  template<typename T> void write( T& v ) const
55  {
56  verifyBound( sizeof v );
57  memcpy( mP, &v, sizeof v );
58  mP += sizeof v;
59  }
60 
61  public:
62  QgsWkbPtr( unsigned char *p, int size );
63 
64  inline const QgsWkbPtr &operator>>( double &v ) const { read( v ); return *this; }
65  inline const QgsWkbPtr &operator>>( float &r ) const { double v; read( v ); r = v; return *this; }
66  inline const QgsWkbPtr &operator>>( int &v ) const { read( v ); return *this; }
67  inline const QgsWkbPtr &operator>>( unsigned int &v ) const { read( v ); return *this; }
68  inline const QgsWkbPtr &operator>>( char &v ) const { read( v ); return *this; }
69  inline const QgsWkbPtr &operator>>( QgsWKBTypes::Type &v ) const { read( v ); return *this; }
70  inline const QgsWkbPtr &operator>>( QGis::WkbType &v ) const { read( v ); return *this; }
71 
72  inline QgsWkbPtr &operator<<( const double &v ) { write( v ); return *this; }
73  inline QgsWkbPtr &operator<<( const float &r ) { double v = r; write( v ); return *this; }
74  inline QgsWkbPtr &operator<<( const int &v ) { write( v ); return *this; }
75  inline QgsWkbPtr &operator<<( const unsigned int &v ) { write( v ); return *this; }
76  inline QgsWkbPtr &operator<<( const char &v ) { write( v ); return *this; }
77  inline QgsWkbPtr &operator<<( const QgsWKBTypes::Type &v ) { write( v ); return *this; }
78  inline QgsWkbPtr &operator<<( const QGis::WkbType &v ) { write( v ); return *this; }
79 
80  inline void operator+=( int n ) { verifyBound( n ); mP += n; }
81 
82  inline operator unsigned char *() const { return mP; }
83  inline int size() const { return mEnd - mStart; }
84  inline int remaining() const { return mEnd - mP; }
85  inline int writtenSize() const { return mP - mStart; }
86 };
87 
93 class CORE_EXPORT QgsConstWkbPtr
94 {
95  protected:
96  mutable unsigned char *mP;
97  unsigned char *mEnd;
98  mutable bool mEndianSwap;
100 
102  void verifyBound( int size ) const;
103 
105  template<typename T> void read( T& v ) const
106  {
107  verifyBound( sizeof v );
108  memcpy( &v, mP, sizeof( v ) );
109  mP += sizeof( v );
110  if ( mEndianSwap )
112  }
113 
114  public:
115  QgsConstWkbPtr( const unsigned char *p, int size );
116  QgsWKBTypes::Type readHeader() const;
117 
118  inline const QgsConstWkbPtr &operator>>( double &v ) const { read( v ); return *this; }
119  inline const QgsConstWkbPtr &operator>>( float &r ) const { double v; read( v ); r = v; return *this; }
120  inline const QgsConstWkbPtr &operator>>( int &v ) const { read( v ); return *this; }
121  inline const QgsConstWkbPtr &operator>>( unsigned int &v ) const { read( v ); return *this; }
122  inline const QgsConstWkbPtr &operator>>( char &v ) const { read( v ); return *this; }
123 
125  virtual const QgsConstWkbPtr &operator>>( QPointF &point ) const;
127  virtual const QgsConstWkbPtr &operator>>( QPolygonF &points ) const;
128 
129  inline void operator+=( int n ) { verifyBound( n ); mP += n; }
130  inline void operator-=( int n ) { mP -= n; }
131 
132  inline operator const unsigned char *() const { return mP; }
133  inline int remaining() const { return mEnd - mP; }
134 };
135 
136 #endif // QGSWKBPTR_H
const QgsWkbPtr & operator>>(int &v) const
Definition: qgswkbptr.h:66
static void endian_swap(T &value)
Swap the endianness of the specified value.
const QgsWkbPtr & operator>>(double &v) const
Definition: qgswkbptr.h:64
int remaining() const
Definition: qgswkbptr.h:84
QgsWkbException(QString const &what)
Definition: qgswkbptr.h:30
unsigned char * mP
Definition: qgswkbptr.h:96
const QgsConstWkbPtr & operator>>(char &v) const
Definition: qgswkbptr.h:122
WkbType
Used for symbology operations.
Definition: qgis.h:61
void operator+=(int n)
Definition: qgswkbptr.h:80
const QgsConstWkbPtr & operator>>(float &r) const
Definition: qgswkbptr.h:119
QDataStream & operator>>(QDataStream &in, QgsFeature &feature)
Reads a feature from stream in into feature.
Definition: qgsfeature.cpp:314
const QgsWkbPtr & operator>>(float &r) const
Definition: qgswkbptr.h:65
int writtenSize() const
Definition: qgswkbptr.h:85
const QgsWkbPtr & operator>>(char &v) const
Definition: qgswkbptr.h:68
QgsWkbPtr & operator<<(const int &v)
Definition: qgswkbptr.h:74
const QgsConstWkbPtr & operator>>(double &v) const
Definition: qgswkbptr.h:118
bool mEndianSwap
Definition: qgswkbptr.h:98
QgsWkbPtr & operator<<(const QgsWKBTypes::Type &v)
Definition: qgswkbptr.h:77
const QgsWkbPtr & operator>>(QgsWKBTypes::Type &v) const
Definition: qgswkbptr.h:69
QgsWkbPtr & operator<<(const double &v)
Definition: qgswkbptr.h:72
unsigned char * mEnd
Definition: qgswkbptr.h:97
QgsWkbPtr & operator<<(const QGis::WkbType &v)
Definition: qgswkbptr.h:78
int remaining() const
Definition: qgswkbptr.h:133
const QgsConstWkbPtr & operator>>(int &v) const
Definition: qgswkbptr.h:120
const QgsConstWkbPtr & operator>>(unsigned int &v) const
Definition: qgswkbptr.h:121
QgsWkbPtr & operator<<(const float &r)
Definition: qgswkbptr.h:73
QgsWkbPtr & operator<<(const unsigned int &v)
Definition: qgswkbptr.h:75
int size() const
Definition: qgswkbptr.h:83
const QgsWkbPtr & operator>>(unsigned int &v) const
Definition: qgswkbptr.h:67
const QgsWkbPtr & operator>>(QGis::WkbType &v) const
Definition: qgswkbptr.h:70
void operator+=(int n)
Definition: qgswkbptr.h:129
void operator-=(int n)
Definition: qgswkbptr.h:130
QgsWKBTypes::Type mWkbType
Definition: qgswkbptr.h:99
void read(T &v) const
Read a value.
Definition: qgswkbptr.h:105
Defines a qgis exception class.
Definition: qgsexception.h:25
QgsWkbPtr & operator<<(const char &v)
Definition: qgswkbptr.h:76