LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/gml - gmlpropertydefn.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 35 27 77.1 %
Date: 2010-01-09 Functions: 4 3 75.0 %

       1                 : /**********************************************************************
       2                 :  * $Id: gmlpropertydefn.cpp 17629 2009-09-10 14:51:45Z chaitanya $
       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              49 : GMLPropertyDefn::GMLPropertyDefn( const char *pszName, 
      39                 :                                   const char *pszSrcElement )
      40                 : 
      41                 : {
      42              49 :     m_pszName = CPLStrdup( pszName );
      43              49 :     if( pszSrcElement != NULL )
      44              49 :         m_pszSrcElement = CPLStrdup( pszSrcElement );
      45                 :     else
      46               0 :         m_pszSrcElement = NULL;
      47              49 :     m_eType = GMLPT_Untyped;
      48              49 :     m_nWidth = 0; 
      49              49 :     m_nPrecision = 0;
      50              49 : }
      51                 : 
      52                 : /************************************************************************/
      53                 : /*                          ~GMLPropertyDefn()                          */
      54                 : /************************************************************************/
      55                 : 
      56              49 : GMLPropertyDefn::~GMLPropertyDefn()
      57                 : 
      58                 : {
      59              49 :     CPLFree( m_pszName );
      60              49 :     CPLFree( m_pszSrcElement );
      61              49 : }
      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             126 : void GMLPropertyDefn::AnalysePropertyValue( const char *pszValue,
      85                 :                                             const char *pszOldValue )
      86                 : 
      87                 : {
      88                 :     (void) pszOldValue; // not used yet. 
      89                 : 
      90                 : /* -------------------------------------------------------------------- */
      91                 : /*      If it is a zero length string, just return.  We can't deduce    */
      92                 : /*      much from this.                                                 */
      93                 : /* -------------------------------------------------------------------- */
      94             126 :     if( *pszValue == '\0' )
      95               0 :         return;
      96                 : 
      97                 : /* -------------------------------------------------------------------- */
      98                 : /*      Does the string consist entirely of numeric values?             */
      99                 : /* -------------------------------------------------------------------- */
     100             126 :     int bIsReal = FALSE;
     101                 : 
     102             126 :     CPLValueType valueType = CPLGetValueType(pszValue);
     103             126 :     if (valueType == CPL_VALUE_STRING)
     104              10 :         m_eType = GMLPT_String;
     105                 :     else
     106             116 :         bIsReal = (valueType == CPL_VALUE_REAL);
     107                 : 
     108             126 :     if( m_eType == GMLPT_String )
     109                 :     {
     110                 :         /* grow the Width to the length of the string passed in */
     111                 :         int nWidth;
     112              10 :         nWidth = strlen(pszValue);
     113              10 :         if ( m_nWidth < nWidth ) 
     114               5 :             SetWidth( nWidth );
     115                 :     }
     116             116 :     else if( m_eType == GMLPT_Untyped || m_eType == GMLPT_Integer )
     117                 :     {
     118              84 :         if( bIsReal )
     119               4 :             m_eType = GMLPT_Real;
     120                 :         else
     121              80 :             m_eType = GMLPT_Integer;
     122                 :     }
     123                 : }
     124                 : 

Generated by: LCOV version 1.7