LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/miramon - ogrmiramon.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 7 7 100.0 %
Date: 2025-01-18 12:42:00 Functions: 4 4 100.0 %

          Line data    Source code
       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             :     GDALDataset *m_poDS;
      29             :     OGRSpatialReference *m_poSRS;
      30             :     OGRFeatureDefn *m_poFeatureDefn;
      31             : 
      32             :     GUIntBig m_iNextFID;
      33             : 
      34             :     // Pointer to one of three possible MiraMon layers: points,
      35             :     // arcs or polygons. Every time a feature is read this pointer
      36             :     // points to the appropriate layer
      37             :     struct MiraMonVectLayerInfo *phMiraMonLayer;
      38             : 
      39             :     // When writing a layer
      40             :     struct MiraMonVectLayerInfo hMiraMonLayerPNT;  // MiraMon points layer
      41             :     struct MiraMonVectLayerInfo hMiraMonLayerARC;  // MiraMon arcs layer
      42             :     struct MiraMonVectLayerInfo hMiraMonLayerPOL;  // MiraMon polygons layer
      43             : 
      44             :     // When reading a layer or the result of writing is only a DBF
      45             :     struct MiraMonVectLayerInfo hMiraMonLayerReadOrNonGeom;
      46             : 
      47             :     struct MiraMonFeature hMMFeature;  // Feature reading/writing
      48             : 
      49             :     bool m_bUpdate;
      50             : 
      51             :     VSILFILE *m_fp = nullptr;
      52             : 
      53             :     // Array of doubles used in the field features processing
      54             :     double *padfValues;
      55             :     GInt64 *pnInt64Values;
      56             : 
      57             :     OGRFeature *GetNextRawFeature();
      58             :     OGRFeature *GetFeature(GIntBig nFeatureId) override;
      59             :     void GoToFieldOfMultipleRecord(MM_INTERNAL_FID iFID,
      60             :                                    MM_EXT_DBF_N_RECORDS nIRecord,
      61             :                                    MM_EXT_DBF_N_FIELDS nIField);
      62             : 
      63             :     OGRErr MMDumpVertices(OGRGeometryH hGeom, MM_BOOLEAN bExternalRing,
      64             :                           MM_BOOLEAN bUseVFG);
      65             :     OGRErr MMProcessGeometry(OGRGeometryH poGeom, OGRFeature *poFeature,
      66             :                              MM_BOOLEAN bcalculateRecord);
      67             :     OGRErr MMProcessMultiGeometry(OGRGeometryH hGeom, OGRFeature *poFeature);
      68             :     OGRErr MMLoadGeometry(OGRGeometryH hGeom);
      69             :     OGRErr MMWriteGeometry();
      70             :     GIntBig GetFeatureCount(int bForce) override;
      71             : 
      72             :   public:
      73             :     bool bValidFile;
      74             : 
      75             :     OGRMiraMonLayer(GDALDataset *poDS, const char *pszFilename, VSILFILE *fp,
      76             :                     const OGRSpatialReference *poSRS, int bUpdate,
      77             :                     CSLConstList papszOpenOptions,
      78             :                     struct MiraMonVectMapInfo *MMMap);
      79             :     virtual ~OGRMiraMonLayer();
      80             : 
      81             :     void ResetReading() override;
      82        1279 :     DEFINE_GET_NEXT_FEATURE_THROUGH_RAW(OGRMiraMonLayer)
      83             : 
      84             :     OGRErr TranslateFieldsToMM();
      85             :     OGRErr TranslateFieldsValuesToMM(OGRFeature *poFeature);
      86             :     OGRErr GetExtent(OGREnvelope *psExtent, int bForce) override;
      87             : 
      88             :     OGRFeatureDefn *GetLayerDefn() override;
      89             : 
      90          37 :     virtual OGRErr GetExtent(int iGeomField, OGREnvelope *psExtent,
      91             :                              int bForce) override
      92             :     {
      93          37 :         return OGRLayer::GetExtent(iGeomField, psExtent, bForce);
      94             :     }
      95             : 
      96             :     OGRErr ICreateFeature(OGRFeature *poFeature) override;
      97             : 
      98             :     virtual OGRErr CreateField(const OGRFieldDefn *poField,
      99             :                                int bApproxOK = TRUE) override;
     100             : 
     101             :     int TestCapability(const char *) override;
     102             :     void AddToFileList(CPLStringList &oFileList);
     103             : 
     104          16 :     GDALDataset *GetDataset() override
     105             :     {
     106          16 :         return m_poDS;
     107             :     }
     108             : };
     109             : 
     110             : /************************************************************************/
     111             : /*                           OGRMiraMonDataSource                       */
     112             : /************************************************************************/
     113             : 
     114             : class OGRMiraMonDataSource final : public GDALDataset
     115             : {
     116             :     std::vector<std::unique_ptr<OGRMiraMonLayer>> m_apoLayers;
     117             :     std::string m_osRootName{};
     118             :     bool m_bUpdate = false;
     119             :     struct MiraMonVectMapInfo m_MMMap;
     120             : 
     121             :   public:
     122             :     OGRMiraMonDataSource();
     123             :     ~OGRMiraMonDataSource();
     124             : 
     125             :     bool Open(const char *pszFilename, VSILFILE *fp,
     126             :               const OGRSpatialReference *poSRS, CSLConstList papszOpenOptions);
     127             :     bool Create(const char *pszFilename, CSLConstList papszOptions);
     128             : 
     129         383 :     int GetLayerCount() override
     130             :     {
     131         383 :         return static_cast<int>(m_apoLayers.size());
     132             :     }
     133             : 
     134             :     OGRLayer *GetLayer(int) override;
     135             :     char **GetFileList() override;
     136             : 
     137             :     OGRLayer *ICreateLayer(const char *pszLayerName,
     138             :                            const OGRGeomFieldDefn *poGeomFieldDefn,
     139             :                            CSLConstList papszOptions) override;
     140             : 
     141             :     int TestCapability(const char *) override;
     142             : };
     143             : 
     144             : #endif /* OGRMIRAMON_H_INCLUDED */

Generated by: LCOV version 1.14