Coverage Report

Created: 2025-12-31 08:30

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/ogr/ogrsf_frmts/miramon/ogrmiramon.h
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Project:  OpenGIS Simple Features Reference Implementation
4
 * Purpose:  C++ classes for the MiraMon driver
5
 * Author:   Abel Pau
6
 ******************************************************************************
7
 * Copyright (c) 2024, Xavier Pons
8
 *
9
 * SPDX-License-Identifier: MIT
10
 ****************************************************************************/
11
12
#ifndef OGRMIRAMON_H_INCLUDED
13
#define OGRMIRAMON_H_INCLUDED
14
15
#include "ogrsf_frmts.h"
16
#include "ogr_api.h"
17
#include "cpl_string.h"
18
#include "mm_wrlayr.h"
19
20
/************************************************************************/
21
/*                             OGRMiraMonLayer                          */
22
/************************************************************************/
23
24
class OGRMiraMonLayer final
25
    : public OGRLayer,
26
      public OGRGetNextFeatureThroughRaw<OGRMiraMonLayer>
27
{
28
    OGRMiraMonLayer(const OGRMiraMonLayer &) = delete;
29
    OGRMiraMonLayer &operator=(const OGRMiraMonLayer &) = delete;
30
31
    GDALDataset *m_poDS;
32
    OGRSpatialReference *m_poSRS;
33
    OGRFeatureDefn *m_poFeatureDefn;
34
35
    GUIntBig m_iNextFID;
36
37
    // Pointer to one of three possible MiraMon layers: points,
38
    // arcs or polygons. Every time a feature is read this pointer
39
    // points to the appropriate layer
40
    struct MiraMonVectLayerInfo *phMiraMonLayer;
41
42
    // When writing a layer
43
    struct MiraMonVectLayerInfo hMiraMonLayerPNT;  // MiraMon points layer
44
    struct MiraMonVectLayerInfo hMiraMonLayerARC;  // MiraMon arcs layer
45
    struct MiraMonVectLayerInfo hMiraMonLayerPOL;  // MiraMon polygons layer
46
47
    // When reading a layer or the result of writing is only a DBF
48
    struct MiraMonVectLayerInfo hMiraMonLayerReadOrNonGeom;
49
50
    struct MiraMonFeature hMMFeature;  // Feature reading/writing
51
52
    bool m_bUpdate;
53
54
    VSILFILE *m_fp = nullptr;
55
56
    // Array of doubles used in the field features processing
57
    double *padfValues = nullptr;
58
    GInt64 *pnInt64Values = nullptr;
59
60
    OGRFeature *GetNextRawFeature();
61
    OGRFeature *GetFeature(GIntBig nFeatureId) override;
62
    void GoToFieldOfMultipleRecord(MM_INTERNAL_FID iFID,
63
                                   MM_EXT_DBF_N_RECORDS nIRecord,
64
                                   MM_EXT_DBF_N_FIELDS nIField);
65
66
    OGRErr MMDumpVertices(OGRGeometryH hGeom, MM_BOOLEAN bExternalRing,
67
                          MM_BOOLEAN bUseVFG);
68
    OGRErr MMProcessGeometry(OGRGeometryH poGeom, OGRFeature *poFeature,
69
                             MM_BOOLEAN bcalculateRecord);
70
    OGRErr MMProcessMultiGeometry(OGRGeometryH hGeom, OGRFeature *poFeature);
71
    OGRErr MMLoadGeometry(OGRGeometryH hGeom);
72
    OGRErr MMWriteGeometry();
73
    GIntBig GetFeatureCount(int bForce) override;
74
75
  public:
76
    bool bValidFile;
77
78
    OGRMiraMonLayer(GDALDataset *poDS, const char *pszFilename, VSILFILE *fp,
79
                    const OGRSpatialReference *poSRS, int bUpdate,
80
                    CSLConstList papszOpenOptions,
81
                    struct MiraMonVectMapInfo *MMMap);
82
    ~OGRMiraMonLayer() override;
83
84
    void ResetReading() override;
85
    DEFINE_GET_NEXT_FEATURE_THROUGH_RAW(OGRMiraMonLayer)
86
87
    OGRErr TranslateFieldsToMM();
88
    OGRErr TranslateFieldsValuesToMM(OGRFeature *poFeature);
89
    static int MM_SprintfDoubleSignifFigures(char *szChain, size_t size_szChain,
90
                                             int nSignifFigures,
91
                                             double dfRealValue);
92
    OGRErr IGetExtent(int iGeomField, OGREnvelope *psExtent,
93
                      bool bForce) override;
94
95
    const OGRFeatureDefn *GetLayerDefn() const override;
96
97
    OGRErr ICreateFeature(OGRFeature *poFeature) override;
98
99
    virtual OGRErr CreateField(const OGRFieldDefn *poField,
100
                               int bApproxOK = TRUE) override;
101
102
    int TestCapability(const char *) const override;
103
    void AddToFileList(CPLStringList &oFileList);
104
105
    GDALDataset *GetDataset() override
106
0
    {
107
0
        return m_poDS;
108
0
    }
109
};
110
111
/************************************************************************/
112
/*                           OGRMiraMonDataSource                       */
113
/************************************************************************/
114
115
class OGRMiraMonDataSource final : public GDALDataset
116
{
117
    std::vector<std::unique_ptr<OGRMiraMonLayer>> m_apoLayers = {};
118
    std::string m_osRootName{};
119
    bool m_bUpdate = false;
120
    struct MiraMonVectMapInfo m_MMMap = {};
121
122
  public:
123
    OGRMiraMonDataSource();
124
    OGRMiraMonDataSource(const OGRMiraMonDataSource &) = delete;
125
    OGRMiraMonDataSource &operator=(const OGRMiraMonDataSource &) = delete;
126
127
    ~OGRMiraMonDataSource() override;
128
129
    bool Open(const char *pszFilename, VSILFILE *fp,
130
              const OGRSpatialReference *poSRS, CSLConstList papszOpenOptions);
131
    bool Create(const char *pszFilename, CSLConstList papszOptions);
132
133
    int GetLayerCount() const override
134
20.0k
    {
135
20.0k
        return static_cast<int>(m_apoLayers.size());
136
20.0k
    }
137
138
    const OGRLayer *GetLayer(int) const override;
139
    char **GetFileList() override;
140
141
    OGRLayer *ICreateLayer(const char *pszLayerName,
142
                           const OGRGeomFieldDefn *poGeomFieldDefn,
143
                           CSLConstList papszOptions) override;
144
145
    int TestCapability(const char *) const override;
146
};
147
148
#endif /* OGRMIRAMON_H_INCLUDED */