LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/csv - ogrcsvdriver.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 35 28 80.0 %
Date: 2010-01-09 Functions: 8 8 100.0 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogrcsvdriver.cpp 10645 2007-01-18 02:22:39Z warmerdam $
       3                 :  *
       4                 :  * Project:  CSV Translator
       5                 :  * Purpose:  Implements OGRCSVDriver.
       6                 :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 2004, Frank Warmerdam <warmerdam@pobox.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                 : #include "ogr_csv.h"
      31                 : #include "cpl_conv.h"
      32                 : 
      33                 : CPL_CVSID("$Id: ogrcsvdriver.cpp 10645 2007-01-18 02:22:39Z warmerdam $");
      34                 : 
      35                 : /************************************************************************/
      36                 : /*                           ~OGRCSVDriver()                            */
      37                 : /************************************************************************/
      38                 : 
      39              96 : OGRCSVDriver::~OGRCSVDriver()
      40                 : 
      41                 : {
      42              96 : }
      43                 : 
      44                 : /************************************************************************/
      45                 : /*                              GetName()                               */
      46                 : /************************************************************************/
      47                 : 
      48            1946 : const char *OGRCSVDriver::GetName()
      49                 : 
      50                 : {
      51            1946 :     return "CSV";
      52                 : }
      53                 : 
      54                 : /************************************************************************/
      55                 : /*                                Open()                                */
      56                 : /************************************************************************/
      57                 : 
      58             163 : OGRDataSource *OGRCSVDriver::Open( const char * pszFilename, int bUpdate )
      59                 : 
      60                 : {
      61             163 :     OGRCSVDataSource   *poDS = new OGRCSVDataSource();
      62                 : 
      63             163 :     if( !poDS->Open( pszFilename, bUpdate, FALSE ) )
      64                 :     {
      65             137 :         delete poDS;
      66             137 :         poDS = NULL;
      67                 :     }
      68                 : 
      69             163 :     return poDS;
      70                 : }
      71                 : 
      72                 : /************************************************************************/
      73                 : /*                          CreateDataSource()                          */
      74                 : /************************************************************************/
      75                 : 
      76               1 : OGRDataSource *OGRCSVDriver::CreateDataSource( const char * pszName,
      77                 :                                                char ** /* papszOptions */ )
      78                 : 
      79                 : {
      80                 : /* -------------------------------------------------------------------- */
      81                 : /*      First, ensure there isn't any such file yet.                    */
      82                 : /* -------------------------------------------------------------------- */
      83                 :     VSIStatBuf sStatBuf;
      84                 : 
      85               1 :     if( VSIStat( pszName, &sStatBuf ) == 0 )
      86                 :     {
      87                 :         CPLError( CE_Failure, CPLE_AppDefined, 
      88                 :                   "It seems a file system object called '%s' already exists.",
      89               0 :                   pszName );
      90                 : 
      91               0 :         return NULL;
      92                 :     }
      93                 : 
      94                 : /* -------------------------------------------------------------------- */
      95                 : /*      Create a directory.                                             */
      96                 : /* -------------------------------------------------------------------- */
      97               1 :     if( VSIMkdir( pszName, 0755 ) != 0 )
      98                 :     {
      99                 :         CPLError( CE_Failure, CPLE_AppDefined, 
     100                 :                   "Failed to create directory %s:\n%s", 
     101               0 :                   pszName, VSIStrerror( errno ) );
     102               0 :         return NULL;
     103                 :     }
     104                 : 
     105                 : /* -------------------------------------------------------------------- */
     106                 : /*      Force it to open as a datasource.                               */
     107                 : /* -------------------------------------------------------------------- */
     108               1 :     OGRCSVDataSource   *poDS = new OGRCSVDataSource();
     109                 : 
     110               1 :     if( !poDS->Open( pszName, TRUE, TRUE ) )
     111                 :     {
     112               0 :         delete poDS;
     113               0 :         return NULL;
     114                 :     }
     115                 : 
     116               1 :     return poDS;
     117                 : }
     118                 : 
     119                 : /************************************************************************/
     120                 : /*                           TestCapability()                           */
     121                 : /************************************************************************/
     122                 : 
     123               2 : int OGRCSVDriver::TestCapability( const char * pszCap )
     124                 : 
     125                 : {
     126               2 :     if( EQUAL(pszCap,ODrCCreateDataSource) )
     127               1 :         return TRUE;
     128               1 :     else if( EQUAL(pszCap,ODrCDeleteDataSource) )
     129               1 :         return TRUE;
     130                 :     else
     131               0 :         return FALSE;
     132                 : }
     133                 : 
     134                 : /************************************************************************/
     135                 : /*                          DeleteDataSource()                          */
     136                 : /************************************************************************/
     137                 : 
     138               3 : OGRErr OGRCSVDriver::DeleteDataSource( const char *pszFilename )
     139                 : 
     140                 : {
     141               3 :     if( CPLUnlinkTree( pszFilename ) == 0 )
     142               1 :         return OGRERR_NONE;
     143                 :     else
     144               2 :         return OGRERR_FAILURE;
     145                 : }
     146                 : 
     147                 : /************************************************************************/
     148                 : /*                           RegisterOGRCSV()                           */
     149                 : /************************************************************************/
     150                 : 
     151              64 : void RegisterOGRCSV()
     152                 : 
     153                 : {
     154              64 :     OGRSFDriverRegistrar::GetRegistrar()->RegisterDriver( new OGRCSVDriver );
     155              64 : }
     156                 : 

Generated by: LCOV version 1.7