LCOV - code coverage report
Current view: top level - frmts/sdts - sdtsattrreader.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 51 59 86.4 %
Date: 2024-05-04 12:52:34 Functions: 10 11 90.9 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  SDTS Translator
       4             :  * Purpose:  Implementation of SDTSAttrReader class.
       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 "sdts_al.h"
      30             : 
      31             : /************************************************************************/
      32             : /* ==================================================================== */
      33             : /*                             SDTSAttrRecord                           */
      34             : /* ==================================================================== */
      35             : /************************************************************************/
      36             : 
      37             : /************************************************************************/
      38             : /*                           SDTSAttrRecord()                           */
      39             : /************************************************************************/
      40             : 
      41         353 : SDTSAttrRecord::SDTSAttrRecord() : poWholeRecord(nullptr), poATTR(nullptr)
      42             : {
      43         353 : }
      44             : 
      45             : /************************************************************************/
      46             : /*                          ~SDTSAttrRecord()                           */
      47             : /************************************************************************/
      48             : 
      49         706 : SDTSAttrRecord::~SDTSAttrRecord()
      50             : 
      51             : {
      52         353 :     if (poWholeRecord != nullptr)
      53         353 :         delete poWholeRecord;
      54         706 : }
      55             : 
      56             : /************************************************************************/
      57             : /*                                Dump()                                */
      58             : /************************************************************************/
      59             : 
      60           0 : void SDTSAttrRecord::Dump(FILE *fp)
      61             : 
      62             : {
      63           0 :     if (poATTR != nullptr)
      64           0 :         poATTR->Dump(fp);
      65           0 : }
      66             : 
      67             : /************************************************************************/
      68             : /* ==================================================================== */
      69             : /*                             SDTSAttrReader                           */
      70             : /*                                                                      */
      71             : /*      This is the class used to read a primary attribute module.      */
      72             : /* ==================================================================== */
      73             : /************************************************************************/
      74             : 
      75             : /************************************************************************/
      76             : /*                           SDTSAttrReader()                           */
      77             : /************************************************************************/
      78             : 
      79           3 : SDTSAttrReader::SDTSAttrReader() : bIsSecondary(FALSE)
      80             : {
      81           3 : }
      82             : 
      83             : /************************************************************************/
      84             : /*                          ~SDTSAttrReader()                           */
      85             : /************************************************************************/
      86             : 
      87           6 : SDTSAttrReader::~SDTSAttrReader()
      88             : {
      89           3 :     Close();
      90           6 : }
      91             : 
      92             : /************************************************************************/
      93             : /*                               Close()                                */
      94             : /************************************************************************/
      95             : 
      96           3 : void SDTSAttrReader::Close()
      97             : 
      98             : {
      99           3 :     ClearIndex();
     100           3 :     oDDFModule.Close();
     101           3 : }
     102             : 
     103             : /************************************************************************/
     104             : /*                                Open()                                */
     105             : /*                                                                      */
     106             : /*      Open the requested attr file, and prepare to start reading      */
     107             : /*      data records.                                                   */
     108             : /************************************************************************/
     109             : 
     110           3 : int SDTSAttrReader::Open(const char *pszFilename)
     111             : 
     112             : {
     113           3 :     bool bSuccess = CPL_TO_BOOL(oDDFModule.Open(pszFilename));
     114             : 
     115           3 :     if (bSuccess)
     116           3 :         bIsSecondary = (oDDFModule.FindFieldDefn("ATTS") != nullptr);
     117             : 
     118           3 :     return bSuccess;
     119             : }
     120             : 
     121             : /************************************************************************/
     122             : /*                           GetNextRecord()                            */
     123             : /************************************************************************/
     124             : 
     125         357 : DDFField *SDTSAttrReader::GetNextRecord(SDTSModId *poModId,
     126             :                                         DDFRecord **ppoRecord, int bDuplicate)
     127             : 
     128             : {
     129             :     /* -------------------------------------------------------------------- */
     130             :     /*      Fetch a record.                                                 */
     131             :     /* -------------------------------------------------------------------- */
     132         357 :     if (ppoRecord != nullptr)
     133         357 :         *ppoRecord = nullptr;
     134             : 
     135         357 :     if (oDDFModule.GetFP() == nullptr)
     136           0 :         return nullptr;
     137             : 
     138         357 :     DDFRecord *poRecord = oDDFModule.ReadRecord();
     139             : 
     140         357 :     if (poRecord == nullptr)
     141           4 :         return nullptr;
     142             : 
     143             :     /* -------------------------------------------------------------------- */
     144             :     /*      Make a copy of the record for persistent use if requested by    */
     145             :     /*      the caller.                                                     */
     146             :     /* -------------------------------------------------------------------- */
     147         353 :     if (bDuplicate)
     148         353 :         poRecord = poRecord->Clone();
     149             : 
     150             :     /* -------------------------------------------------------------------- */
     151             :     /*      Find the ATTP field.                                            */
     152             :     /* -------------------------------------------------------------------- */
     153         353 :     DDFField *poATTP = poRecord->FindField("ATTP", 0);
     154         353 :     if (poATTP == nullptr)
     155             :     {
     156           0 :         poATTP = poRecord->FindField("ATTS", 0);
     157             :     }
     158             : 
     159         353 :     if (poATTP == nullptr)
     160           0 :         return nullptr;
     161             : 
     162             :     /* -------------------------------------------------------------------- */
     163             :     /*      Update the module ID if required.                               */
     164             :     /* -------------------------------------------------------------------- */
     165         353 :     if (poModId != nullptr)
     166             :     {
     167         353 :         DDFField *poATPR = poRecord->FindField("ATPR");
     168             : 
     169         353 :         if (poATPR == nullptr)
     170           0 :             poATPR = poRecord->FindField("ATSC");
     171             : 
     172         353 :         if (poATPR != nullptr)
     173         353 :             poModId->Set(poATPR);
     174             :     }
     175             : 
     176             :     /* -------------------------------------------------------------------- */
     177             :     /*      return proper answer.                                           */
     178             :     /* -------------------------------------------------------------------- */
     179         353 :     if (ppoRecord != nullptr)
     180         353 :         *ppoRecord = poRecord;
     181             : 
     182         353 :     return poATTP;
     183             : }
     184             : 
     185             : /************************************************************************/
     186             : /*                         GetNextAttrRecord()                          */
     187             : /************************************************************************/
     188             : 
     189         357 : SDTSAttrRecord *SDTSAttrReader::GetNextAttrRecord()
     190             : 
     191             : {
     192         357 :     SDTSModId oModId;
     193         357 :     DDFRecord *poRawRecord = nullptr;
     194             : 
     195         357 :     DDFField *poATTRField = GetNextRecord(&oModId, &poRawRecord, TRUE);
     196             : 
     197         357 :     if (poATTRField == nullptr)
     198           4 :         return nullptr;
     199             : 
     200         353 :     SDTSAttrRecord *poAttrRecord = new SDTSAttrRecord();
     201             : 
     202         353 :     poAttrRecord->poWholeRecord = poRawRecord;
     203         353 :     poAttrRecord->poATTR = poATTRField;
     204         353 :     memcpy(&(poAttrRecord->oModId), &oModId, sizeof(SDTSModId));
     205             : 
     206         353 :     return poAttrRecord;
     207             : }

Generated by: LCOV version 1.14