LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/generic - ogrdatasource.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 51 100 51.0 %
Date: 2025-07-09 17:50:03 Functions: 11 21 52.4 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  OpenGIS Simple Features Reference Implementation
       4             :  * Purpose:  The generic portions of the GDALDataset class.
       5             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 1999,  Les Technologies SoftMap Inc.
       9             :  * Copyright (c) 2008-2014, Even Rouault <even dot rouault at spatialys.com>
      10             :  *
      11             :  * SPDX-License-Identifier: MIT
      12             :  ****************************************************************************/
      13             : 
      14             : #include "ogrsf_frmts.h"
      15             : #include "ogr_api.h"
      16             : #include "ograpispy.h"
      17             : 
      18             : /************************************************************************/
      19             : /*                            OGRDataSource()                           */
      20             : /************************************************************************/
      21             : 
      22             : OGRDataSource::OGRDataSource() = default;
      23             : 
      24             : /************************************************************************/
      25             : /*                           ~OGRDataSource()                           */
      26             : /************************************************************************/
      27             : 
      28             : OGRDataSource::~OGRDataSource() = default;
      29             : 
      30             : /************************************************************************/
      31             : /*                         DestroyDataSource()                          */
      32             : /************************************************************************/
      33             : 
      34             : //! @cond Doxygen_Suppress
      35           0 : void OGRDataSource::DestroyDataSource(OGRDataSource *poDS)
      36             : 
      37             : {
      38           0 :     delete poDS;
      39           0 : }
      40             : 
      41             : //! @endcond
      42             : 
      43             : /************************************************************************/
      44             : /*                           OGR_DS_Destroy()                           */
      45             : /************************************************************************/
      46             : 
      47          25 : void OGR_DS_Destroy(OGRDataSourceH hDS)
      48             : 
      49             : {
      50          25 :     if (hDS == nullptr)
      51           0 :         return;
      52          25 :     GDALClose(reinterpret_cast<GDALDatasetH>(hDS));
      53             :     // VALIDATE_POINTER0( hDS, "OGR_DS_Destroy" );
      54             : }
      55             : 
      56             : /************************************************************************/
      57             : /*                          OGR_DS_Reference()                          */
      58             : /************************************************************************/
      59             : 
      60           0 : int OGR_DS_Reference(OGRDataSourceH hDataSource)
      61             : 
      62             : {
      63           0 :     VALIDATE_POINTER1(hDataSource, "OGR_DS_Reference", 0);
      64             : 
      65           0 :     return GDALDataset::FromHandle(hDataSource)->Reference();
      66             : }
      67             : 
      68             : /************************************************************************/
      69             : /*                         OGR_DS_Dereference()                         */
      70             : /************************************************************************/
      71             : 
      72           0 : int OGR_DS_Dereference(OGRDataSourceH hDataSource)
      73             : 
      74             : {
      75           0 :     VALIDATE_POINTER1(hDataSource, "OGR_DS_Dereference", 0);
      76             : 
      77           0 :     return GDALDataset::FromHandle(hDataSource)->Dereference();
      78             : }
      79             : 
      80             : /************************************************************************/
      81             : /*                         OGR_DS_GetRefCount()                         */
      82             : /************************************************************************/
      83             : 
      84          14 : int OGR_DS_GetRefCount(OGRDataSourceH hDataSource)
      85             : 
      86             : {
      87          14 :     VALIDATE_POINTER1(hDataSource, "OGR_DS_GetRefCount", 0);
      88             : 
      89          14 :     return GDALDataset::FromHandle(hDataSource)->GetRefCount();
      90             : }
      91             : 
      92             : /************************************************************************/
      93             : /*                     OGR_DS_GetSummaryRefCount()                      */
      94             : /************************************************************************/
      95             : 
      96           0 : int OGR_DS_GetSummaryRefCount(OGRDataSourceH hDataSource)
      97             : 
      98             : {
      99           0 :     VALIDATE_POINTER1(hDataSource, "OGR_DS_GetSummaryRefCount", 0);
     100             : 
     101           0 :     return GDALDataset::FromHandle(hDataSource)->GetSummaryRefCount();
     102             : }
     103             : 
     104             : /************************************************************************/
     105             : /*                         OGR_DS_CreateLayer()                         */
     106             : /************************************************************************/
     107             : 
     108          13 : OGRLayerH OGR_DS_CreateLayer(OGRDataSourceH hDS, const char *pszName,
     109             :                              OGRSpatialReferenceH hSpatialRef,
     110             :                              OGRwkbGeometryType eType, char **papszOptions)
     111             : 
     112             : {
     113          13 :     VALIDATE_POINTER1(hDS, "OGR_DS_CreateLayer", nullptr);
     114             : 
     115          13 :     if (pszName == nullptr)
     116             :     {
     117           0 :         CPLError(CE_Failure, CPLE_ObjectNull,
     118             :                  "Name was NULL in OGR_DS_CreateLayer");
     119           0 :         return nullptr;
     120             :     }
     121             :     OGRLayerH hLayer =
     122          26 :         OGRLayer::ToHandle(GDALDataset::FromHandle(hDS)->CreateLayer(
     123          13 :             pszName, OGRSpatialReference::FromHandle(hSpatialRef), eType,
     124             :             papszOptions));
     125             : 
     126             : #ifdef OGRAPISPY_ENABLED
     127          13 :     if (bOGRAPISpyEnabled)
     128           0 :         OGRAPISpy_DS_CreateLayer(hDS, pszName, hSpatialRef, eType, papszOptions,
     129             :                                  hLayer);
     130             : #endif
     131             : 
     132          13 :     return hLayer;
     133             : }
     134             : 
     135             : /************************************************************************/
     136             : /*                          OGR_DS_CopyLayer()                          */
     137             : /************************************************************************/
     138             : 
     139           0 : OGRLayerH OGR_DS_CopyLayer(OGRDataSourceH hDS, OGRLayerH hSrcLayer,
     140             :                            const char *pszNewName, char **papszOptions)
     141             : 
     142             : {
     143           0 :     VALIDATE_POINTER1(hDS, "OGR_DS_CopyLayer", nullptr);
     144           0 :     VALIDATE_POINTER1(hSrcLayer, "OGR_DS_CopyLayer", nullptr);
     145           0 :     VALIDATE_POINTER1(pszNewName, "OGR_DS_CopyLayer", nullptr);
     146             : 
     147           0 :     return OGRLayer::ToHandle(GDALDataset::FromHandle(hDS)->CopyLayer(
     148           0 :         OGRLayer::FromHandle(hSrcLayer), pszNewName, papszOptions));
     149             : }
     150             : 
     151             : /************************************************************************/
     152             : /*                         OGR_DS_DeleteLayer()                         */
     153             : /************************************************************************/
     154             : 
     155           7 : OGRErr OGR_DS_DeleteLayer(OGRDataSourceH hDS, int iLayer)
     156             : 
     157             : {
     158           7 :     VALIDATE_POINTER1(hDS, "OGR_DS_DeleteLayer", OGRERR_INVALID_HANDLE);
     159             : 
     160             : #ifdef OGRAPISPY_ENABLED
     161           7 :     if (bOGRAPISpyEnabled)
     162           0 :         OGRAPISpy_DS_DeleteLayer(reinterpret_cast<GDALDatasetH>(hDS), iLayer);
     163             : #endif
     164             : 
     165           7 :     OGRErr eErr = GDALDataset::FromHandle(hDS)->DeleteLayer(iLayer);
     166             : 
     167           7 :     return eErr;
     168             : }
     169             : 
     170             : /************************************************************************/
     171             : /*                       OGR_DS_GetLayerByName()                        */
     172             : /************************************************************************/
     173             : 
     174           3 : OGRLayerH OGR_DS_GetLayerByName(OGRDataSourceH hDS, const char *pszLayerName)
     175             : 
     176             : {
     177           3 :     VALIDATE_POINTER1(hDS, "OGR_DS_GetLayerByName", nullptr);
     178             : 
     179           3 :     OGRLayerH hLayer = OGRLayer::ToHandle(
     180           3 :         GDALDataset::FromHandle(hDS)->GetLayerByName(pszLayerName));
     181             : 
     182             : #ifdef OGRAPISPY_ENABLED
     183           3 :     if (bOGRAPISpyEnabled)
     184           0 :         OGRAPISpy_DS_GetLayerByName(reinterpret_cast<GDALDatasetH>(hDS),
     185             :                                     pszLayerName, hLayer);
     186             : #endif
     187             : 
     188           3 :     return hLayer;
     189             : }
     190             : 
     191             : /************************************************************************/
     192             : /*                         OGR_DS_ExecuteSQL()                          */
     193             : /************************************************************************/
     194             : 
     195           2 : OGRLayerH OGR_DS_ExecuteSQL(OGRDataSourceH hDS, const char *pszStatement,
     196             :                             OGRGeometryH hSpatialFilter, const char *pszDialect)
     197             : 
     198             : {
     199           2 :     VALIDATE_POINTER1(hDS, "OGR_DS_ExecuteSQL", nullptr);
     200             : 
     201             :     OGRLayerH hLayer =
     202           4 :         OGRLayer::ToHandle(GDALDataset::FromHandle(hDS)->ExecuteSQL(
     203           2 :             pszStatement, OGRGeometry::FromHandle(hSpatialFilter), pszDialect));
     204             : 
     205             : #ifdef OGRAPISPY_ENABLED
     206           2 :     if (bOGRAPISpyEnabled)
     207           0 :         OGRAPISpy_DS_ExecuteSQL(reinterpret_cast<GDALDatasetH>(hDS),
     208             :                                 pszStatement, hSpatialFilter, pszDialect,
     209             :                                 hLayer);
     210             : #endif
     211             : 
     212           2 :     return hLayer;
     213             : }
     214             : 
     215             : /************************************************************************/
     216             : /*                      OGR_DS_ReleaseResultSet()                       */
     217             : /************************************************************************/
     218             : 
     219           2 : void OGR_DS_ReleaseResultSet(OGRDataSourceH hDS, OGRLayerH hLayer)
     220             : 
     221             : {
     222           2 :     VALIDATE_POINTER0(hDS, "OGR_DS_ReleaseResultSet");
     223             : 
     224             : #ifdef OGRAPISPY_ENABLED
     225           2 :     if (bOGRAPISpyEnabled)
     226           0 :         OGRAPISpy_DS_ReleaseResultSet(reinterpret_cast<GDALDatasetH>(hDS),
     227             :                                       hLayer);
     228             : #endif
     229             : 
     230           4 :     GDALDataset::FromHandle(hDS)->ReleaseResultSet(
     231           2 :         OGRLayer::FromHandle(hLayer));
     232             : }
     233             : 
     234             : /************************************************************************/
     235             : /*                       OGR_DS_TestCapability()                        */
     236             : /************************************************************************/
     237             : 
     238           1 : int OGR_DS_TestCapability(OGRDataSourceH hDS, const char *pszCapability)
     239             : 
     240             : {
     241           1 :     VALIDATE_POINTER1(hDS, "OGR_DS_TestCapability", 0);
     242           1 :     VALIDATE_POINTER1(pszCapability, "OGR_DS_TestCapability", 0);
     243             : 
     244           1 :     return GDALDataset::FromHandle(hDS)->TestCapability(pszCapability);
     245             : }
     246             : 
     247             : /************************************************************************/
     248             : /*                        OGR_DS_GetLayerCount()                        */
     249             : /************************************************************************/
     250             : 
     251          27 : int OGR_DS_GetLayerCount(OGRDataSourceH hDS)
     252             : 
     253             : {
     254          27 :     VALIDATE_POINTER1(hDS, "OGR_DS_GetLayerCount", 0);
     255             : 
     256             : #ifdef OGRAPISPY_ENABLED
     257          27 :     if (bOGRAPISpyEnabled)
     258           0 :         OGRAPISpy_DS_GetLayerCount(reinterpret_cast<GDALDatasetH>(hDS));
     259             : #endif
     260             : 
     261          27 :     return GDALDataset::FromHandle(hDS)->GetLayerCount();
     262             : }
     263             : 
     264             : /************************************************************************/
     265             : /*                          OGR_DS_GetLayer()                           */
     266             : /************************************************************************/
     267             : 
     268          32 : OGRLayerH OGR_DS_GetLayer(OGRDataSourceH hDS, int iLayer)
     269             : 
     270             : {
     271          32 :     VALIDATE_POINTER1(hDS, "OGR_DS_GetLayer", nullptr);
     272             : 
     273             :     OGRLayerH hLayer =
     274          32 :         OGRLayer::ToHandle(GDALDataset::FromHandle(hDS)->GetLayer(iLayer));
     275             : 
     276             : #ifdef OGRAPISPY_ENABLED
     277          32 :     if (bOGRAPISpyEnabled)
     278           0 :         OGRAPISpy_DS_GetLayer(reinterpret_cast<GDALDatasetH>(hDS), iLayer,
     279             :                               hLayer);
     280             : #endif
     281             : 
     282          32 :     return hLayer;
     283             : }
     284             : 
     285             : /************************************************************************/
     286             : /*                           OGR_DS_GetName()                           */
     287             : /************************************************************************/
     288             : 
     289           0 : const char *OGR_DS_GetName(OGRDataSourceH hDS)
     290             : 
     291             : {
     292           0 :     VALIDATE_POINTER1(hDS, "OGR_DS_GetName", nullptr);
     293             : 
     294           0 :     return GDALDataset::FromHandle(hDS)->GetDescription();
     295             : }
     296             : 
     297             : /************************************************************************/
     298             : /*                         OGR_DS_SyncToDisk()                          */
     299             : /************************************************************************/
     300             : 
     301           0 : OGRErr OGR_DS_SyncToDisk(OGRDataSourceH hDS)
     302             : 
     303             : {
     304           0 :     VALIDATE_POINTER1(hDS, "OGR_DS_SyncToDisk", OGRERR_INVALID_HANDLE);
     305             : 
     306           0 :     GDALDataset::FromHandle(hDS)->FlushCache(false);
     307           0 :     if (CPLGetLastErrorType() != 0)
     308           0 :         return OGRERR_FAILURE;
     309             :     else
     310           0 :         return OGRERR_NONE;
     311             : }
     312             : 
     313             : /************************************************************************/
     314             : /*                          OGR_DS_GetDriver()                          */
     315             : /************************************************************************/
     316             : 
     317           5 : OGRSFDriverH OGR_DS_GetDriver(OGRDataSourceH hDS)
     318             : 
     319             : {
     320           5 :     VALIDATE_POINTER1(hDS, "OGR_DS_GetDriver", nullptr);
     321             : 
     322             :     return reinterpret_cast<OGRSFDriverH>(
     323           5 :         reinterpret_cast<OGRDataSource *>(hDS)->GetDriver());
     324             : }
     325             : 
     326             : /************************************************************************/
     327             : /*                         OGR_DS_GetStyleTable()                       */
     328             : /************************************************************************/
     329             : 
     330           0 : OGRStyleTableH OGR_DS_GetStyleTable(OGRDataSourceH hDS)
     331             : 
     332             : {
     333           0 :     VALIDATE_POINTER1(hDS, "OGR_DS_GetStyleTable", nullptr);
     334             : 
     335             :     return reinterpret_cast<OGRStyleTableH>(
     336           0 :         GDALDataset::FromHandle(hDS)->GetStyleTable());
     337             : }
     338             : 
     339             : /************************************************************************/
     340             : /*                         OGR_DS_SetStyleTableDirectly()               */
     341             : /************************************************************************/
     342             : 
     343           0 : void OGR_DS_SetStyleTableDirectly(OGRDataSourceH hDS,
     344             :                                   OGRStyleTableH hStyleTable)
     345             : 
     346             : {
     347           0 :     VALIDATE_POINTER0(hDS, "OGR_DS_SetStyleTableDirectly");
     348             : 
     349           0 :     GDALDataset::FromHandle(hDS)->SetStyleTableDirectly(
     350           0 :         reinterpret_cast<OGRStyleTable *>(hStyleTable));
     351             : }
     352             : 
     353             : /************************************************************************/
     354             : /*                         OGR_DS_SetStyleTable()                       */
     355             : /************************************************************************/
     356             : 
     357           0 : void OGR_DS_SetStyleTable(OGRDataSourceH hDS, OGRStyleTableH hStyleTable)
     358             : 
     359             : {
     360           0 :     VALIDATE_POINTER0(hDS, "OGR_DS_SetStyleTable");
     361           0 :     VALIDATE_POINTER0(hStyleTable, "OGR_DS_SetStyleTable");
     362             : 
     363           0 :     GDALDataset::FromHandle(hDS)->SetStyleTable(
     364           0 :         reinterpret_cast<OGRStyleTable *>(hStyleTable));
     365             : }

Generated by: LCOV version 1.14