LTP GCOV extension - code coverage report
Current view: directory - ogr/ogrsf_frmts/gml - gmlreadstate.cpp
Test: gdal_filtered.info
Date: 2010-07-12 Instrumented lines: 50
Code covered: 80.0 % Executed lines: 40

       1                 : /**********************************************************************
       2                 :  * $Id: gmlreadstate.cpp 10645 2007-01-18 02:22:39Z warmerdam $
       3                 :  *
       4                 :  * Project:  GML Reader
       5                 :  * Purpose:  Implementation of GMLReadState class.
       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 "gmlreaderp.h"
      31                 : #include "cpl_conv.h"
      32                 : #include "cpl_string.h"
      33                 : 
      34                 : /************************************************************************/
      35                 : /*                            GMLReadState()                            */
      36                 : /************************************************************************/
      37                 : 
      38           16736 : GMLReadState::GMLReadState()
      39                 : 
      40                 : {
      41           16736 :     m_poFeature = NULL;
      42           16736 :     m_poParentState = NULL;
      43                 : 
      44           16736 :     m_pszPath = CPLStrdup("");
      45           16736 :     m_nPathLength = 0;
      46           16736 :     m_papszPathComponents = NULL;
      47           16736 : }
      48                 : 
      49                 : /************************************************************************/
      50                 : /*                           ~GMLReadState()                            */
      51                 : /************************************************************************/
      52                 : 
      53           16736 : GMLReadState::~GMLReadState()
      54                 : 
      55                 : {
      56           16736 :     CPLFree( m_pszPath );
      57           16751 :     for( int i = 0; i < m_nPathLength; i++ )
      58              15 :         CPLFree( m_papszPathComponents[i] );
      59           16736 :     CPLFree( m_papszPathComponents );
      60           16736 : }
      61                 : 
      62                 : /************************************************************************/
      63                 : /*                              PushPath()                              */
      64                 : /************************************************************************/
      65                 : 
      66         1025434 : void GMLReadState::PushPath( const char *pszElement )
      67                 : 
      68                 : {
      69         1025434 :     m_nPathLength++;
      70         1025434 :     m_papszPathComponents = CSLAddString( m_papszPathComponents, pszElement );
      71                 : 
      72         1025434 :     RebuildPath();
      73         1025434 : }
      74                 : 
      75                 : /************************************************************************/
      76                 : /*                              PopPath()                               */
      77                 : /************************************************************************/
      78                 : 
      79         1025419 : void GMLReadState::PopPath()
      80                 : 
      81                 : {
      82         1025419 :     CPLAssert( m_nPathLength > 0 );
      83         1025419 :     if( m_nPathLength <= 0 )
      84               0 :         return;
      85                 : 
      86         1025419 :     CPLFree( m_papszPathComponents[m_nPathLength-1] );
      87         1025419 :     m_papszPathComponents[--m_nPathLength] = NULL;
      88                 : 
      89         1025419 :     RebuildPath();
      90                 : }
      91                 : 
      92                 : /************************************************************************/
      93                 : /*                            RebuildPath()                             */
      94                 : /************************************************************************/
      95                 : 
      96         2050853 : void GMLReadState::RebuildPath()
      97                 : 
      98                 : {
      99         2050853 :     int   nLength=0, i;
     100                 : 
     101        16408568 :     for( i = 0; i < m_nPathLength; i++ )
     102        14357715 :         nLength += strlen(m_papszPathComponents[i]) + 1;
     103                 :     
     104         2050853 :     m_pszPath = (char *) CPLRealloc(m_pszPath, nLength );
     105                 : 
     106         2050853 :     nLength = 0;
     107        16408568 :     for( i = 0; i < m_nPathLength; i++ )
     108                 :     {
     109        14357715 :         if( i > 0 )
     110        12380259 :             m_pszPath[nLength++] = '|';
     111                 : 
     112        14357715 :         strcpy( m_pszPath + nLength, m_papszPathComponents[i] );
     113        14357715 :         nLength += strlen(m_papszPathComponents[i]);
     114                 :     }
     115         2050853 : }
     116                 : 
     117                 : /************************************************************************/
     118                 : /*                          GetLastComponent()                          */
     119                 : /************************************************************************/
     120                 : 
     121         1202580 : const char *GMLReadState::GetLastComponent() const
     122                 : 
     123                 : {
     124         1202580 :     if( m_nPathLength == 0 )
     125           73141 :         return "";
     126                 :     else
     127         1129439 :         return m_papszPathComponents[m_nPathLength-1];
     128                 : }
     129                 : 
     130                 : /************************************************************************/
     131                 : /*                             MatchPath()                              */
     132                 : /*                                                                      */
     133                 : /*      Compare the passed in path to the current one and see if        */
     134                 : /*      they match.  It is assumed that the passed in path may          */
     135                 : /*      contain one or more elements and must match the tail of the     */
     136                 : /*      current path.  However, the passed in path does not need all    */
     137                 : /*      the components of the current read state path.                  */
     138                 : /*                                                                      */
     139                 : /*      Returns TRUE if the paths match.                                */
     140                 : /************************************************************************/
     141                 : 
     142               0 : int GMLReadState::MatchPath( const char *pszPathIn )
     143                 : 
     144                 : {
     145                 :     int iOffset;
     146               0 :     int nInputLength = strlen(pszPathIn);
     147               0 :     int nInternalLength = strlen(m_pszPath);
     148                 : 
     149               0 :     if( nInputLength > nInternalLength )
     150               0 :         return FALSE;
     151                 : 
     152               0 :     iOffset = nInternalLength - nInputLength;
     153               0 :     if( iOffset > 0 && m_pszPath[iOffset-1] != '|' )
     154               0 :         return FALSE;
     155                 : 
     156               0 :     return strcmp(pszPathIn,m_pszPath + iOffset) == 0;
     157                 : }

Generated by: LTP GCOV extension version 1.5