LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/pdf - ogrpdfdriver.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 34 21 61.8 %
Date: 2012-12-26 Functions: 9 6 66.7 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogrpdfdriver.cpp 24143 2012-03-19 21:40:42Z rouault $
       3                 :  *
       4                 :  * Project:  PDF Translator
       5                 :  * Purpose:  Implements OGRPDFDriver.
       6                 :  * Author:   Even Rouault, even dot rouault at mines dash paris dot org
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 2012, Even Rouault <even dot rouault at mines dash paris dot org>
      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                 : #include "ogr_pdf.h"
      31                 : #include "cpl_conv.h"
      32                 : 
      33                 : CPL_CVSID("$Id: ogrpdfdriver.cpp 24143 2012-03-19 21:40:42Z rouault $");
      34                 : 
      35                 : extern "C" void RegisterOGRPDF();
      36                 : 
      37                 : // g++ -g -Wall -fPIC ogr/ogrsf_frmts/pdf/*.cpp -shared -o ogr_PDF.so -Iport -Igcore -Iogr -Iogr/ogrsf_frmts -Iogr/ogrsf_frmts/mem -Iogr/ogrsf_frmts/pdf -Ifrmts/pdf -L. -lgdal
      38                 : 
      39                 : /************************************************************************/
      40                 : /*                           ~OGRPDFDriver()                            */
      41                 : /************************************************************************/
      42                 : 
      43             214 : OGRPDFDriver::~OGRPDFDriver()
      44                 : 
      45                 : {
      46             214 : }
      47                 : 
      48                 : /************************************************************************/
      49                 : /*                              GetName()                               */
      50                 : /************************************************************************/
      51                 : 
      52           13815 : const char *OGRPDFDriver::GetName()
      53                 : 
      54                 : {
      55           13815 :     return "PDF";
      56                 : }
      57                 : 
      58                 : /************************************************************************/
      59                 : /*                                Open()                                */
      60                 : /************************************************************************/
      61                 : 
      62              37 : OGRDataSource *OGRPDFDriver::Open( const char * pszFilename, int bUpdate )
      63                 : 
      64                 : {
      65              37 :     if( !EQUAL(CPLGetExtension(pszFilename), "pdf") || bUpdate )
      66              31 :         return NULL;
      67                 : 
      68                 : /* -------------------------------------------------------------------- */
      69                 : /*      Try to create datasource.                                       */
      70                 : /* -------------------------------------------------------------------- */
      71                 :     OGRPDFDataSource     *poDS;
      72                 : 
      73               6 :     poDS = new OGRPDFDataSource();
      74                 : 
      75               6 :     if( !poDS->Open( pszFilename ) )
      76                 :     {
      77               0 :         delete poDS;
      78               0 :         return NULL;
      79                 :     }
      80                 :     else
      81               6 :         return poDS;
      82                 : }
      83                 : 
      84                 : /************************************************************************/
      85                 : /*                          CreateDataSource()                          */
      86                 : /************************************************************************/
      87                 : 
      88               2 : OGRDataSource *OGRPDFDriver::CreateDataSource( const char * pszName,
      89                 :                                                 char **papszOptions )
      90                 : 
      91                 : {
      92                 : /* -------------------------------------------------------------------- */
      93                 : /*      First, ensure there isn't any such file yet.                    */
      94                 : /* -------------------------------------------------------------------- */
      95                 :     VSIStatBufL sStatBuf;
      96                 : 
      97               2 :     if( VSIStatL( pszName, &sStatBuf ) == 0 )
      98                 :     {
      99                 :         CPLError( CE_Failure, CPLE_AppDefined,
     100                 :                   "It seems a file system object called '%s' already exists.",
     101               0 :                   pszName );
     102                 : 
     103               0 :         return NULL;
     104                 :     }
     105                 : 
     106                 : /* -------------------------------------------------------------------- */
     107                 : /*      Try to create datasource.                                       */
     108                 : /* -------------------------------------------------------------------- */
     109                 :     OGRPDFDataSource     *poDS;
     110                 : 
     111               2 :     poDS = new OGRPDFDataSource();
     112                 : 
     113               2 :     if( !poDS->Create( pszName, papszOptions ) )
     114                 :     {
     115               0 :         delete poDS;
     116               0 :         return NULL;
     117                 :     }
     118                 :     else
     119               2 :         return poDS;
     120                 : }
     121                 : 
     122                 : /************************************************************************/
     123                 : /*                         DeleteDataSource()                           */
     124                 : /************************************************************************/
     125                 : 
     126               2 : OGRErr OGRPDFDriver::DeleteDataSource( const char *pszName )
     127                 : {
     128               2 :     if (VSIUnlink( pszName ) == 0)
     129               2 :         return OGRERR_NONE;
     130                 :     else
     131               0 :         return OGRERR_FAILURE;
     132                 : }
     133                 : 
     134                 : /************************************************************************/
     135                 : /*                           TestCapability()                           */
     136                 : /************************************************************************/
     137                 : 
     138               0 : int OGRPDFDriver::TestCapability( const char * pszCap )
     139                 : 
     140                 : {
     141               0 :     if( EQUAL(pszCap,ODrCCreateDataSource) )
     142               0 :         return TRUE;
     143               0 :     else if( EQUAL(pszCap,ODrCDeleteDataSource) )
     144               0 :         return TRUE;
     145                 :     else
     146               0 :         return FALSE;
     147                 : }
     148                 : 
     149                 : /************************************************************************/
     150                 : /*                           RegisterOGRPDF()                           */
     151                 : /************************************************************************/
     152                 : 
     153             226 : void RegisterOGRPDF()
     154                 : 
     155                 : {
     156             226 :     OGRSFDriverRegistrar::GetRegistrar()->RegisterDriver( new OGRPDFDriver );
     157             226 : }
     158                 : 

Generated by: LCOV version 1.7