LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/sqlite - ogrsqlitesinglefeaturelayer.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 42 38 90.5 %
Date: 2012-12-26 Functions: 11 5 45.5 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogrsqlitesinglefeaturelayer.cpp 23736 2012-01-09 19:05:02Z rouault $
       3                 :  *
       4                 :  * Project:  OpenGIS Simple Features Reference Implementation
       5                 :  * Purpose:  Implements OGRSQLiteSingleFeatureLayer class.
       6                 :  * Author:   Even Rouault, <even dot rouault at mines dash paris dot org>
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 2010, Even Rouault
      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 "cpl_conv.h"
      31                 : #include "cpl_string.h"
      32                 : #include "ogr_sqlite.h"
      33                 : 
      34                 : CPL_CVSID("$Id: ogrsqlitesinglefeaturelayer.cpp 23736 2012-01-09 19:05:02Z rouault $");
      35                 : 
      36                 : /************************************************************************/
      37                 : /*                    OGRSQLiteSingleFeatureLayer()                     */
      38                 : /************************************************************************/
      39                 : 
      40              60 : OGRSQLiteSingleFeatureLayer::OGRSQLiteSingleFeatureLayer(
      41                 :                                                      const char* pszLayerName,
      42              60 :                                                      int nVal )
      43                 : {
      44              60 :     poFeatureDefn = new OGRFeatureDefn( "SELECT" );
      45              60 :     poFeatureDefn->Reference();
      46              60 :     OGRFieldDefn oField( pszLayerName, OFTInteger );
      47              60 :     poFeatureDefn->AddFieldDefn( &oField );
      48                 : 
      49              60 :     iNextShapeId = 0;
      50              60 :     this->nVal = nVal;
      51              60 :     pszVal = NULL;
      52              60 : }
      53                 : 
      54                 : /************************************************************************/
      55                 : /*                    OGRSQLiteSingleFeatureLayer()                     */
      56                 : /************************************************************************/
      57                 : 
      58               1 : OGRSQLiteSingleFeatureLayer::OGRSQLiteSingleFeatureLayer(
      59                 :                                                      const char* pszLayerName,
      60               1 :                                                      const char *pszVal )
      61                 : {
      62               1 :     poFeatureDefn = new OGRFeatureDefn( "SELECT" );
      63               1 :     poFeatureDefn->Reference();
      64               1 :     OGRFieldDefn oField( pszLayerName, OFTString );
      65               1 :     poFeatureDefn->AddFieldDefn( &oField );
      66                 : 
      67               1 :     iNextShapeId = 0;
      68               1 :     nVal = 0;
      69               1 :     this->pszVal = CPLStrdup(pszVal);
      70               1 : }
      71                 : 
      72                 : /************************************************************************/
      73                 : /*                   ~OGRSQLiteSingleFeatureLayer()                     */
      74                 : /************************************************************************/
      75                 : 
      76              61 : OGRSQLiteSingleFeatureLayer::~OGRSQLiteSingleFeatureLayer()
      77                 : {
      78              61 :     if( poFeatureDefn != NULL )
      79                 :     {
      80              61 :         poFeatureDefn->Release();
      81              61 :         poFeatureDefn = NULL;
      82                 :     }
      83              61 :     CPLFree(pszVal);
      84              61 : }
      85                 : 
      86                 : /************************************************************************/
      87                 : /*                            ResetReading()                            */
      88                 : /************************************************************************/
      89                 : 
      90               2 : void OGRSQLiteSingleFeatureLayer::ResetReading()
      91                 : {
      92               2 :     iNextShapeId = 0;
      93               2 : }
      94                 : 
      95                 : /************************************************************************/
      96                 : /*                           GetNextFeature()                           */
      97                 : /************************************************************************/
      98                 : 
      99               4 : OGRFeature * OGRSQLiteSingleFeatureLayer::GetNextFeature()
     100                 : {
     101               4 :     if (iNextShapeId != 0)
     102               1 :         return NULL;
     103                 : 
     104               3 :     OGRFeature* poFeature = new OGRFeature(poFeatureDefn);
     105               3 :     if (pszVal)
     106               1 :         poFeature->SetField(0, pszVal);
     107                 :     else
     108               2 :         poFeature->SetField(0, nVal);
     109               3 :     poFeature->SetFID(iNextShapeId ++);
     110               3 :     return poFeature;
     111                 : }
     112                 : 
     113                 : /************************************************************************/
     114                 : /*                            GetLayerDefn()                            */
     115                 : /************************************************************************/
     116                 : 
     117               0 : OGRFeatureDefn * OGRSQLiteSingleFeatureLayer::GetLayerDefn()
     118                 : {
     119               0 :     return poFeatureDefn;
     120                 : }
     121                 : 
     122                 : /************************************************************************/
     123                 : /*                           TestCapability()                           */
     124                 : /************************************************************************/
     125                 : 
     126               0 : int OGRSQLiteSingleFeatureLayer::TestCapability( const char * )
     127                 : {
     128               0 :     return FALSE;
     129                 : }

Generated by: LCOV version 1.7