LCOV - code coverage report
Current view: directory - frmts/sdts - sdtsattrreader.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 61 53 86.9 %
Date: 2010-01-09 Functions: 11 10 90.9 %

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

Generated by: LCOV version 1.7