QGIS API Documentation  2.14.0-Essen
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 
26 class CORE_EXPORT QgsWkbException : public QgsException
27 {
28  public:
29  QgsWkbException( QString const &what ) : QgsException( what ) {}
30 };
31 
32 
37 class CORE_EXPORT QgsWkbPtr
38 {
39  mutable unsigned char *mP;
40  unsigned char *mStart;
41  unsigned char *mEnd;
42 
43  void verifyBound( int size ) const;
44 
45  template<typename T> void read( T& v ) const
46  {
47  verifyBound( sizeof v );
48  memcpy( &v, mP, sizeof v );
49  mP += sizeof v;
50  }
51 
52  template<typename T> void write( T& v ) const
53  {
54  verifyBound( sizeof v );
55  memcpy( mP, &v, sizeof v );
56  mP += sizeof v;
57  }
58 
59  public:
60  QgsWkbPtr( unsigned char *p, int size );
61 
62  inline const QgsWkbPtr &operator>>( double &v ) const { read( v ); return *this; }
63  inline const QgsWkbPtr &operator>>( float &r ) const { double v; read( v ); r = v; return *this; }
64  inline const QgsWkbPtr &operator>>( int &v ) const { read( v ); return *this; }
65  inline const QgsWkbPtr &operator>>( unsigned int &v ) const { read( v ); return *this; }
66  inline const QgsWkbPtr &operator>>( char &v ) const { read( v ); return *this; }
67  inline const QgsWkbPtr &operator>>( QgsWKBTypes::Type &v ) const { read( v ); return *this; }
68  inline const QgsWkbPtr &operator>>( QGis::WkbType &v ) const { read( v ); return *this; }
69 
70  inline QgsWkbPtr &operator<<( const double &v ) { write( v ); return *this; }
71  inline QgsWkbPtr &operator<<( const float &r ) { double v = r; write( v ); return *this; }
72  inline QgsWkbPtr &operator<<( const int &v ) { write( v ); return *this; }
73  inline QgsWkbPtr &operator<<( const unsigned int &v ) { write( v ); return *this; }
74  inline QgsWkbPtr &operator<<( const char &v ) { write( v ); return *this; }
75  inline QgsWkbPtr &operator<<( const QgsWKBTypes::Type &v ) { write( v ); return *this; }
76  inline QgsWkbPtr &operator<<( const QGis::WkbType &v ) { write( v ); return *this; }
77 
78  inline void operator+=( int n ) { verifyBound( n ); mP += n; }
79 
80  inline operator unsigned char *() const { return mP; }
81  inline int size() const { return mEnd - mStart; }
82  inline int remaining() const { return mEnd - mP; }
83  inline int writtenSize() const { return mP - mStart; }
84 };
85 
90 class CORE_EXPORT QgsConstWkbPtr
91 {
92  mutable unsigned char *mP;
93  unsigned char *mEnd;
94  mutable bool mEndianSwap;
95 
96  void verifyBound( int size ) const;
97 
98  template<typename T> void read( T& v ) const
99  {
100  verifyBound( sizeof v );
101  memcpy( &v, mP, sizeof( v ) );
102  mP += sizeof( v );
103  if ( mEndianSwap )
105  }
106 
107  public:
108  QgsConstWkbPtr( const unsigned char *p, int size );
109  QgsWKBTypes::Type readHeader() const;
110 
111  inline const QgsConstWkbPtr &operator>>( double &v ) const { read( v ); return *this; }
112  inline const QgsConstWkbPtr &operator>>( float &r ) const { double v; read( v ); r = v; return *this; }
113  inline const QgsConstWkbPtr &operator>>( int &v ) const { read( v ); return *this; }
114  inline const QgsConstWkbPtr &operator>>( unsigned int &v ) const { read( v ); return *this; }
115  inline const QgsConstWkbPtr &operator>>( char &v ) const { read( v ); return *this; }
116 
117  inline void operator+=( int n ) { verifyBound( n ); mP += n; }
118  inline void operator-=( int n ) { mP -= n; }
119 
120  inline operator const unsigned char *() const { return mP; }
121  inline int remaining() const { return mEnd - mP; }
122 };
123 
124 #endif // QGSWKBPTR_H
static void endian_swap(T &value)
Swap the endianness of the specified value.
QgsWkbException(QString const &what)
Definition: qgswkbptr.h:29
int remaining() const
Definition: qgswkbptr.h:121
const QgsConstWkbPtr & operator>>(char &v) const
Definition: qgswkbptr.h:115
const QgsConstWkbPtr & operator>>(double &v) const
Definition: qgswkbptr.h:111
const QgsWkbPtr & operator>>(int &v) const
Definition: qgswkbptr.h:64
WkbType
Used for symbology operations.
Definition: qgis.h:57
void operator+=(int n)
Definition: qgswkbptr.h:78
const QgsWkbPtr & operator>>(float &r) const
Definition: qgswkbptr.h:63
int writtenSize() const
Definition: qgswkbptr.h:83
const QgsConstWkbPtr & operator>>(unsigned int &v) const
Definition: qgswkbptr.h:114
QgsWkbPtr & operator<<(const int &v)
Definition: qgswkbptr.h:72
QgsWkbPtr & operator<<(const QgsWKBTypes::Type &v)
Definition: qgswkbptr.h:75
QgsWkbPtr & operator<<(const double &v)
Definition: qgswkbptr.h:70
QgsWkbPtr & operator<<(const QGis::WkbType &v)
Definition: qgswkbptr.h:76
const QgsWkbPtr & operator>>(double &v) const
Definition: qgswkbptr.h:62
int size() const
Definition: qgswkbptr.h:81
const QgsWkbPtr & operator>>(char &v) const
Definition: qgswkbptr.h:66
const QgsWkbPtr & operator>>(QGis::WkbType &v) const
Definition: qgswkbptr.h:68
const QgsConstWkbPtr & operator>>(int &v) const
Definition: qgswkbptr.h:113
QgsWkbPtr & operator<<(const float &r)
Definition: qgswkbptr.h:71
QgsWkbPtr & operator<<(const unsigned int &v)
Definition: qgswkbptr.h:73
int remaining() const
Definition: qgswkbptr.h:82
const QgsWkbPtr & operator>>(unsigned int &v) const
Definition: qgswkbptr.h:65
void operator+=(int n)
Definition: qgswkbptr.h:117
const QgsConstWkbPtr & operator>>(float &r) const
Definition: qgswkbptr.h:112
void operator-=(int n)
Definition: qgswkbptr.h:118
Defines a qgis exception class.
Definition: qgsexception.h:25
QgsWkbPtr & operator<<(const char &v)
Definition: qgswkbptr.h:74
const QgsWkbPtr & operator>>(QgsWKBTypes::Type &v) const
Definition: qgswkbptr.h:67