LTP GCOV extension - code coverage report
Current view: directory - ogr/ogrsf_frmts/tiger - tigerarealandmarks.cpp
Test: gdal_filtered.info
Date: 2010-07-12 Instrumented lines: 38
Code covered: 0.0 % Executed lines: 0

       1                 : /******************************************************************************
       2                 :  * $Id: tigerarealandmarks.cpp 10645 2007-01-18 02:22:39Z warmerdam $
       3                 :  *
       4                 :  * Project:  TIGER/Line Translator
       5                 :  * Purpose:  Implements TigerAreaLandmarks, providing access to .RT8 files.
       6                 :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 1999, Frank Warmerdam
      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_tiger.h"
      31                 : #include "cpl_conv.h"
      32                 : 
      33                 : CPL_CVSID("$Id: tigerarealandmarks.cpp 10645 2007-01-18 02:22:39Z warmerdam $");
      34                 : 
      35                 : #define FILE_CODE "8"
      36                 : 
      37                 : static TigerFieldInfo rt8_fields[] = {
      38                 :   // fieldname    fmt  type OFTType      beg  end  len  bDefine bSet bWrite
      39                 :   { "MODULE",     ' ', ' ', OFTString,     0,   0,   8,       1,   0,     0 },
      40                 :   { "FILE",       'L', 'N', OFTString,     6,  10,   5,       1,   1,     1 },
      41                 :   { "STATE",      'L', 'N', OFTInteger,    6,   7,   2,       1,   1,     1 },
      42                 :   { "COUNTY",     'L', 'N', OFTInteger,    8,  10,   3,       1,   1,     1 },
      43                 :   { "CENID",      'L', 'A', OFTString,    11,  15,   5,       1,   1,     1 },
      44                 :   { "POLYID",     'R', 'N', OFTInteger,   16,  25,  10,       1,   1,     1 },
      45                 :   { "LAND",       'R', 'N', OFTInteger,   26,  35,  10,       1,   1,     1 }
      46                 : };
      47                 : 
      48                 : static TigerRecordInfo rt8_info =
      49                 :   {
      50                 :     rt8_fields,
      51                 :     sizeof(rt8_fields) / sizeof(TigerFieldInfo),
      52                 :     36
      53                 :   };
      54                 : 
      55                 : /************************************************************************/
      56                 : /*                         TigerAreaLandmarks()                         */
      57                 : /************************************************************************/
      58                 : 
      59                 : TigerAreaLandmarks::TigerAreaLandmarks( OGRTigerDataSource * poDSIn,
      60               0 :                                   const char * pszPrototypeModule )
      61                 : 
      62                 : {
      63               0 :     OGRFieldDefn        oField("",OFTInteger);
      64                 : 
      65               0 :     poDS = poDSIn;
      66               0 :     poFeatureDefn = new OGRFeatureDefn( "AreaLandmarks" );
      67               0 :     poFeatureDefn->Reference();
      68               0 :     poFeatureDefn->SetGeomType( wkbNone );
      69                 : 
      70               0 :     psRT8Info = &rt8_info;
      71                 : 
      72                 :     /* -------------------------------------------------------------------- */
      73                 :     /*      Fields from type 8 record.                                      */
      74                 :     /* -------------------------------------------------------------------- */
      75                 : 
      76               0 :     AddFieldDefns( psRT8Info, poFeatureDefn );
      77                 : 
      78               0 : }
      79                 : 
      80                 : /************************************************************************/
      81                 : /*                        ~TigerAreaLandmarks()                         */
      82                 : /************************************************************************/
      83                 : 
      84               0 : TigerAreaLandmarks::~TigerAreaLandmarks()
      85                 : 
      86                 : {
      87               0 : }
      88                 : 
      89                 : /************************************************************************/
      90                 : /*                             SetModule()                              */
      91                 : /************************************************************************/
      92                 : 
      93               0 : int TigerAreaLandmarks::SetModule( const char * pszModule )
      94                 : 
      95                 : {
      96               0 :     if( !OpenFile( pszModule, FILE_CODE ) )
      97               0 :         return FALSE;
      98                 : 
      99               0 :     EstablishFeatureCount();
     100                 :     
     101               0 :     return TRUE;
     102                 : }
     103                 : 
     104                 : /************************************************************************/
     105                 : /*                             GetFeature()                             */
     106                 : /************************************************************************/
     107                 : 
     108               0 : OGRFeature *TigerAreaLandmarks::GetFeature( int nRecordId )
     109                 : 
     110                 : {
     111                 :     char        achRecord[OGR_TIGER_RECBUF_LEN];
     112                 : 
     113               0 :     if( nRecordId < 0 || nRecordId >= nFeatures )
     114                 :     {
     115                 :         CPLError( CE_Failure, CPLE_FileIO,
     116                 :                   "Request for out-of-range feature %d of %s8",
     117               0 :                   nRecordId, pszModule );
     118               0 :         return NULL;
     119                 :     }
     120                 : 
     121                 : /* -------------------------------------------------------------------- */
     122                 : /*      Read the raw record data from the file.                         */
     123                 : /* -------------------------------------------------------------------- */
     124               0 :     if( fpPrimary == NULL )
     125               0 :         return NULL;
     126                 : 
     127               0 :     if( VSIFSeek( fpPrimary, nRecordId * nRecordLength, SEEK_SET ) != 0 )
     128                 :     {
     129                 :         CPLError( CE_Failure, CPLE_FileIO,
     130                 :                   "Failed to seek to %d of %s8",
     131               0 :                   nRecordId * nRecordLength, pszModule );
     132               0 :         return NULL;
     133                 :     }
     134                 : 
     135               0 :     if( VSIFRead( achRecord, psRT8Info->nRecordLength, 1, fpPrimary ) != 1 )
     136                 :     {
     137                 :         CPLError( CE_Failure, CPLE_FileIO,
     138                 :                   "Failed to read record %d of %s8",
     139               0 :                   nRecordId, pszModule );
     140               0 :         return NULL;
     141                 :     }
     142                 : 
     143                 : /* -------------------------------------------------------------------- */
     144                 : /*      Set fields.                                                     */
     145                 : /* -------------------------------------------------------------------- */
     146               0 :     OGRFeature  *poFeature = new OGRFeature( poFeatureDefn );
     147                 : 
     148               0 :     SetFields( psRT8Info, poFeature, achRecord );
     149                 : 
     150               0 :     return poFeature;
     151                 : }
     152                 : 
     153                 : /************************************************************************/
     154                 : /*                           CreateFeature()                            */
     155                 : /************************************************************************/
     156                 : 
     157               0 : OGRErr TigerAreaLandmarks::CreateFeature( OGRFeature *poFeature )
     158                 : 
     159                 : {
     160                 :     char        szRecord[OGR_TIGER_RECBUF_LEN];
     161                 : 
     162               0 :     if( !SetWriteModule( FILE_CODE, psRT8Info->nRecordLength+2, poFeature ) )
     163               0 :         return OGRERR_FAILURE;
     164                 : 
     165               0 :     memset( szRecord, ' ', psRT8Info->nRecordLength );
     166                 : 
     167               0 :     WriteFields( psRT8Info, poFeature, szRecord);
     168                 : 
     169               0 :     WriteRecord( szRecord, psRT8Info->nRecordLength, FILE_CODE );
     170                 : 
     171               0 :     return OGRERR_NONE;
     172                 : }

Generated by: LTP GCOV extension version 1.5