LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/gml - gmlfeature.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 58 38 65.5 %
Date: 2010-01-09 Functions: 10 6 60.0 %

       1                 : /**********************************************************************
       2                 :  * $Id: gmlfeature.cpp 17165 2009-06-01 22:44:30Z warmerdam $
       3                 :  *
       4                 :  * Project:  GML Reader
       5                 :  * Purpose:  Implementation of GMLFeature.
       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                 : /*                             GMLFeature()                             */
      36                 : /************************************************************************/
      37                 : 
      38              56 : GMLFeature::GMLFeature( GMLFeatureClass *poClass )
      39                 : 
      40                 : {
      41              56 :     m_poClass = poClass;
      42              56 :     m_pszFID = NULL;
      43              56 :     m_pszGeometry = NULL;
      44                 :     
      45              56 :     m_nPropertyCount = 0;
      46              56 :     m_papszProperty = NULL;
      47                 :     
      48              56 :     m_papszOBProperties = NULL;
      49              56 : }
      50                 : 
      51                 : /************************************************************************/
      52                 : /*                            ~GMLFeature()                             */
      53                 : /************************************************************************/
      54                 : 
      55              56 : GMLFeature::~GMLFeature()
      56                 : 
      57                 : {
      58              56 :     CPLFree( m_pszFID );
      59                 :     
      60             239 :     for( int i = 0; i < m_nPropertyCount; i++ )
      61                 :     {
      62             183 :         if( m_papszProperty[i] )
      63             179 :             CPLFree( m_papszProperty[i] );
      64                 :     }
      65                 : 
      66              56 :     CPLFree( m_papszProperty );
      67              56 :     CPLFree( m_pszGeometry );
      68              56 :     CSLDestroy( m_papszOBProperties );
      69              56 : }
      70                 : 
      71                 : /************************************************************************/
      72                 : /*                               SetFID()                               */
      73                 : /************************************************************************/
      74                 : 
      75              52 : void GMLFeature::SetFID( const char *pszFID )
      76                 : 
      77                 : {
      78              52 :     CPLFree( m_pszFID );
      79              52 :     if( pszFID != NULL )
      80              52 :         m_pszFID = CPLStrdup( pszFID );
      81                 :     else
      82               0 :         m_pszFID = NULL;
      83              52 : }
      84                 : 
      85                 : /************************************************************************/
      86                 : /*                            GetProperty()                             */
      87                 : /************************************************************************/
      88                 : 
      89             109 : const char *GMLFeature::GetProperty( int iIndex ) const
      90                 : 
      91                 : {
      92             109 :     if( iIndex < 0 || iIndex >= m_nPropertyCount )
      93               0 :         return NULL;
      94                 :     else
      95             109 :         return m_papszProperty[iIndex];
      96                 : }
      97                 : 
      98                 : /************************************************************************/
      99                 : /*                            SetProperty()                             */
     100                 : /************************************************************************/
     101                 : 
     102             179 : void GMLFeature::SetProperty( int iIndex, const char *pszValue )
     103                 : 
     104                 : {
     105             179 :     if( iIndex < 0 || iIndex >= m_poClass->GetPropertyCount() )
     106                 :     {
     107                 :         CPLAssert( FALSE );
     108               0 :         return;
     109                 :     }
     110                 : 
     111             179 :     if( iIndex >= m_nPropertyCount )
     112                 :     {
     113                 :         m_papszProperty = (char **) 
     114                 :             CPLRealloc( m_papszProperty, 
     115              69 :                         sizeof(char *) * m_poClass->GetPropertyCount() );
     116             252 :         for( int i = m_nPropertyCount; i < m_poClass->GetPropertyCount(); i++ )
     117             183 :             m_papszProperty[i] = NULL;
     118              69 :         m_nPropertyCount = m_poClass->GetPropertyCount();
     119                 :     }
     120                 : 
     121             179 :     CPLFree( m_papszProperty[iIndex] );
     122             179 :     m_papszProperty[iIndex] = CPLStrdup( pszValue );
     123                 : }
     124                 : 
     125                 : /************************************************************************/
     126                 : /*                                Dump()                                */
     127                 : /************************************************************************/
     128                 : 
     129               0 : void GMLFeature::Dump( FILE * fp )
     130                 : 
     131                 : {
     132               0 :     printf( "GMLFeature(%s):\n", m_poClass->GetName() );
     133                 :     
     134               0 :     if( m_pszFID != NULL )
     135               0 :         printf( "  FID = %s\n", m_pszFID );
     136                 :     
     137               0 :     for( int i = 0; i < m_nPropertyCount; i++ )
     138                 :         printf( "  %s = %s\n", 
     139                 :                 m_poClass->GetProperty( i )->GetName(),
     140               0 :                 GetProperty( i ) );
     141                 : 
     142               0 :     if( m_pszGeometry )
     143               0 :         printf( "  %s\n", m_pszGeometry );
     144               0 : }
     145                 : 
     146                 : /************************************************************************/
     147                 : /*                        SetGeometryDirectly()                         */
     148                 : /************************************************************************/
     149                 : 
     150              54 : void GMLFeature::SetGeometryDirectly( char *pszGeometry )
     151                 : 
     152                 : {
     153              54 :     if( m_pszGeometry )
     154               0 :         CPLFree( m_pszGeometry );
     155                 : 
     156              54 :     m_pszGeometry = pszGeometry;
     157              54 : }
     158                 : 
     159                 : /************************************************************************/
     160                 : /*                           AddOBProperty()                            */
     161                 : /************************************************************************/
     162                 : 
     163               0 : void GMLFeature::AddOBProperty( const char *pszName, const char *pszValue )
     164                 : 
     165                 : {
     166                 :     m_papszOBProperties = 
     167               0 :         CSLAddNameValue( m_papszOBProperties, pszName, pszValue );
     168               0 : }
     169                 : 
     170                 : /************************************************************************/
     171                 : /*                           GetOBProperty()                            */
     172                 : /************************************************************************/
     173                 : 
     174               0 : const char *GMLFeature::GetOBProperty( const char *pszName )
     175                 : 
     176                 : {
     177               0 :     return CSLFetchNameValue( m_papszOBProperties, pszName );
     178                 : }
     179                 : 
     180                 : /************************************************************************/
     181                 : /*                          GetOBProperties()                           */
     182                 : /************************************************************************/
     183                 : 
     184               0 : char **GMLFeature::GetOBProperties()
     185                 : 
     186                 : {
     187               0 :     return m_papszOBProperties;
     188                 : }

Generated by: LCOV version 1.7