LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/mem - ogrmemdatasource.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 35 34 97.1 %
Date: 2012-04-28 Functions: 9 6 66.7 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogrmemdatasource.cpp 13027 2007-11-25 19:21:57Z warmerdam $
       3                 :  *
       4                 :  * Project:  OpenGIS Simple Features Reference Implementation
       5                 :  * Purpose:  Implements OGRMemDataSource class.
       6                 :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 2003, 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_mem.h"
      31                 : #include "cpl_conv.h"
      32                 : #include "cpl_string.h"
      33                 : 
      34                 : CPL_CVSID("$Id: ogrmemdatasource.cpp 13027 2007-11-25 19:21:57Z warmerdam $");
      35                 : 
      36                 : /************************************************************************/
      37                 : /*                          OGRMemDataSource()                          */
      38                 : /************************************************************************/
      39                 : 
      40             126 : OGRMemDataSource::OGRMemDataSource( const char *pszFilename, 
      41             126 :                                     char **papszOptions)
      42                 : 
      43                 : {
      44             126 :     pszName = CPLStrdup(pszFilename);
      45             126 :     papoLayers = NULL;
      46             126 :     nLayers = 0;
      47             126 : }
      48                 : 
      49                 : /************************************************************************/
      50                 : /*                         ~OGRMemDataSource()                          */
      51                 : /************************************************************************/
      52                 : 
      53             126 : OGRMemDataSource::~OGRMemDataSource()
      54                 : 
      55                 : {
      56             126 :     CPLFree( pszName );
      57                 : 
      58             258 :     for( int i = 0; i < nLayers; i++ )
      59             132 :         delete papoLayers[i];
      60                 :     
      61             126 :     CPLFree( papoLayers );
      62             126 : }
      63                 : 
      64                 : /************************************************************************/
      65                 : /*                            CreateLayer()                             */
      66                 : /************************************************************************/
      67                 : 
      68                 : OGRLayer *
      69             134 : OGRMemDataSource::CreateLayer( const char * pszLayerName,
      70                 :                                  OGRSpatialReference *poSRS,
      71                 :                                  OGRwkbGeometryType eType,
      72                 :                                  char ** papszOptions )
      73                 : 
      74                 : {
      75                 : /* -------------------------------------------------------------------- */
      76                 : /*      Create the layer object.                                        */
      77                 : /* -------------------------------------------------------------------- */
      78                 :     OGRMemLayer *poLayer;
      79                 : 
      80             134 :     poLayer = new OGRMemLayer( pszLayerName, poSRS, eType );
      81                 : 
      82                 : /* -------------------------------------------------------------------- */
      83                 : /*      Add layer to data source layer list.                            */
      84                 : /* -------------------------------------------------------------------- */
      85                 :     papoLayers = (OGRMemLayer **)
      86             134 :         CPLRealloc( papoLayers,  sizeof(OGRMemLayer *) * (nLayers+1) );
      87                 :     
      88             134 :     papoLayers[nLayers++] = poLayer;
      89                 : 
      90             134 :     return poLayer;
      91                 : }
      92                 : 
      93                 : /************************************************************************/
      94                 : /*                            DeleteLayer()                             */
      95                 : /************************************************************************/
      96                 : 
      97               6 : OGRErr OGRMemDataSource::DeleteLayer( int iLayer )
      98                 : 
      99                 : {
     100               6 :     if( iLayer >= 0 && iLayer < nLayers )
     101                 :     {
     102               2 :         delete papoLayers[iLayer];
     103                 : 
     104               4 :         for( int i = iLayer+1; i < nLayers; i++ )
     105               2 :             papoLayers[i-1] = papoLayers[i];
     106                 :         
     107               2 :         nLayers--;
     108                 :         
     109               2 :         return OGRERR_NONE;
     110                 :     }
     111                 :     else
     112               4 :         return OGRERR_FAILURE;
     113                 : }
     114                 : 
     115                 : /************************************************************************/
     116                 : /*                           TestCapability()                           */
     117                 : /************************************************************************/
     118                 : 
     119              68 : int OGRMemDataSource::TestCapability( const char * pszCap )
     120                 : 
     121                 : {
     122              68 :     if( EQUAL(pszCap,ODsCCreateLayer) )
     123              66 :         return TRUE;
     124               2 :     else if( EQUAL(pszCap,ODsCDeleteLayer) )
     125               2 :         return TRUE;
     126                 :     else
     127               0 :         return FALSE;
     128                 : }
     129                 : 
     130                 : /************************************************************************/
     131                 : /*                              GetLayer()                              */
     132                 : /************************************************************************/
     133                 : 
     134             512 : OGRLayer *OGRMemDataSource::GetLayer( int iLayer )
     135                 : 
     136                 : {
     137             512 :     if( iLayer < 0 || iLayer >= nLayers )
     138               4 :         return NULL;
     139                 :     else
     140             508 :         return papoLayers[iLayer];
     141                 : }
     142                 : 

Generated by: LCOV version 1.7