/src/gdal/ogr/ogrsf_frmts/vfk/vfkreaderp.h
Line | Count | Source |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Project: VFK Reader |
4 | | * Purpose: Private Declarations for OGR free VFK Reader code. |
5 | | * Author: Martin Landa, landa.martin gmail.com |
6 | | * |
7 | | ****************************************************************************** |
8 | | * Copyright (c) 2012-2018, Martin Landa <landa.martin gmail.com> |
9 | | * |
10 | | * SPDX-License-Identifier: MIT |
11 | | ****************************************************************************/ |
12 | | |
13 | | #ifndef GDAL_OGR_VFK_VFKREADERP_H_INCLUDED |
14 | | #define GDAL_OGR_VFK_VFKREADERP_H_INCLUDED |
15 | | |
16 | | #include <map> |
17 | | #include <string> |
18 | | |
19 | | #include "vfkreader.h" |
20 | | #include "ogr_api.h" |
21 | | |
22 | | #include "sqlite3.h" |
23 | | |
24 | | class VFKReader; |
25 | | |
26 | | /************************************************************************/ |
27 | | /* VFKReader */ |
28 | | /************************************************************************/ |
29 | | class VFKReader : public IVFKReader |
30 | | { |
31 | | private: |
32 | | const char *m_pszEncoding; |
33 | | |
34 | | VSILFILE *m_poFD; |
35 | | char *ReadLine(); |
36 | | |
37 | | void AddInfo(const char *) override; |
38 | | |
39 | | CPL_DISALLOW_COPY_ASSIGN(VFKReader) |
40 | | |
41 | | protected: |
42 | | char *m_pszFilename; |
43 | | VSIStatBufL *m_poFStat; |
44 | | bool m_bAmendment; |
45 | | bool m_bFileField; |
46 | | int m_nDataBlockCount; |
47 | | IVFKDataBlock **m_papoDataBlock; |
48 | | |
49 | | IVFKDataBlock *CreateDataBlock(const char *) override; |
50 | | void AddDataBlock(IVFKDataBlock *, const char *) override; |
51 | | OGRErr AddFeature(IVFKDataBlock *, VFKFeature *) override; |
52 | | void ReadEncoding(); |
53 | | |
54 | | // Metadata. |
55 | | std::map<CPLString, CPLString> poInfo; |
56 | | |
57 | | public: |
58 | | explicit VFKReader(const GDALOpenInfo *); |
59 | | ~VFKReader() override; |
60 | | |
61 | | const char *GetFilename() const override |
62 | 0 | { |
63 | 0 | return m_pszFilename; |
64 | 0 | } |
65 | | |
66 | | const char *GetEncoding() const override |
67 | 64.6k | { |
68 | 64.6k | return m_pszEncoding; |
69 | 64.6k | } |
70 | | |
71 | | bool IsSpatial() const override |
72 | 0 | { |
73 | 0 | return false; |
74 | 0 | } |
75 | | |
76 | | bool IsPreProcessed() const override |
77 | 0 | { |
78 | 0 | return false; |
79 | 0 | } |
80 | | |
81 | | bool IsValid() const override |
82 | 3.74k | { |
83 | 3.74k | return m_poFD != nullptr; |
84 | 3.74k | } |
85 | | |
86 | | bool HasFileField() const override |
87 | 23.4k | { |
88 | 23.4k | return m_bFileField; |
89 | 23.4k | } |
90 | | |
91 | | int ReadDataBlocks(bool = false) override; |
92 | | int64_t ReadDataRecords(IVFKDataBlock * = nullptr) override; |
93 | | int LoadGeometry() override; |
94 | | |
95 | | int GetDataBlockCount() const override |
96 | 89.0k | { |
97 | 89.0k | return m_nDataBlockCount; |
98 | 89.0k | } |
99 | | |
100 | | IVFKDataBlock *GetDataBlock(int) const override; |
101 | | IVFKDataBlock *GetDataBlock(const char *) const override; |
102 | | |
103 | | const char *GetInfo(const char *) override; |
104 | | }; |
105 | | |
106 | | /************************************************************************/ |
107 | | /* VFKReaderSQLite */ |
108 | | /************************************************************************/ |
109 | | |
110 | | class VFKReaderSQLite final : public VFKReader |
111 | | { |
112 | | private: |
113 | | char *m_pszDBname; |
114 | | sqlite3 *m_poDB; |
115 | | bool m_bSpatial; |
116 | | bool m_bNewDb; |
117 | | bool m_bDbSource; |
118 | | |
119 | | IVFKDataBlock *CreateDataBlock(const char *) override; |
120 | | void AddDataBlock(IVFKDataBlock *, const char *) override; |
121 | | OGRErr AddFeature(IVFKDataBlock *, VFKFeature *) override; |
122 | | |
123 | | void StoreInfo2DB(); |
124 | | |
125 | | void CreateIndex(const char *, const char *, const char *, bool = true); |
126 | | void CreateIndices(); |
127 | | |
128 | | friend class VFKFeatureSQLite; |
129 | | |
130 | | public: |
131 | | explicit VFKReaderSQLite(const GDALOpenInfo *); |
132 | | ~VFKReaderSQLite() override; |
133 | | |
134 | | bool IsSpatial() const override |
135 | 7.00k | { |
136 | 7.00k | return m_bSpatial; |
137 | 7.00k | } |
138 | | |
139 | | bool IsPreProcessed() const override |
140 | 0 | { |
141 | 0 | return !m_bNewDb; |
142 | 0 | } |
143 | | |
144 | | bool IsValid() const override |
145 | 3.74k | { |
146 | 3.74k | return VFKReader::IsValid() && m_poDB != nullptr; |
147 | 3.74k | } |
148 | | |
149 | | int ReadDataBlocks(bool = false) override; |
150 | | int64_t ReadDataRecords(IVFKDataBlock * = nullptr) override; |
151 | | |
152 | | sqlite3_stmt *PrepareStatement(const char *); |
153 | | OGRErr ExecuteSQL(const char *, CPLErr = CE_Failure); |
154 | | OGRErr ExecuteSQL(sqlite3_stmt *&); |
155 | | }; |
156 | | |
157 | | #endif // GDAL_OGR_VFK_VFKREADERP_H_INCLUDED |