Coverage Report

Created: 2025-11-16 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/ogr/ogrsf_frmts/geojson/ogrjsoncollectionstreamingparser.h
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Project:  OpenGIS Simple Features Reference Implementation
4
 * Purpose:  Streaming parser for GeoJSON-like FeatureCollection
5
 * Author:   Even Rouault <even.rouault at spatialys.com>
6
 *
7
 ******************************************************************************
8
 * Copyright (c) 2017, Even Rouault <even.rouault at spatialys.com>
9
 *
10
 * SPDX-License-Identifier: MIT
11
 ****************************************************************************/
12
13
#ifndef OGRJSONCOLLECTIONSTREAMING_PARSER_H_INCLUDED
14
#define OGRJSONCOLLECTIONSTREAMING_PARSER_H_INCLUDED
15
16
#include "cpl_json_streaming_parser.h"
17
18
#include <json.h>  // JSON-C
19
20
/************************************************************************/
21
/*                      OGRJSONCollectionStreamingParser                */
22
/************************************************************************/
23
24
/** Streaming parser for GeoJSON-like FeatureCollection */
25
class OGRJSONCollectionStreamingParser CPL_NON_FINAL
26
    : public CPLJSonStreamingParser
27
{
28
    bool m_bFirstPass = false;
29
30
    int m_nDepth = 0;
31
    bool m_bInFeatures = false;
32
    bool m_bCanEasilyAppend = false;
33
    bool m_bInFeaturesArray = false;
34
    bool m_bInCoordinates = false;
35
    bool m_bInType = false;
36
    bool m_bIsTypeKnown = false;
37
    bool m_bIsFeatureCollection = false;
38
    bool m_bInMeasures = false;
39
    bool m_bInMeasuresEnabled = false;
40
    json_object *m_poRootObj = nullptr;
41
    size_t m_nRootObjMemEstimate = 0;
42
    json_object *m_poCurObj = nullptr;
43
    size_t m_nCurObjMemEstimate = 0;
44
    GUIntBig m_nTotalOGRFeatureMemEstimate = 0;
45
    bool m_bKeySet = false;
46
    std::string m_osCurKey{};
47
    std::vector<json_object *> m_apoCurObj{};
48
    std::vector<bool> m_abFirstMember{};
49
    bool m_bStoreNativeData = false;
50
    std::string m_osJson{};
51
    size_t m_nMaxObjectSize = 0;
52
53
    bool m_bStartFeature = false;
54
    bool m_bEndFeature = false;
55
56
    void AppendObject(json_object *poNewObj);
57
58
    CPL_DISALLOW_COPY_ASSIGN(OGRJSONCollectionStreamingParser)
59
60
  protected:
61
    inline bool IsFirstPass() const
62
0
    {
63
0
        return m_bFirstPass;
64
0
    }
65
66
    virtual void GotFeature(json_object *poObj, bool bFirstPass,
67
                            const std::string &osJson) = 0;
68
    virtual void TooComplex() = 0;
69
70
    bool m_bHasTopLevelMeasures = false;
71
72
  public:
73
    OGRJSONCollectionStreamingParser(bool bFirstPass, bool bStoreNativeData,
74
                                     size_t nMaxObjectSize);
75
    ~OGRJSONCollectionStreamingParser() override;
76
77
    void String(std::string_view) override;
78
    void Number(std::string_view) override;
79
    void Boolean(bool b) override;
80
    void Null() override;
81
82
    void StartObject() override;
83
    void EndObject() override;
84
    void StartObjectMember(std::string_view) override;
85
86
    void StartArray() override;
87
    void EndArray() override;
88
    void StartArrayMember() override;
89
90
    void Exception(const char * /*pszMessage*/) override;
91
92
    json_object *StealRootObject();
93
94
    inline bool HasTopLevelMeasures() const
95
0
    {
96
0
        return m_bHasTopLevelMeasures;
97
0
    }
98
99
    inline bool IsTypeKnown() const
100
0
    {
101
0
        return m_bIsTypeKnown;
102
0
    }
103
104
    inline bool IsFeatureCollection() const
105
0
    {
106
0
        return m_bIsFeatureCollection;
107
0
    }
108
109
    inline GUIntBig GetTotalOGRFeatureMemEstimate() const
110
0
    {
111
0
        return m_nTotalOGRFeatureMemEstimate;
112
0
    }
113
114
    inline bool CanEasilyAppend() const
115
0
    {
116
0
        return m_bCanEasilyAppend;
117
0
    }
118
119
    inline void ResetFeatureDetectionState()
120
0
    {
121
0
        m_bStartFeature = false;
122
0
        m_bEndFeature = false;
123
0
    }
124
125
    inline bool IsStartFeature() const
126
0
    {
127
0
        return m_bStartFeature;
128
0
    }
129
130
    inline bool IsEndFeature() const
131
0
    {
132
0
        return m_bEndFeature;
133
0
    }
134
};
135
136
#endif  // OGRJSONCOLLECTIONSTREAMING_PARSER_H_INCLUDED