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

Generated by: LCOV version 1.14