LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/sosi - ogrsosidriver.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 23 30 76.7 %
Date: 2024-05-14 23:54:21 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  SOSI Translator
       4             :  * Purpose:  Implements OGRSOSIDriver.
       5             :  * Author:   Thomas Hirsch, <thomas.hirsch statkart no>
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2010, Thomas Hirsch
       9             :  * Copyright (c) 2010, Even Rouault <even dot rouault at spatialys.com>
      10             :  *
      11             :  * Permission is hereby granted, free of charge, to any person obtaining a
      12             :  * copy of this software and associated documentation files (the "Software"),
      13             :  * to deal in the Software without restriction, including without limitation
      14             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      15             :  * and/or sell copies of the Software, and to permit persons to whom the
      16             :  * Software is furnished to do so, subject to the following conditions:
      17             :  *
      18             :  * The above copyright notice and this permission notice shall be included
      19             :  * in all copies or substantial portions of the Software.
      20             :  *
      21             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      22             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      23             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      24             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      25             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      26             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      27             :  * DEALINGS IN THE SOFTWARE.
      28             :  ****************************************************************************/
      29             : 
      30             : // Must be included before FYBA headers that mess with min() / max()
      31             : #include <mutex>
      32             : 
      33             : #include "ogr_sosi.h"
      34             : #include "ogrsosidrivercore.h"
      35             : 
      36             : static int bFYBAInit = FALSE;
      37             : static std::mutex oMutex;
      38             : 
      39             : /************************************************************************/
      40             : /*                          OGRSOSIInit()                               */
      41             : /************************************************************************/
      42             : 
      43           3 : static void OGRSOSIInit()
      44             : {
      45           6 :     std::lock_guard<std::mutex> oLock(oMutex);
      46           3 :     if (!bFYBAInit)
      47             :     {
      48           1 :         LC_Init(); /* Init FYBA */
      49           1 :         SOSIInitTypes();
      50           1 :         bFYBAInit = TRUE;
      51             :     }
      52           3 : }
      53             : 
      54             : /************************************************************************/
      55             : /*                        OGRSOSIDriverUnload()                         */
      56             : /************************************************************************/
      57             : 
      58           4 : static void OGRSOSIDriverUnload(CPL_UNUSED GDALDriver *poDriver)
      59             : {
      60             : 
      61           4 :     if (bFYBAInit)
      62             :     {
      63           0 :         LC_Close(); /* Close FYBA */
      64           0 :         SOSICleanupTypes();
      65           0 :         bFYBAInit = FALSE;
      66             :     }
      67           4 : }
      68             : 
      69             : /************************************************************************/
      70             : /*                              Open()                                  */
      71             : /************************************************************************/
      72             : 
      73           3 : static GDALDataset *OGRSOSIDriverOpen(GDALOpenInfo *poOpenInfo)
      74             : {
      75           3 :     if (OGRSOSIDriverIdentify(poOpenInfo) == FALSE)
      76           0 :         return nullptr;
      77             : 
      78           3 :     OGRSOSIInit();
      79             : 
      80           3 :     OGRSOSIDataSource *poDS = new OGRSOSIDataSource();
      81           3 :     if (!poDS->Open(poOpenInfo->pszFilename, 0))
      82             :     {
      83           0 :         delete poDS;
      84           0 :         return nullptr;
      85             :     }
      86             : 
      87           3 :     return poDS;
      88             : }
      89             : 
      90             : #ifdef WRITE_SUPPORT
      91             : /************************************************************************/
      92             : /*                              Create()                                */
      93             : /************************************************************************/
      94             : 
      95             : static GDALDataset *
      96             : OGRSOSIDriverCreate(const char *pszName, CPL_UNUSED int nBands,
      97             :                     CPL_UNUSED int nXSize, CPL_UNUSED int nYSize,
      98             :                     CPL_UNUSED GDALDataType eDT, CPL_UNUSED char **papszOptions)
      99             : {
     100             :     OGRSOSIInit();
     101             :     OGRSOSIDataSource *poDS = new OGRSOSIDataSource();
     102             :     if (!poDS->Create(pszName))
     103             :     {
     104             :         delete poDS;
     105             :         return NULL;
     106             :     }
     107             :     return poDS;
     108             : }
     109             : #endif
     110             : 
     111             : /************************************************************************/
     112             : /*                         RegisterOGRSOSI()                            */
     113             : /************************************************************************/
     114             : 
     115           7 : void RegisterOGRSOSI()
     116             : {
     117           7 :     if (GDALGetDriverByName(DRIVER_NAME) != nullptr)
     118           0 :         return;
     119             : 
     120           7 :     GDALDriver *poDriver = new GDALDriver();
     121           7 :     OGRSOSIDriverSetCommonMetadata(poDriver);
     122           7 :     poDriver->pfnOpen = OGRSOSIDriverOpen;
     123             : #ifdef WRITE_SUPPORT
     124             :     poDriver->pfnCreate = OGRSOSIDriverCreate;
     125             : #endif
     126           7 :     poDriver->pfnUnloadDriver = OGRSOSIDriverUnload;
     127             : 
     128           7 :     GetGDALDriverManager()->RegisterDriver(poDriver);
     129             : }

Generated by: LCOV version 1.14