LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/tiger - tigeraltname.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 0 32 0.0 %
Date: 2024-04-29 17:29:47 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  TIGER/Line Translator
       4             :  * Purpose:  Implements TigerAltName, providing access to RT4 files.
       5             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 1999, Frank Warmerdam
       9             :  *
      10             :  * Permission is hereby granted, free of charge, to any person obtaining a
      11             :  * copy of this software and associated documentation files (the "Software"),
      12             :  * to deal in the Software without restriction, including without limitation
      13             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      14             :  * and/or sell copies of the Software, and to permit persons to whom the
      15             :  * Software is furnished to do so, subject to the following conditions:
      16             :  *
      17             :  * The above copyright notice and this permission notice shall be included
      18             :  * in all copies or substantial portions of the Software.
      19             :  *
      20             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      21             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      22             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      23             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      24             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      25             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      26             :  * DEALINGS IN THE SOFTWARE.
      27             :  ****************************************************************************/
      28             : 
      29             : #include "ogr_tiger.h"
      30             : #include "cpl_conv.h"
      31             : 
      32             : #include <cinttypes>
      33             : 
      34             : static const char FOUR_FILE_CODE[] = "4";
      35             : 
      36             : static const TigerFieldInfo rt4_fields[] = {
      37             :     // fieldname    fmt  type  OFTType         beg  end  len  bDefine bSet
      38             :     {"MODULE", ' ', ' ', OFTString, 0, 0, 8, 1, 0},
      39             :     {"TLID", 'R', 'N', OFTInteger, 6, 15, 10, 1, 1},
      40             :     {"RTSQ", 'R', 'N', OFTInteger, 16, 18, 3, 1, 1},
      41             :     {"FEAT", ' ', ' ', OFTIntegerList, 0, 0, 8, 1, 0}
      42             :     // Note: we don't mention the FEAT1, FEAT2, FEAT3, FEAT4, FEAT5 fields
      43             :     // here because they're handled separately in the code below; they
      44             :     // correspond
      45             :     // to the FEAT array field here.
      46             : };
      47             : 
      48             : static const TigerRecordInfo rt4_info = {
      49             :     rt4_fields, sizeof(rt4_fields) / sizeof(TigerFieldInfo), 58};
      50             : 
      51             : /************************************************************************/
      52             : /*                            TigerAltName()                            */
      53             : /************************************************************************/
      54             : 
      55           0 : TigerAltName::TigerAltName(OGRTigerDataSource *poDSIn,
      56           0 :                            CPL_UNUSED const char *pszPrototypeModule)
      57           0 :     : TigerFileBase(&rt4_info, FOUR_FILE_CODE)
      58             : {
      59           0 :     OGRFieldDefn oField("", OFTInteger);
      60             : 
      61           0 :     poDS = poDSIn;
      62           0 :     poFeatureDefn = new OGRFeatureDefn("AltName");
      63           0 :     poFeatureDefn->Reference();
      64           0 :     poFeatureDefn->SetGeomType(wkbNone);
      65             : 
      66             :     /* -------------------------------------------------------------------- */
      67             :     /*      Fields from type 4 record.                                      */
      68             :     /* -------------------------------------------------------------------- */
      69             : 
      70           0 :     AddFieldDefns(psRTInfo, poFeatureDefn);
      71           0 : }
      72             : 
      73             : /************************************************************************/
      74             : /*                             GetFeature()                             */
      75             : /************************************************************************/
      76             : 
      77           0 : OGRFeature *TigerAltName::GetFeature(int nRecordId)
      78             : 
      79             : {
      80             :     char achRecord[OGR_TIGER_RECBUF_LEN];
      81             : 
      82           0 :     if (nRecordId < 0 || nRecordId >= nFeatures)
      83             :     {
      84           0 :         CPLError(CE_Failure, CPLE_FileIO,
      85             :                  "Request for out-of-range feature %d of %s4", nRecordId,
      86             :                  pszModule);
      87           0 :         return nullptr;
      88             :     }
      89             : 
      90             :     /* -------------------------------------------------------------------- */
      91             :     /*      Read the raw record data from the file.                         */
      92             :     /* -------------------------------------------------------------------- */
      93           0 :     if (fpPrimary == nullptr)
      94           0 :         return nullptr;
      95             : 
      96           0 :     const auto nOffset = static_cast<uint64_t>(nRecordId) * nRecordLength;
      97           0 :     if (VSIFSeekL(fpPrimary, nOffset, SEEK_SET) != 0)
      98             :     {
      99           0 :         CPLError(CE_Failure, CPLE_FileIO,
     100             :                  "Failed to seek to %" PRIu64 " of %s4", nOffset, pszModule);
     101           0 :         return nullptr;
     102             :     }
     103             : 
     104             :     // Overflow cannot happen since psRTInfo->nRecordLength is unsigned
     105             :     // char and sizeof(achRecord) == OGR_TIGER_RECBUF_LEN > 255
     106           0 :     if (VSIFReadL(achRecord, psRTInfo->nRecordLength, 1, fpPrimary) != 1)
     107             :     {
     108           0 :         CPLError(CE_Failure, CPLE_FileIO, "Failed to read record %d of %s4",
     109             :                  nRecordId, pszModule);
     110           0 :         return nullptr;
     111             :     }
     112             : 
     113             :     /* -------------------------------------------------------------------- */
     114             :     /*      Set fields.                                                     */
     115             :     /* -------------------------------------------------------------------- */
     116             : 
     117           0 :     OGRFeature *poFeature = new OGRFeature(poFeatureDefn);
     118             :     int anFeatList[5];
     119           0 :     int nFeatCount = 0;
     120             : 
     121           0 :     SetFields(psRTInfo, poFeature, achRecord);
     122             : 
     123           0 :     for (int iFeat = 0; iFeat < 5; iFeat++)
     124             :     {
     125             :         const char *pszFieldText =
     126           0 :             GetField(achRecord, 19 + iFeat * 8, 26 + iFeat * 8);
     127             : 
     128           0 :         if (*pszFieldText != '\0')
     129           0 :             anFeatList[nFeatCount++] = atoi(pszFieldText);
     130             :     }
     131             : 
     132           0 :     poFeature->SetField("FEAT", nFeatCount, anFeatList);
     133             : 
     134           0 :     return poFeature;
     135             : }

Generated by: LCOV version 1.14