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: 2025-01-18 12:42:00 Functions: 12 12 100.0 %

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

Generated by: LCOV version 1.14