/src/gdal/ogr/ogrsf_frmts/geojson/ogrjsoncollectionstreamingparser.h
Line | Count | Source (jump to first uncovered line) |
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 | | json_object *m_poRootObj = nullptr; |
39 | | size_t m_nRootObjMemEstimate = 0; |
40 | | json_object *m_poCurObj = nullptr; |
41 | | size_t m_nCurObjMemEstimate = 0; |
42 | | GUIntBig m_nTotalOGRFeatureMemEstimate = 0; |
43 | | bool m_bKeySet = false; |
44 | | std::string m_osCurKey{}; |
45 | | std::vector<json_object *> m_apoCurObj{}; |
46 | | std::vector<bool> m_abFirstMember{}; |
47 | | bool m_bStoreNativeData = false; |
48 | | std::string m_osJson{}; |
49 | | size_t m_nMaxObjectSize = 0; |
50 | | |
51 | | bool m_bStartFeature = false; |
52 | | bool m_bEndFeature = false; |
53 | | |
54 | | void AppendObject(json_object *poNewObj); |
55 | | |
56 | | CPL_DISALLOW_COPY_ASSIGN(OGRJSONCollectionStreamingParser) |
57 | | |
58 | | protected: |
59 | | inline bool IsFirstPass() const |
60 | 0 | { |
61 | 0 | return m_bFirstPass; |
62 | 0 | } |
63 | | |
64 | | virtual void GotFeature(json_object *poObj, bool bFirstPass, |
65 | | const std::string &osJson) = 0; |
66 | | virtual void TooComplex() = 0; |
67 | | |
68 | | public: |
69 | | OGRJSONCollectionStreamingParser(bool bFirstPass, bool bStoreNativeData, |
70 | | size_t nMaxObjectSize); |
71 | | ~OGRJSONCollectionStreamingParser(); |
72 | | |
73 | | virtual void String(const char * /*pszValue*/, size_t) override; |
74 | | virtual void Number(const char * /*pszValue*/, size_t) override; |
75 | | virtual void Boolean(bool b) override; |
76 | | virtual void Null() override; |
77 | | |
78 | | virtual void StartObject() override; |
79 | | virtual void EndObject() override; |
80 | | virtual void StartObjectMember(const char * /*pszKey*/, size_t) override; |
81 | | |
82 | | virtual void StartArray() override; |
83 | | virtual void EndArray() override; |
84 | | virtual void StartArrayMember() override; |
85 | | |
86 | | virtual void Exception(const char * /*pszMessage*/) override; |
87 | | |
88 | | json_object *StealRootObject(); |
89 | | |
90 | | inline bool IsTypeKnown() const |
91 | 0 | { |
92 | 0 | return m_bIsTypeKnown; |
93 | 0 | } |
94 | | |
95 | | inline bool IsFeatureCollection() const |
96 | 0 | { |
97 | 0 | return m_bIsFeatureCollection; |
98 | 0 | } |
99 | | |
100 | | inline GUIntBig GetTotalOGRFeatureMemEstimate() const |
101 | 0 | { |
102 | 0 | return m_nTotalOGRFeatureMemEstimate; |
103 | 0 | } |
104 | | |
105 | | inline bool CanEasilyAppend() const |
106 | 0 | { |
107 | 0 | return m_bCanEasilyAppend; |
108 | 0 | } |
109 | | |
110 | | inline void ResetFeatureDetectionState() |
111 | 0 | { |
112 | 0 | m_bStartFeature = false; |
113 | 0 | m_bEndFeature = false; |
114 | 0 | } |
115 | | |
116 | | inline bool IsStartFeature() const |
117 | 0 | { |
118 | 0 | return m_bStartFeature; |
119 | 0 | } |
120 | | |
121 | | inline bool IsEndFeature() const |
122 | 0 | { |
123 | 0 | return m_bEndFeature; |
124 | 0 | } |
125 | | }; |
126 | | |
127 | | #endif // OGRJSONCOLLECTIONSTREAMING_PARSER_H_INCLUDED |