LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/wasp - ogrwaspdriver.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 36 36 100.0 %
Date: 2024-05-07 17:03:27 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  WAsP Translator
       4             :  * Purpose:  Implements OGRWAsPDriver.
       5             :  * Author:   Vincent Mora, vincent dot mora at oslandia dot com
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2014, Oslandia <info at oslandia dot com>
       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             : #include "ogrwasp.h"
      30             : #include "cpl_conv.h"
      31             : #include <cassert>
      32             : 
      33             : /************************************************************************/
      34             : /*                                Open()                                */
      35             : /************************************************************************/
      36             : 
      37       23743 : OGRDataSource *OGRWAsPDriver::Open(const char *pszFilename, int bUpdate)
      38             : 
      39             : {
      40       23743 :     if (bUpdate)
      41             :     {
      42         496 :         return nullptr;
      43             :     }
      44             : 
      45       23247 :     if (!EQUAL(CPLGetExtension(pszFilename), "map"))
      46             :     {
      47       23202 :         return nullptr;
      48             :     }
      49             : 
      50          45 :     VSILFILE *fh = VSIFOpenL(pszFilename, "r");
      51          45 :     if (!fh)
      52             :     {
      53             :         /*CPLError( CE_Failure, CPLE_FileIO, "cannot open file %s", pszFilename
      54             :          * );*/
      55          36 :         return nullptr;
      56             :     }
      57          18 :     auto pDataSource = std::make_unique<OGRWAsPDataSource>(pszFilename, fh);
      58             : 
      59           9 :     if (pDataSource->Load(true) != OGRERR_NONE)
      60             :     {
      61           6 :         return nullptr;
      62             :     }
      63           3 :     return pDataSource.release();
      64             : }
      65             : 
      66             : /************************************************************************/
      67             : /*                           TestCapability()                           */
      68             : /************************************************************************/
      69             : 
      70        2438 : int OGRWAsPDriver::TestCapability(const char *pszCap)
      71             : 
      72             : {
      73        3657 :     return EQUAL(pszCap, ODrCCreateDataSource) ||
      74        3657 :            EQUAL(pszCap, ODrCDeleteDataSource);
      75             : }
      76             : 
      77             : /************************************************************************/
      78             : /*                           CreateDataSource()                           */
      79             : /************************************************************************/
      80             : 
      81          34 : OGRDataSource *OGRWAsPDriver::CreateDataSource(const char *pszName, char **)
      82             : 
      83             : {
      84          34 :     VSILFILE *fh = VSIFOpenL(pszName, "w");
      85          34 :     if (!fh)
      86             :     {
      87           1 :         CPLError(CE_Failure, CPLE_FileIO, "cannot open file %s", pszName);
      88           1 :         return nullptr;
      89             :     }
      90          33 :     return new OGRWAsPDataSource(pszName, fh);
      91             : }
      92             : 
      93             : /************************************************************************/
      94             : /*                           DeleteDataSource()                         */
      95             : /************************************************************************/
      96             : 
      97          34 : OGRErr OGRWAsPDriver::DeleteDataSource(const char *pszName)
      98             : 
      99             : {
     100          34 :     return VSIUnlink(pszName) == 0 ? OGRERR_NONE : OGRERR_FAILURE;
     101             : }
     102             : 
     103             : /************************************************************************/
     104             : /*                           RegisterOGRWAsP()                           */
     105             : /************************************************************************/
     106             : 
     107        1520 : void RegisterOGRWAsP()
     108             : 
     109             : {
     110        1520 :     OGRSFDriver *poDriver = new OGRWAsPDriver;
     111             : 
     112        1520 :     poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES");
     113        1520 :     poDriver->SetMetadataItem(GDAL_DCAP_CREATE_LAYER, "YES");
     114        1520 :     poDriver->SetMetadataItem(GDAL_DCAP_CREATE_FIELD, "YES");
     115        1520 :     poDriver->SetMetadataItem(GDAL_DCAP_Z_GEOMETRIES, "YES");
     116        1520 :     poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, "OGRSQL SQLITE");
     117             : 
     118        1520 :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "WAsP .map format");
     119        1520 :     poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "map");
     120        1520 :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/wasp.html");
     121        1520 :     poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
     122             : 
     123        1520 :     OGRSFDriverRegistrar::GetRegistrar()->RegisterDriver(poDriver);
     124        1520 : }

Generated by: LCOV version 1.14