Coverage Report

Created: 2026-11-12 08:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/ogr/ogrsf_frmts/flatgeobuf/geometryreader.h
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Project:  FlatGeobuf driver
4
 * Purpose:  GeometryReader class declarations.
5
 * Author:   Björn Harrtell <bjorn at wololo dot org>
6
 *
7
 ******************************************************************************
8
 * Copyright (c) 2018-2019, Björn Harrtell <bjorn at wololo dot org>
9
 *
10
 * SPDX-License-Identifier: MIT
11
 ****************************************************************************/
12
13
#ifndef FLATGEOBUF_GEOMETRYREADER_H_INCLUDED
14
#define FLATGEOBUF_GEOMETRYREADER_H_INCLUDED
15
16
#if defined(__clang__)
17
#pragma clang diagnostic push
18
#pragma clang diagnostic ignored "-Wweak-vtables"
19
#endif
20
#include "feature_generated.h"
21
#if defined(__clang__)
22
#pragma clang diagnostic pop
23
#endif
24
25
#include "ogr_p.h"
26
27
namespace ogr_flatgeobuf
28
{
29
30
class GeometryReader
31
{
32
  private:
33
    const FlatGeobuf::Geometry *m_geometry;
34
    const FlatGeobuf::GeometryType m_geometryType;
35
    const bool m_hasZ;
36
    const bool m_hasM;
37
38
    const double *m_xy = nullptr;
39
    uint32_t m_xylength = 0;
40
    uint32_t m_length = 0;
41
    uint32_t m_offset = 0;
42
43
    OGRPoint *readPoint();
44
    OGRMultiPoint *readMultiPoint();
45
    OGRErr readSimpleCurve(OGRSimpleCurve *c);
46
    OGRMultiLineString *readMultiLineString();
47
    OGRPolygon *readPolygon();
48
    OGRMultiPolygon *readMultiPolygon();
49
    OGRGeometryCollection *readGeometryCollection();
50
    OGRCompoundCurve *readCompoundCurve();
51
    OGRCurvePolygon *readCurvePolygon();
52
    OGRMultiCurve *readMultiCurve();
53
    OGRMultiSurface *readMultiSurface();
54
    OGRPolyhedralSurface *readPolyhedralSurface();
55
    OGRTriangulatedSurface *readTIN();
56
    OGRTriangle *readTriangle();
57
58
    OGRGeometry *readPart(const FlatGeobuf::Geometry *part)
59
2.44k
    {
60
2.44k
        return GeometryReader(part, m_hasZ, m_hasM).read();
61
2.44k
    }
62
63
    OGRGeometry *readPart(const FlatGeobuf::Geometry *part,
64
                          const FlatGeobuf::GeometryType geometryType)
65
1.17k
    {
66
1.17k
        return GeometryReader(part, geometryType, m_hasZ, m_hasM).read();
67
1.17k
    }
68
69
    template <class T> T *readSimpleCurve(const bool halfLength = false)
70
8.71k
    {
71
8.71k
        if (halfLength)
72
2.34k
            m_length = m_length / 2;
73
8.71k
        const auto csc = new T();
74
8.71k
        if (readSimpleCurve(csc) != OGRERR_NONE)
75
3.20k
        {
76
3.20k
            delete csc;
77
3.20k
            return nullptr;
78
3.20k
        }
79
5.51k
        return csc;
80
8.71k
    }
OGRLineString* ogr_flatgeobuf::GeometryReader::readSimpleCurve<OGRLineString>(bool)
Line
Count
Source
70
544
    {
71
544
        if (halfLength)
72
68
            m_length = m_length / 2;
73
544
        const auto csc = new T();
74
544
        if (readSimpleCurve(csc) != OGRERR_NONE)
75
35
        {
76
35
            delete csc;
77
35
            return nullptr;
78
35
        }
79
509
        return csc;
80
544
    }
OGRLinearRing* ogr_flatgeobuf::GeometryReader::readSimpleCurve<OGRLinearRing>(bool)
Line
Count
Source
70
5.89k
    {
71
5.89k
        if (halfLength)
72
0
            m_length = m_length / 2;
73
5.89k
        const auto csc = new T();
74
5.89k
        if (readSimpleCurve(csc) != OGRERR_NONE)
75
3.17k
        {
76
3.17k
            delete csc;
77
3.17k
            return nullptr;
78
3.17k
        }
79
2.72k
        return csc;
80
5.89k
    }
OGRCircularString* ogr_flatgeobuf::GeometryReader::readSimpleCurve<OGRCircularString>(bool)
Line
Count
Source
70
2.27k
    {
71
2.27k
        if (halfLength)
72
2.27k
            m_length = m_length / 2;
73
2.27k
        const auto csc = new T();
74
2.27k
        if (readSimpleCurve(csc) != OGRERR_NONE)
75
0
        {
76
0
            delete csc;
77
0
            return nullptr;
78
0
        }
79
2.27k
        return csc;
80
2.27k
    }
81
82
  public:
83
    GeometryReader(const FlatGeobuf::Geometry *geometry,
84
                   const FlatGeobuf::GeometryType geometryType, const bool hasZ,
85
                   const bool hasM)
86
4.69k
        : m_geometry(geometry), m_geometryType(geometryType), m_hasZ(hasZ),
87
4.69k
          m_hasM(hasM)
88
4.69k
    {
89
4.69k
    }
90
91
    GeometryReader(const FlatGeobuf::Geometry *geometry, const bool hasZ,
92
                   const bool hasM)
93
2.44k
        : m_geometry(geometry), m_geometryType(geometry->type()), m_hasZ(hasZ),
94
2.44k
          m_hasM(hasM)
95
2.44k
    {
96
2.44k
    }
97
98
    OGRGeometry *read();
99
};
100
101
}  // namespace ogr_flatgeobuf
102
103
#endif /* ndef FLATGEOBUF_GEOMETRYREADER_H_INCLUDED */