LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/sdts - ogrsdtsdriver.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 23 31 74.2 %
Date: 2024-11-21 22:18:42 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  SDTS Translator
       4             :  * Purpose:  Implements OGRSDTSDriver
       5             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 1999, Frank Warmerdam
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #include "ogr_sdts.h"
      14             : #include "cpl_conv.h"
      15             : 
      16             : /************************************************************************/
      17             : /*                                Open()                                */
      18             : /************************************************************************/
      19             : 
      20       28349 : static GDALDataset *OGRSDTSDriverOpen(GDALOpenInfo *poOpenInfo)
      21             : 
      22             : {
      23       28349 :     if (!EQUAL(CPLGetExtension(poOpenInfo->pszFilename), "DDF"))
      24       28348 :         return nullptr;
      25           1 :     if (poOpenInfo->nHeaderBytes < 10)
      26           0 :         return nullptr;
      27           1 :     const char *pachLeader = (const char *)poOpenInfo->pabyHeader;
      28           1 :     if ((pachLeader[5] != '1' && pachLeader[5] != '2' &&
      29           0 :          pachLeader[5] != '3') ||
      30           1 :         pachLeader[6] != 'L' || (pachLeader[8] != '1' && pachLeader[8] != ' '))
      31             :     {
      32           0 :         return nullptr;
      33             :     }
      34             : 
      35           1 :     OGRSDTSDataSource *poDS = new OGRSDTSDataSource();
      36           1 :     if (!poDS->Open(poOpenInfo->pszFilename, TRUE))
      37             :     {
      38           0 :         delete poDS;
      39           0 :         poDS = nullptr;
      40             :     }
      41             : 
      42           1 :     if (poDS != nullptr && poOpenInfo->eAccess == GA_Update)
      43             :     {
      44           0 :         CPLError(CE_Failure, CPLE_OpenFailed,
      45             :                  "SDTS Driver doesn't support update.");
      46           0 :         delete poDS;
      47           0 :         poDS = nullptr;
      48             :     }
      49             : 
      50           1 :     return poDS;
      51             : }
      52             : 
      53             : /************************************************************************/
      54             : /*                           RegisterOGRSDTS()                          */
      55             : /************************************************************************/
      56             : 
      57        1595 : void RegisterOGRSDTS()
      58             : 
      59             : {
      60        1595 :     if (GDALGetDriverByName("OGR_SDTS") != nullptr)
      61         302 :         return;
      62             : 
      63        1293 :     GDALDriver *poDriver = new GDALDriver();
      64             : 
      65        1293 :     poDriver->SetDescription("OGR_SDTS");
      66        1293 :     poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES");
      67        1293 :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "SDTS");
      68        1293 :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/sdts.html");
      69        1293 :     poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
      70        1293 :     poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, "OGRSQL SQLITE");
      71             : 
      72        1293 :     poDriver->pfnOpen = OGRSDTSDriverOpen;
      73             : 
      74        1293 :     GetGDALDriverManager()->RegisterDriver(poDriver);
      75             : }

Generated by: LCOV version 1.14