LTP GCOV extension - code coverage report
Current view: directory - ogr/ogrsf_frmts/gml - gmlpropertydefn.cpp
Test: gdal_filtered.info
Date: 2010-07-12 Instrumented lines: 47
Code covered: 63.8 % Executed lines: 30

       1                 : /**********************************************************************
       2                 :  * $Id: gmlpropertydefn.cpp 20013 2010-07-11 09:54:54Z rouault $
       3                 :  *
       4                 :  * Project:  GML Reader
       5                 :  * Purpose:  Implementation of GMLPropertyDefn
       6                 :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       7                 :  *
       8                 :  **********************************************************************
       9                 :  * Copyright (c) 2002, 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 OR
      22                 :  * 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 "gmlreader.h"
      31                 : #include "cpl_conv.h"
      32                 : #include "cpl_string.h"
      33                 : 
      34                 : /************************************************************************/
      35                 : /*                           GMLPropertyDefn                            */
      36                 : /************************************************************************/
      37                 : 
      38                 : GMLPropertyDefn::GMLPropertyDefn( const char *pszName, 
      39             244 :                                   const char *pszSrcElement )
      40                 : 
      41                 : {
      42             244 :     m_pszName = CPLStrdup( pszName );
      43             244 :     if( pszSrcElement != NULL )
      44             244 :         m_pszSrcElement = CPLStrdup( pszSrcElement );
      45                 :     else
      46               0 :         m_pszSrcElement = NULL;
      47             244 :     m_eType = GMLPT_Untyped;
      48             244 :     m_nWidth = 0; 
      49             244 :     m_nPrecision = 0;
      50             244 : }
      51                 : 
      52                 : /************************************************************************/
      53                 : /*                          ~GMLPropertyDefn()                          */
      54                 : /************************************************************************/
      55                 : 
      56             244 : GMLPropertyDefn::~GMLPropertyDefn()
      57                 : 
      58                 : {
      59             244 :     CPLFree( m_pszName );
      60             244 :     CPLFree( m_pszSrcElement );
      61             244 : }
      62                 : 
      63                 : /************************************************************************/
      64                 : /*                           SetSrcElement()                            */
      65                 : /************************************************************************/
      66                 : 
      67               0 : void GMLPropertyDefn::SetSrcElement( const char *pszSrcElement )
      68                 : 
      69                 : {
      70               0 :     CPLFree( m_pszSrcElement );
      71               0 :     if( pszSrcElement != NULL )
      72               0 :         m_pszSrcElement = CPLStrdup( pszSrcElement );
      73                 :     else
      74               0 :         m_pszSrcElement = NULL;
      75               0 : }
      76                 : 
      77                 : /************************************************************************/
      78                 : /*                        AnalysePropertyValue()                        */
      79                 : /*                                                                      */
      80                 : /*      Examine the passed property value, and see if we need to        */
      81                 : /*      make the field type more specific, or more general.             */
      82                 : /************************************************************************/
      83                 : 
      84                 : void GMLPropertyDefn::AnalysePropertyValue( const char *pszValue,
      85             184 :                                             const char *pszOldValue )
      86                 : 
      87                 : {
      88                 : /* -------------------------------------------------------------------- */
      89                 : /*      If it is a zero length string, just return.  We can't deduce    */
      90                 : /*      much from this.                                                 */
      91                 : /* -------------------------------------------------------------------- */
      92             184 :     if( *pszValue == '\0' )
      93               0 :         return;
      94                 : 
      95                 : /* -------------------------------------------------------------------- */
      96                 : /*      Does the string consist entirely of numeric values?             */
      97                 : /* -------------------------------------------------------------------- */
      98             184 :     int bIsReal = FALSE;
      99                 : 
     100             184 :     CPLValueType valueType = CPLGetValueType(pszValue);
     101             195 :     if (valueType == CPL_VALUE_STRING
     102                 :         && m_eType != GMLPT_String 
     103                 :         && m_eType != GMLPT_StringList )
     104                 :     {
     105              11 :         if( m_eType == GMLPT_IntegerList
     106                 :             || m_eType == GMLPT_RealList )
     107               0 :             m_eType = GMLPT_StringList;
     108                 :         else
     109              11 :             m_eType = GMLPT_String;
     110                 :     }
     111                 :     else
     112             173 :         bIsReal = (valueType == CPL_VALUE_REAL);
     113                 : 
     114             184 :     if( m_eType == GMLPT_String )
     115                 :     {
     116                 :         /* grow the Width to the length of the string passed in */
     117                 :         int nWidth;
     118              33 :         nWidth = strlen(pszValue);
     119              33 :         if ( m_nWidth < nWidth ) 
     120              12 :             SetWidth( nWidth );
     121                 :     }
     122             266 :     else if( m_eType == GMLPT_Untyped || m_eType == GMLPT_Integer )
     123                 :     {
     124             115 :         if( bIsReal )
     125               5 :             m_eType = GMLPT_Real;
     126                 :         else
     127             110 :             m_eType = GMLPT_Integer;
     128                 :     }
     129              36 :     else if( m_eType == GMLPT_IntegerList && bIsReal )
     130                 :     {
     131               0 :         m_eType = GMLPT_RealList;
     132                 :     }
     133                 : 
     134                 : /* -------------------------------------------------------------------- */
     135                 : /*      If we already had a value then we are dealing with a list       */
     136                 : /*      type value.                                                     */
     137                 : /* -------------------------------------------------------------------- */
     138             184 :     if( pszOldValue != NULL && strlen(pszOldValue) > 0 )
     139                 :     {
     140               0 :         if( m_eType == GMLPT_Integer )
     141               0 :             m_eType = GMLPT_IntegerList;
     142               0 :         else if( m_eType == GMLPT_Real )
     143               0 :             m_eType = GMLPT_RealList;
     144               0 :         else if( m_eType == GMLPT_String )
     145                 :         {
     146               0 :             m_eType = GMLPT_StringList;
     147               0 :             m_nWidth = 0;
     148                 :         }
     149                 :     }
     150                 : }

Generated by: LTP GCOV extension version 1.5