LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/nas - ogrnasrelationlayer.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 65 45 69.2 %
Date: 2012-04-28 Functions: 10 4 40.0 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogrnasrelationlayer.cpp 24105 2012-03-10 12:08:04Z rouault $
       3                 :  *
       4                 :  * Project:  OGR
       5                 :  * Purpose:  Implements OGRNASRelationLayer class, a special layer holding all
       6                 :  *           the relations from the NAS file.
       7                 :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       8                 :  *
       9                 :  ******************************************************************************
      10                 :  * Copyright (c) 2009, Frank Warmerdam <warmerdam@pobox.com>
      11                 :  *
      12                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      13                 :  * copy of this software and associated documentation files (the "Software"),
      14                 :  * to deal in the Software without restriction, including without limitation
      15                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      16                 :  * and/or sell copies of the Software, and to permit persons to whom the
      17                 :  * Software is furnished to do so, subject to the following conditions:
      18                 :  *
      19                 :  * The above copyright notice and this permission notice shall be included
      20                 :  * in all copies or substantial portions of the Software.
      21                 :  *
      22                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      23                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      24                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      25                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      26                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      27                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      28                 :  * DEALINGS IN THE SOFTWARE.
      29                 :  ****************************************************************************/
      30                 : 
      31                 : #include "ogr_nas.h"
      32                 : #include "cpl_conv.h"
      33                 : #include "cpl_port.h"
      34                 : #include "cpl_string.h"
      35                 : 
      36                 : CPL_CVSID("$Id: ogrnasrelationlayer.cpp 24105 2012-03-10 12:08:04Z rouault $");
      37                 : 
      38                 : /************************************************************************/
      39                 : /*                        OGRNASRelationLayer()                         */
      40                 : /************************************************************************/
      41                 : 
      42              10 : OGRNASRelationLayer::OGRNASRelationLayer( OGRNASDataSource *poDSIn )
      43                 : 
      44                 : {
      45              10 :     poDS = poDSIn;
      46                 : 
      47              10 :     iNextFeature = 0;
      48              10 :     bPopulated = FALSE;
      49                 : 
      50                 : /* -------------------------------------------------------------------- */
      51                 : /*      Establish the layer fields.                                     */
      52                 : /* -------------------------------------------------------------------- */
      53              10 :     poFeatureDefn = new OGRFeatureDefn( "ALKIS_beziehungen" );
      54              10 :     poFeatureDefn->Reference();
      55              10 :     poFeatureDefn->SetGeomType( wkbNone );
      56                 : 
      57              10 :     OGRFieldDefn  oFD( "", OFTString );
      58                 : 
      59              10 :     oFD.SetName( "beziehung_von" );
      60              10 :     poFeatureDefn->AddFieldDefn( &oFD );
      61                 : 
      62              10 :     oFD.SetName( "beziehungsart" );
      63              10 :     poFeatureDefn->AddFieldDefn( &oFD );
      64                 : 
      65              10 :     oFD.SetName( "beziehung_zu" );
      66              10 :     poFeatureDefn->AddFieldDefn( &oFD );
      67              10 : }
      68                 : 
      69                 : /************************************************************************/
      70                 : /*                        ~OGRNASRelationLayer()                        */
      71                 : /************************************************************************/
      72                 : 
      73              10 : OGRNASRelationLayer::~OGRNASRelationLayer()
      74                 : 
      75                 : {
      76              10 :     if( poFeatureDefn )
      77              10 :         poFeatureDefn->Release();
      78              10 : }
      79                 : 
      80                 : /************************************************************************/
      81                 : /*                            ResetReading()                            */
      82                 : /************************************************************************/
      83                 : 
      84               0 : void OGRNASRelationLayer::ResetReading()
      85                 : 
      86                 : {
      87               0 :     iNextFeature = 0;
      88               0 : }
      89                 : 
      90                 : /************************************************************************/
      91                 : /*                           GetNextFeature()                           */
      92                 : /************************************************************************/
      93                 : 
      94               2 : OGRFeature *OGRNASRelationLayer::GetNextFeature()
      95                 : 
      96                 : {
      97               2 :     if( !bPopulated )
      98               2 :         poDS->PopulateRelations();
      99                 : 
     100                 : /* ==================================================================== */
     101                 : /*      Loop till we find and translate a feature meeting all our       */
     102                 : /*      requirements.                                                   */
     103                 : /* ==================================================================== */
     104               0 :     while( TRUE )
     105                 :     {
     106                 :         // out of features?
     107               2 :         if( iNextFeature >= (int) aoRelationCollection.size() )
     108               0 :             return NULL;
     109                 : 
     110                 : /* -------------------------------------------------------------------- */
     111                 : /*      The from/type/to values are stored in a packed string with      */
     112                 : /*      \0 separators for compactness.  Split out components.           */
     113                 : /* -------------------------------------------------------------------- */
     114                 :         const char *pszFromID, *pszType, *pszToID;
     115                 : 
     116               2 :         pszFromID = aoRelationCollection[iNextFeature].c_str();
     117               2 :         pszType = pszFromID + strlen(pszFromID) + 1;
     118               2 :         pszToID = pszType + strlen(pszType) + 1;
     119                 : 
     120               2 :         m_nFeaturesRead++;
     121                 : 
     122                 : /* -------------------------------------------------------------------- */
     123                 : /*      Translate values into an OGRFeature.                            */
     124                 : /* -------------------------------------------------------------------- */
     125               2 :         OGRFeature *poFeature = new OGRFeature( poFeatureDefn );
     126                 : 
     127               2 :         poFeature->SetField( 0, pszFromID );
     128               2 :         poFeature->SetField( 1, pszType );
     129               2 :         poFeature->SetField( 2, pszToID );
     130                 : 
     131               2 :         poFeature->SetFID( iNextFeature++ );
     132                 : 
     133                 : /* -------------------------------------------------------------------- */
     134                 : /*      Test against the attribute query.                               */
     135                 : /* -------------------------------------------------------------------- */
     136               2 :         if( m_poAttrQuery != NULL
     137                 :             && !m_poAttrQuery->Evaluate( poFeature ) )
     138               0 :             delete poFeature;
     139                 :         else
     140               2 :             return poFeature;
     141                 :     }
     142                 : 
     143                 :     return NULL;
     144                 : }
     145                 : 
     146                 : /************************************************************************/
     147                 : /*                          GetFeatureCount()                           */
     148                 : /************************************************************************/
     149                 : 
     150               0 : int OGRNASRelationLayer::GetFeatureCount( int bForce )
     151                 : 
     152                 : {
     153               0 :     if( !bPopulated )
     154               0 :         poDS->PopulateRelations();
     155                 : 
     156               0 :     if( m_poAttrQuery == NULL )
     157               0 :         return aoRelationCollection.size();
     158                 :     else
     159               0 :         return OGRLayer::GetFeatureCount( bForce );
     160                 : }
     161                 : 
     162                 : /************************************************************************/
     163                 : /*                           TestCapability()                           */
     164                 : /************************************************************************/
     165                 : 
     166               0 : int OGRNASRelationLayer::TestCapability( const char * pszCap )
     167                 : 
     168                 : {
     169               0 :     if( EQUAL(pszCap,OLCFastGetExtent) )
     170               0 :         return TRUE;
     171                 : 
     172               0 :     else if( EQUAL(pszCap,OLCFastFeatureCount) )
     173               0 :         return bPopulated && m_poAttrQuery == NULL;
     174                 : 
     175               0 :     else if( EQUAL(pszCap,OLCStringsAsUTF8) )
     176               0 :         return TRUE;
     177                 : 
     178                 :     else 
     179               0 :         return FALSE;
     180                 : }
     181                 : 
     182                 : /************************************************************************/
     183                 : /*                            AddRelation()                             */
     184                 : /************************************************************************/
     185                 : 
     186            3672 : void OGRNASRelationLayer::AddRelation( const char *pszFromID,
     187                 :                                        const char *pszType,
     188                 :                                        const char *pszToID )
     189                 : 
     190                 : {
     191            3672 :     int nMergedLen = strlen(pszFromID) + strlen(pszType) + strlen(pszToID) + 3;
     192            3672 :     char *pszMerged = (char *) CPLMalloc(nMergedLen);
     193                 :     
     194            3672 :     strcpy( pszMerged, pszFromID );
     195            3672 :     strcpy( pszMerged + strlen(pszFromID) + 1, pszType );
     196            3672 :     strcpy( pszMerged + strlen(pszFromID) + strlen(pszType) + 2, pszToID );
     197                 : 
     198            3672 :     CPLString osRelation;
     199            3672 :     osRelation.assign( pszMerged, nMergedLen );
     200                 : 
     201            3672 :     CPLFree( pszMerged );
     202                 : 
     203            3672 :     aoRelationCollection.push_back( osRelation );
     204            3672 : }
     205                 : 

Generated by: LCOV version 1.7