LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/mem - ogr_mem.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 29 29 100.0 %
Date: 2024-11-21 22:18:42 Functions: 12 12 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  * $Id$
       3             :  *
       4             :  * Project:  OpenGIS Simple Features Reference Implementation
       5             :  * Purpose:  Private definitions within the OGR Memory driver.
       6             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       7             :  *
       8             :  ******************************************************************************
       9             :  * Copyright (c) 2003, Frank Warmerdam <warmerdam@pobox.com>
      10             :  * Copyright (c) 2011-2013, Even Rouault <even dot rouault at spatialys.com>
      11             :  *
      12             :  * SPDX-License-Identifier: MIT
      13             :  ****************************************************************************/
      14             : 
      15             : #ifndef OGRMEM_H_INCLUDED
      16             : #define OGRMEM_H_INCLUDED
      17             : 
      18             : #include "ogrsf_frmts.h"
      19             : 
      20             : #include <map>
      21             : 
      22             : /************************************************************************/
      23             : /*                             OGRMemLayer                              */
      24             : /************************************************************************/
      25             : class OGRMemDataSource;
      26             : 
      27             : class IOGRMemLayerFeatureIterator;
      28             : 
      29             : class CPL_DLL OGRMemLayer CPL_NON_FINAL : public OGRLayer
      30             : {
      31             :     CPL_DISALLOW_COPY_ASSIGN(OGRMemLayer)
      32             : 
      33             :     typedef std::map<GIntBig, std::unique_ptr<OGRFeature>> FeatureMap;
      34             :     typedef FeatureMap::iterator FeatureIterator;
      35             : 
      36             :     OGRFeatureDefn *m_poFeatureDefn = nullptr;
      37             : 
      38             :     GIntBig m_nFeatureCount = 0;
      39             : 
      40             :     GIntBig m_iNextReadFID = 0;
      41             :     GIntBig m_nMaxFeatureCount = 0;  // Max size of papoFeatures.
      42             :     OGRFeature **m_papoFeatures = nullptr;
      43             :     bool m_bHasHoles = false;
      44             : 
      45             :     FeatureMap m_oMapFeatures{};
      46             :     FeatureIterator m_oMapFeaturesIter{};
      47             : 
      48             :     GIntBig m_iNextCreateFID = 0;
      49             : 
      50             :     bool m_bUpdatable = true;
      51             :     bool m_bAdvertizeUTF8 = false;
      52             : 
      53             :     bool m_bUpdated = false;
      54             : 
      55             :     std::string m_osFIDColumn{};
      56             : 
      57             :     GDALDataset *m_poDS{};
      58             : 
      59             :     // Only use it in the lifetime of a function where the list of features
      60             :     // doesn't change.
      61             :     IOGRMemLayerFeatureIterator *GetIterator();
      62             : 
      63             :   protected:
      64             :     OGRFeature *GetFeatureRef(GIntBig nFeatureId);
      65             : 
      66             :   public:
      67             :     // Clone poSRS if not nullptr
      68             :     OGRMemLayer(const char *pszName, const OGRSpatialReference *poSRS,
      69             :                 OGRwkbGeometryType eGeomType);
      70             :     virtual ~OGRMemLayer();
      71             : 
      72             :     void ResetReading() override;
      73             :     OGRFeature *GetNextFeature() override;
      74             :     virtual OGRErr SetNextByIndex(GIntBig nIndex) override;
      75             : 
      76             :     OGRFeature *GetFeature(GIntBig nFeatureId) override;
      77             :     OGRErr ISetFeature(OGRFeature *poFeature) override;
      78             :     OGRErr ICreateFeature(OGRFeature *poFeature) override;
      79             :     OGRErr IUpsertFeature(OGRFeature *poFeature) override;
      80             :     OGRErr IUpdateFeature(OGRFeature *poFeature, int nUpdatedFieldsCount,
      81             :                           const int *panUpdatedFieldsIdx,
      82             :                           int nUpdatedGeomFieldsCount,
      83             :                           const int *panUpdatedGeomFieldsIdx,
      84             :                           bool bUpdateStyleString) override;
      85             :     virtual OGRErr DeleteFeature(GIntBig nFID) override;
      86             : 
      87     1303562 :     OGRFeatureDefn *GetLayerDefn() override
      88             :     {
      89     1303562 :         return m_poFeatureDefn;
      90             :     }
      91             : 
      92             :     GIntBig GetFeatureCount(int) override;
      93             : 
      94             :     virtual OGRErr CreateField(const OGRFieldDefn *poField,
      95             :                                int bApproxOK = TRUE) override;
      96             :     virtual OGRErr DeleteField(int iField) override;
      97             :     virtual OGRErr ReorderFields(int *panMap) override;
      98             :     virtual OGRErr AlterFieldDefn(int iField, OGRFieldDefn *poNewFieldDefn,
      99             :                                   int nFlags) override;
     100             :     virtual OGRErr
     101             :     AlterGeomFieldDefn(int iGeomField,
     102             :                        const OGRGeomFieldDefn *poNewGeomFieldDefn,
     103             :                        int nFlagsIn) override;
     104             :     virtual OGRErr CreateGeomField(const OGRGeomFieldDefn *poGeomField,
     105             :                                    int bApproxOK = TRUE) override;
     106             : 
     107             :     int TestCapability(const char *) override;
     108             : 
     109        2419 :     const char *GetFIDColumn() override
     110             :     {
     111        2419 :         return m_osFIDColumn.c_str();
     112             :     }
     113             : 
     114        1021 :     bool IsUpdatable() const
     115             :     {
     116        1021 :         return m_bUpdatable;
     117             :     }
     118             : 
     119        1472 :     void SetUpdatable(bool bUpdatableIn)
     120             :     {
     121        1472 :         m_bUpdatable = bUpdatableIn;
     122        1472 :     }
     123             : 
     124         931 :     void SetAdvertizeUTF8(bool bAdvertizeUTF8In)
     125             :     {
     126         931 :         m_bAdvertizeUTF8 = bAdvertizeUTF8In;
     127         931 :     }
     128             : 
     129         877 :     void SetFIDColumn(const char *pszFIDColumn)
     130             :     {
     131         877 :         m_osFIDColumn = pszFIDColumn;
     132         877 :     }
     133             : 
     134         463 :     bool HasBeenUpdated() const
     135             :     {
     136         463 :         return m_bUpdated;
     137             :     }
     138             : 
     139         379 :     void SetUpdated(bool bUpdated)
     140             :     {
     141         379 :         m_bUpdated = bUpdated;
     142         379 :     }
     143             : 
     144          25 :     GIntBig GetNextReadFID()
     145             :     {
     146          25 :         return m_iNextReadFID;
     147             :     }
     148             : 
     149         877 :     void SetDataset(GDALDataset *poDS)
     150             :     {
     151         877 :         m_poDS = poDS;
     152         877 :     }
     153             : 
     154         429 :     GDALDataset *GetDataset() override
     155             :     {
     156         429 :         return m_poDS;
     157             :     }
     158             : };
     159             : 
     160             : /************************************************************************/
     161             : /*                           OGRMemDataSource                           */
     162             : /************************************************************************/
     163             : 
     164             : class OGRMemDataSource CPL_NON_FINAL : public GDALDataset
     165             : {
     166             :     CPL_DISALLOW_COPY_ASSIGN(OGRMemDataSource)
     167             : 
     168             :     OGRMemLayer **papoLayers;
     169             :     int nLayers;
     170             : 
     171             :   public:
     172             :     OGRMemDataSource(const char *, char **);
     173             :     virtual ~OGRMemDataSource();
     174             : 
     175        3162 :     int GetLayerCount() override
     176             :     {
     177        3162 :         return nLayers;
     178             :     }
     179             : 
     180             :     OGRLayer *GetLayer(int) override;
     181             : 
     182             :     OGRLayer *ICreateLayer(const char *pszName,
     183             :                            const OGRGeomFieldDefn *poGeomFieldDefn,
     184             :                            CSLConstList papszOptions) override;
     185             :     OGRErr DeleteLayer(int iLayer) override;
     186             : 
     187             :     int TestCapability(const char *) override;
     188             : 
     189             :     bool AddFieldDomain(std::unique_ptr<OGRFieldDomain> &&domain,
     190             :                         std::string &failureReason) override;
     191             : 
     192             :     bool DeleteFieldDomain(const std::string &name,
     193             :                            std::string &failureReason) override;
     194             : 
     195             :     bool UpdateFieldDomain(std::unique_ptr<OGRFieldDomain> &&domain,
     196             :                            std::string &failureReason) override;
     197             : };
     198             : 
     199             : #endif  // ndef OGRMEM_H_INCLUDED

Generated by: LCOV version 1.14