LCOV - code coverage report
Current view: directory - frmts/hfa - hfadictionary.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 57 47 82.5 %
Date: 2010-01-09 Functions: 6 5 83.3 %

       1                 : /******************************************************************************
       2                 :  * $Id: hfadictionary.cpp 18184 2009-12-05 04:17:34Z warmerdam $
       3                 :  *
       4                 :  * Project:  Erdas Imagine (.img) Translator
       5                 :  * Purpose:  Implementation of the HFADictionary class for managing the
       6                 :  *           dictionary read from the HFA file.  Most work done by the
       7                 :  *           HFAType, and HFAField classes.
       8                 :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       9                 :  *
      10                 :  ******************************************************************************
      11                 :  * Copyright (c) 1999, Intergraph Corporation
      12                 :  *
      13                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      14                 :  * copy of this software and associated documentation files (the "Software"),
      15                 :  * to deal in the Software without restriction, including without limitation
      16                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      17                 :  * and/or sell copies of the Software, and to permit persons to whom the
      18                 :  * Software is furnished to do so, subject to the following conditions:
      19                 :  *
      20                 :  * The above copyright notice and this permission notice shall be included
      21                 :  * in all copies or substantial portions of the Software.
      22                 :  *
      23                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      24                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      25                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      26                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      27                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      28                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      29                 :  * DEALINGS IN THE SOFTWARE.
      30                 :  ****************************************************************************/
      31                 : 
      32                 : #include "hfa_p.h"
      33                 : #include "cpl_conv.h"
      34                 : 
      35                 : CPL_CVSID("$Id: hfadictionary.cpp 18184 2009-12-05 04:17:34Z warmerdam $");
      36                 : 
      37                 : static const char *apszDefDefn[] = {
      38                 : 
      39                 :     "Edsc_Table",
      40                 :     "{1:lnumrows,}Edsc_Table",
      41                 : 
      42                 :     "Edsc_Column", 
      43                 :     "{1:lnumRows,1:LcolumnDataPtr,1:e4:integer,real,complex,string,dataType,1:lmaxNumChars,}Edsc_Column", 
      44                 :     
      45                 :     "Eprj_Size",
      46                 :     "{1:dwidth,1:dheight,}Eprj_Size",
      47                 : 
      48                 :     "Eprj_Coordinate",
      49                 :     "{1:dx,1:dy,}Eprj_Coordinate",
      50                 : 
      51                 :     "Eprj_MapInfo", 
      52                 :     "{0:pcproName,1:*oEprj_Coordinate,upperLeftCenter,1:*oEprj_Coordinate,lowerRightCenter,1:*oEprj_Size,pixelSize,0:pcunits,}Eprj_MapInfo",
      53                 :     
      54                 :     "Eimg_StatisticsParameters830", 
      55                 :     "{0:poEmif_String,LayerNames,1:*bExcludedValues,1:oEmif_String,AOIname,1:lSkipFactorX,1:lSkipFactorY,1:*oEdsc_BinFunction,BinFunction,}Eimg_StatisticsParameters830",
      56                 :     
      57                 :     "Esta_Statistics", 
      58                 :     "{1:dminimum,1:dmaximum,1:dmean,1:dmedian,1:dmode,1:dstddev,}Esta_Statistics",
      59                 : 
      60                 :     "Edsc_BinFunction", 
      61                 :     "{1:lnumBins,1:e4:direct,linear,logarithmic,explicit,binFunctionType,1:dminLimit,1:dmaxLimit,1:*bbinLimits,}Edsc_BinFunction",
      62                 : 
      63                 :     "Eimg_NonInitializedValue", 
      64                 :     "{1:*bvalueBD,}Eimg_NonInitializedValue",
      65                 : 
      66                 :     "Eprj_MapProjection842",
      67                 :     "{1:x{1:x{0:pcstring,}Emif_String,type,1:x{0:pcstring,}Emif_String,MIFDictionary,0:pCMIFObject,}Emif_MIFObject,projection,1:x{0:pcstring,}Emif_String,title,}Eprj_MapProjection842",
      68                 : 
      69                 :     "Emif_MIFObject",
      70                 :     "{1:x{0:pcstring,}Emif_String,type,1:x{0:pcstring,}Emif_String,MIFDictionary,0:pCMIFObject,}Emif_MIFObject",
      71                 : 
      72                 :     "Eprj_ProParameters",
      73                 :     "{1:e2:EPRJ_INTERNAL,EPRJ_EXTERNAL,proType,1:lproNumber,0:pcproExeName,0:pcproName,1:lproZone,0:pdproParams,1:*oEprj_Spheroid,proSpheroid,}Eprj_ProParameters",
      74                 :     
      75                 :     "Eprj_Datum",
      76                 :     "{0:pcdatumname,1:e3:EPRJ_DATUM_PARAMETRIC,EPRJ_DATUM_GRID,EPRJ_DATUM_REGRESSION,type,0:pdparams,0:pcgridname,}Eprj_Datum",
      77                 : 
      78                 :     "Eprj_Spheroid",
      79                 :     "{0:pcsphereName,1:da,1:db,1:deSquared,1:dradius,}Eprj_Spheroid",
      80                 : 
      81                 :     NULL,
      82                 :     NULL };
      83                 :     
      84                 :     
      85                 : 
      86                 : /************************************************************************/
      87                 : /* ==================================================================== */
      88                 : /*                         HFADictionary                            */
      89                 : /* ==================================================================== */
      90                 : /************************************************************************/
      91                 : 
      92                 : 
      93                 : /************************************************************************/
      94                 : /*                           HFADictionary()                            */
      95                 : /************************************************************************/
      96                 : 
      97             397 : HFADictionary::HFADictionary( const char * pszString )
      98                 : 
      99                 : {
     100                 :     int   i;
     101                 :     
     102             397 :     nTypes = 0;
     103             397 :     nTypesMax = 0;
     104             397 :     papoTypes = NULL;
     105                 : 
     106             397 :     osDictionaryText = pszString;
     107             397 :     bDictionaryTextDirty = FALSE;
     108                 : 
     109                 : /* -------------------------------------------------------------------- */
     110                 : /*      Read all the types.                                             */
     111                 : /* -------------------------------------------------------------------- */
     112           14596 :     while( pszString != NULL && *pszString != '.' )
     113                 :     {
     114                 :         HFAType   *poNewType;
     115                 : 
     116           13802 :         poNewType = new HFAType();
     117           27604 :         pszString = poNewType->Initialize( pszString );
     118                 : 
     119           13802 :         if( pszString != NULL )
     120           13802 :             AddType( poNewType );
     121                 :         else
     122               0 :             delete poNewType;
     123                 :     }
     124                 : 
     125                 : /* -------------------------------------------------------------------- */
     126                 : /*      Complete the definitions.                                       */
     127                 : /* -------------------------------------------------------------------- */
     128           14199 :     for( i = 0; i < nTypes; i++ )
     129                 :     {
     130           13802 :         papoTypes[i]->CompleteDefn( this );
     131                 :     }
     132             397 : }
     133                 : 
     134                 : /************************************************************************/
     135                 : /*                           ~HFADictionary()                           */
     136                 : /************************************************************************/
     137                 : 
     138             397 : HFADictionary::~HFADictionary()
     139                 : 
     140                 : {
     141                 :     int   i;
     142                 : 
     143           14200 :     for( i = 0; i < nTypes; i++ )
     144           13803 :         delete papoTypes[i];
     145                 :     
     146             397 :     CPLFree( papoTypes );
     147             397 : }
     148                 : 
     149                 : /************************************************************************/
     150                 : /*                              AddType()                               */
     151                 : /************************************************************************/
     152                 : 
     153           13803 : void HFADictionary::AddType( HFAType *poType )
     154                 : 
     155                 : {
     156           13803 :     if( nTypes == nTypesMax )
     157                 :     {
     158            1140 :         nTypesMax = nTypes * 2 + 10;
     159                 :         papoTypes = (HFAType **) CPLRealloc( papoTypes,
     160            1140 :                                              sizeof(void*) * nTypesMax );
     161                 :     }
     162                 : 
     163           13803 :     papoTypes[nTypes++] = poType;
     164           13803 : }
     165                 : 
     166                 : /************************************************************************/
     167                 : /*                              FindType()                              */
     168                 : /************************************************************************/
     169                 : 
     170           10051 : HFAType * HFADictionary::FindType( const char * pszName )
     171                 : 
     172                 : {
     173                 :     int   i;
     174                 : 
     175          163303 :     for( i = 0; i < nTypes; i++ )
     176                 :     {
     177          163302 :         if( strcmp(pszName,papoTypes[i]->pszTypeName) == 0 )
     178           10050 :             return( papoTypes[i] );
     179                 :     }
     180                 : 
     181                 : /* -------------------------------------------------------------------- */
     182                 : /*      Check if this is a type have other knowledge of.  If so, add    */
     183                 : /*      it to the dictionary now.  I'm not sure how some files end      */
     184                 : /*      up being distributed using types not in the dictionary.         */
     185                 : /* -------------------------------------------------------------------- */
     186               1 :     for( i = 0; apszDefDefn[i] != NULL; i += 2 )
     187                 :     {
     188               1 :         if( strcmp( pszName, apszDefDefn[i] ) == 0 )
     189                 :         {
     190               1 :             HFAType *poNewType = new HFAType();
     191                 : 
     192               1 :             poNewType->Initialize( apszDefDefn[i+1] );
     193               1 :             AddType( poNewType );
     194               1 :             poNewType->CompleteDefn( this );
     195                 : 
     196               1 :             osDictionaryText.erase( osDictionaryText.size() - 1, 1 );
     197               1 :             osDictionaryText += apszDefDefn[i+1];
     198               1 :             osDictionaryText += ",.";
     199                 : 
     200               1 :             bDictionaryTextDirty = TRUE;
     201                 : 
     202               1 :             return poNewType;
     203                 :         }
     204                 :     }
     205                 : 
     206               0 :     return NULL;
     207                 : }
     208                 : 
     209                 : /************************************************************************/
     210                 : /*                            GetItemSize()                             */
     211                 : /*                                                                      */
     212                 : /*      Get the size of a basic (atomic) item.                          */
     213                 : /************************************************************************/
     214                 : 
     215           44981 : int HFADictionary::GetItemSize( char chType )
     216                 : 
     217                 : {
     218           44981 :     switch( chType )
     219                 :     {
     220                 :       case '1':
     221                 :       case '2':
     222                 :       case '4':
     223                 :       case 'c':
     224                 :       case 'C':
     225            7325 :         return 1;
     226                 : 
     227                 :       case 'e':
     228                 :       case 's':
     229                 :       case 'S':
     230            7782 :         return 2;
     231                 : 
     232                 :       case 't':
     233                 :       case 'l':
     234                 :       case 'L':
     235                 :       case 'f':
     236           21148 :         return 4;
     237                 : 
     238                 :       case 'd':
     239                 :       case 'm':
     240            6685 :         return 8;
     241                 : 
     242                 :       case 'M':
     243               0 :         return 16;
     244                 : 
     245                 :       case 'b':
     246            2041 :         return -1;
     247                 :         
     248                 :       case 'o':
     249                 :       case 'x':
     250               0 :         return 0;
     251                 : 
     252                 :       default:
     253                 :         CPLAssert( FALSE );
     254                 :     }
     255                 : 
     256               0 :     return 0;
     257                 : }
     258                 : 
     259                 : /************************************************************************/
     260                 : /*                                Dump()                                */
     261                 : /************************************************************************/
     262                 : 
     263               0 : void HFADictionary::Dump( FILE * fp )
     264                 : 
     265                 : {
     266                 :     int   i;
     267                 :     
     268               0 :     VSIFPrintf( fp, "\nHFADictionary:\n" );
     269                 : 
     270               0 :     for( i = 0; i < nTypes; i++ )
     271                 :     {
     272               0 :         papoTypes[i]->Dump( fp );
     273                 :     }
     274               0 : }

Generated by: LCOV version 1.7