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: 2024-11-25 23:50:41 Functions: 4 4 100.0 %

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

Generated by: LCOV version 1.14