Coverage Report

Created: 2026-05-16 07:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/PROJ/include/proj/internal/io_internal.hpp
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Project:  PROJ
4
 * Purpose:  ISO19111:2019 implementation
5
 * Author:   Even Rouault <even dot rouault at spatialys dot com>
6
 *
7
 ******************************************************************************
8
 * Copyright (c) 2018, Even Rouault <even dot rouault at spatialys dot com>
9
 *
10
 * Permission is hereby granted, free of charge, to any person obtaining a
11
 * copy of this software and associated documentation files (the "Software"),
12
 * to deal in the Software without restriction, including without limitation
13
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14
 * and/or sell copies of the Software, and to permit persons to whom the
15
 * Software is furnished to do so, subject to the following conditions:
16
 *
17
 * The above copyright notice and this permission notice shall be included
18
 * in all copies or substantial portions of the Software.
19
 *
20
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26
 * DEALINGS IN THE SOFTWARE.
27
 ****************************************************************************/
28
29
#ifndef FROM_PROJ_CPP
30
#error This file should only be included from a PROJ cpp file
31
#endif
32
33
#ifndef IO_INTERNAL_HH_INCLUDED
34
#define IO_INTERNAL_HH_INCLUDED
35
36
#include <string>
37
#include <vector>
38
39
#include "proj/io.hpp"
40
#include "proj/util.hpp"
41
42
//! @cond Doxygen_Suppress
43
44
NS_PROJ_START
45
46
namespace io {
47
48
// CRS subtypes
49
118k
#define CRS_SUBTYPE_GEOG_2D "geographic 2D"
50
71.2k
#define CRS_SUBTYPE_GEOG_3D "geographic 3D"
51
41.9k
#define CRS_SUBTYPE_GEOCENTRIC "geocentric"
52
372
#define CRS_SUBTYPE_OTHER "other"
53
159
#define CRS_SUBTYPE_PROJECTED "projected"
54
39
#define CRS_SUBTYPE_DERIVED_PROJECTED "derived projected"
55
39
#define CRS_SUBTYPE_ENGINEERING "engineering"
56
318
#define CRS_SUBTYPE_VERTICAL "vertical"
57
36
#define CRS_SUBTYPE_COMPOUND "compound"
58
59
// ---------------------------------------------------------------------------
60
61
class WKTConstants {
62
  public:
63
    // WKT1
64
    static const std::string GEOCCS;
65
    static const std::string GEOGCS;
66
    static const std::string DATUM; // WKT2 preferred too
67
    static const std::string UNIT;
68
    static const std::string SPHEROID;
69
    static const std::string AXIS;   // WKT2 too
70
    static const std::string PRIMEM; // WKT2 too
71
    static const std::string AUTHORITY;
72
    static const std::string PROJCS;
73
    static const std::string PROJECTION;
74
    static const std::string PARAMETER; // WKT2 too
75
    static const std::string VERT_CS;
76
    static const std::string VERTCS; // WKT1 ESRI
77
    static const std::string VERT_DATUM;
78
    static const std::string COMPD_CS;
79
    static const std::string TOWGS84;     // WKT1 only
80
    static const std::string EXTENSION;   // WKT1 only - GDAL specific
81
    static const std::string LOCAL_CS;    // WKT1 only
82
    static const std::string LOCAL_DATUM; // WKT1 only
83
    static const std::string LINUNIT;     // WKT1 ESRI (ArcGIS Pro >= 2.7)
84
85
    // WKT2 preferred
86
    static const std::string GEODCRS;
87
    static const std::string LENGTHUNIT;
88
    static const std::string ANGLEUNIT;
89
    static const std::string SCALEUNIT;
90
    static const std::string TIMEUNIT;
91
    static const std::string ELLIPSOID;
92
    // underscore, since there is a CS macro in Solaris system headers
93
    static const std::string CS_;
94
    static const std::string ID;
95
    static const std::string PROJCRS;
96
    static const std::string BASEGEODCRS;
97
    static const std::string MERIDIAN;
98
    static const std::string ORDER;
99
    static const std::string ANCHOR;
100
    static const std::string ANCHOREPOCH; // WKT2-2019
101
    static const std::string CONVERSION;
102
    static const std::string METHOD;
103
    static const std::string REMARK;
104
    static const std::string GEOGCRS;     // WKT2-2019
105
    static const std::string BASEGEOGCRS; // WKT2-2019
106
    static const std::string SCOPE;
107
    static const std::string AREA;
108
    static const std::string BBOX;
109
    static const std::string CITATION;
110
    static const std::string URI;
111
    static const std::string VERTCRS;
112
    static const std::string VDATUM; // WKT2 and WKT1 ESRI
113
    static const std::string COMPOUNDCRS;
114
    static const std::string PARAMETERFILE;
115
    static const std::string COORDINATEOPERATION;
116
    static const std::string SOURCECRS;
117
    static const std::string TARGETCRS;
118
    static const std::string INTERPOLATIONCRS;
119
    static const std::string OPERATIONACCURACY;
120
    static const std::string CONCATENATEDOPERATION; // WKT2-2019
121
    static const std::string STEP;                  // WKT2-2019
122
    static const std::string BOUNDCRS;
123
    static const std::string ABRIDGEDTRANSFORMATION;
124
    static const std::string DERIVINGCONVERSION;
125
    static const std::string TDATUM;
126
    static const std::string CALENDAR; // WKT2-2019
127
    static const std::string TIMEORIGIN;
128
    static const std::string TIMECRS;
129
    static const std::string VERTICALEXTENT;
130
    static const std::string TIMEEXTENT;
131
    static const std::string USAGE;            // WKT2-2019
132
    static const std::string DYNAMIC;          // WKT2-2019
133
    static const std::string FRAMEEPOCH;       // WKT2-2019
134
    static const std::string MODEL;            // WKT2-2019
135
    static const std::string VELOCITYGRID;     // WKT2-2019
136
    static const std::string ENSEMBLE;         // WKT2-2019
137
    static const std::string MEMBER;           // WKT2-2019
138
    static const std::string ENSEMBLEACCURACY; // WKT2-2019
139
    static const std::string DERIVEDPROJCRS;   // WKT2-2019
140
    static const std::string BASEPROJCRS;      // WKT2-2019
141
    static const std::string EDATUM;
142
    static const std::string ENGCRS;
143
    static const std::string PDATUM;
144
    static const std::string PARAMETRICCRS;
145
    static const std::string PARAMETRICUNIT;
146
    static const std::string BASEVERTCRS;
147
    static const std::string BASEENGCRS;
148
    static const std::string BASEPARAMCRS;
149
    static const std::string BASETIMECRS;
150
    static const std::string VERSION;
151
    static const std::string GEOIDMODEL;           // WKT2-2019
152
    static const std::string COORDINATEMETADATA;   // WKT2-2019
153
    static const std::string EPOCH;                // WKT2-2019
154
    static const std::string AXISMINVALUE;         // WKT2-2019
155
    static const std::string AXISMAXVALUE;         // WKT2-2019
156
    static const std::string RANGEMEANING;         // WKT2-2019
157
    static const std::string POINTMOTIONOPERATION; // WKT2-2019
158
159
    // WKT2 alternate (longer or shorter)
160
    static const std::string GEODETICCRS;
161
    static const std::string GEODETICDATUM;
162
    static const std::string PROJECTEDCRS;
163
    static const std::string PRIMEMERIDIAN;
164
    static const std::string GEOGRAPHICCRS; // WKT2-2019
165
    static const std::string TRF;           // WKT2-2019
166
    static const std::string VERTICALCRS;
167
    static const std::string VERTICALDATUM;
168
    static const std::string VRF; // WKT2-2019
169
    static const std::string TIMEDATUM;
170
    static const std::string TEMPORALQUANTITY;
171
    static const std::string ENGINEERINGDATUM;
172
    static const std::string ENGINEERINGCRS;
173
    static const std::string PARAMETRICDATUM;
174
175
24.0k
    static const std::vector<std::string> &constants() { return constants_; }
176
177
  private:
178
    static std::vector<std::string> constants_;
179
    static const char *createAndAddToConstantList(const char *text);
180
};
181
182
} // namespace io
183
184
NS_PROJ_END
185
186
// ---------------------------------------------------------------------------
187
188
/** Auxiliary structure to PJ_CONTEXT storing C++ context stuff. */
189
struct PROJ_GCC_DLL projCppContext {
190
  private:
191
    NS_PROJ::io::DatabaseContextPtr databaseContext_{};
192
    PJ_CONTEXT *ctx_ = nullptr;
193
    std::string dbPath_{};
194
    std::vector<std::string> auxDbPaths_{};
195
196
    projCppContext(const projCppContext &) = delete;
197
    projCppContext &operator=(const projCppContext &) = delete;
198
199
  public:
200
    std::string lastDbPath_{};
201
    std::string lastDbMetadataItem_{};
202
    std::string lastUOMName_{};
203
    std::string lastGridFullName_{};
204
    std::string lastGridPackageName_{};
205
    std::string lastGridUrl_{};
206
207
    static std::vector<std::string> toVector(const char *const *auxDbPaths);
208
209
    explicit projCppContext(PJ_CONTEXT *ctx, const char *dbPath = nullptr,
210
                            const std::vector<std::string> &auxDbPaths = {});
211
212
    projCppContext *clone(PJ_CONTEXT *ctx) const;
213
214
    // cppcheck-suppress functionStatic
215
61.4k
    inline const std::string &getDbPath() const { return dbPath_; }
216
217
    // cppcheck-suppress functionStatic
218
61.4k
    inline const std::vector<std::string> &getAuxDbPaths() const {
219
61.4k
        return auxDbPaths_;
220
61.4k
    }
221
222
    NS_PROJ::io::DatabaseContextNNPtr PROJ_FOR_TEST getDatabaseContext();
223
224
    /** Return the database context only if already opened.
225
     * Does not attempt to open proj.db. */
226
41.3k
    inline NS_PROJ::io::DatabaseContextPtr getDatabaseContextIfOpen() const {
227
41.3k
        return databaseContext_;
228
41.3k
    }
229
230
12.6k
    void closeDb() { databaseContext_ = nullptr; }
231
};
232
233
//! @endcond
234
235
#endif // IO_INTERNAL_HH_INCLUDED