LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/xplane - ogrxplanedatasource.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 58 51 87.9 %
Date: 2010-01-09 Functions: 8 7 87.5 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogrxplanedatasource.cpp
       3                 :  *
       4                 :  * Project:  X-Plane aeronautical data reader
       5                 :  * Purpose:  Implements OGRXPlaneDataSource class
       6                 :  * Author:   Even Rouault, even dot rouault at mines dash paris dot org
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 2008, Even Rouault
      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
      22                 :  * OR 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 "ogr_xplane.h"
      31                 : #include "ogr_xplane_reader.h"
      32                 : 
      33                 : CPL_CVSID("$Id: ogrxplanedatasource.cpp 17748 2009-10-03 21:46:41Z rouault $");
      34                 : 
      35                 : /************************************************************************/
      36                 : /*                          OGRXPlaneDataSource()                          */
      37                 : /************************************************************************/
      38                 : 
      39              31 : OGRXPlaneDataSource::OGRXPlaneDataSource()
      40                 : 
      41                 : {
      42              31 :     pszName = NULL;
      43              31 :     papoLayers = NULL;
      44              31 :     nLayers = 0;
      45              31 :     poReader = NULL;
      46              31 :     bReadWholeFile = TRUE;
      47              31 : }
      48                 : 
      49                 : /************************************************************************/
      50                 : /*                         ~OGRXPlaneDataSource()                       */
      51                 : /************************************************************************/
      52                 : 
      53              62 : OGRXPlaneDataSource::~OGRXPlaneDataSource()
      54                 : 
      55                 : {
      56              31 :     Reset();
      57              62 : }
      58                 : 
      59                 : /************************************************************************/
      60                 : /*                              Reset()                                 */
      61                 : /************************************************************************/
      62                 : 
      63              62 : void OGRXPlaneDataSource::Reset()
      64                 : {
      65              62 :     if ( poReader != NULL)
      66                 :     {
      67               4 :         delete poReader;
      68               4 :         poReader = NULL;
      69                 :     }
      70                 : 
      71              62 :     CPLFree( pszName );
      72              62 :     pszName = NULL;
      73                 : 
      74              90 :     for( int i = 0; i < nLayers; i++ )
      75              28 :         delete papoLayers[i];
      76              62 :     CPLFree( papoLayers );
      77              62 :     papoLayers = NULL;
      78              62 :     nLayers = 0;
      79              62 : }
      80                 : 
      81                 : /************************************************************************/
      82                 : /*                              GetLayer()                              */
      83                 : /************************************************************************/
      84                 : 
      85             203 : OGRLayer *OGRXPlaneDataSource::GetLayer( int iLayer )
      86                 : 
      87                 : {
      88             203 :     if( iLayer < 0 || iLayer >= nLayers )
      89               0 :         return NULL;
      90                 :     else
      91             203 :         return papoLayers[iLayer];
      92                 : }
      93                 : 
      94                 : /************************************************************************/
      95                 : /*                           RegisterLayer()                            */
      96                 : /************************************************************************/
      97                 : 
      98              28 : void OGRXPlaneDataSource::RegisterLayer(OGRXPlaneLayer* poLayer)
      99                 : {
     100                 :     papoLayers = (OGRXPlaneLayer**) CPLRealloc(papoLayers,
     101              28 :                                     (nLayers + 1) * sizeof(OGRXPlaneLayer*));
     102              28 :     papoLayers[nLayers++] = poLayer;
     103              28 : }
     104                 : 
     105                 : /************************************************************************/
     106                 : /*                                Open()                                */
     107                 : /************************************************************************/
     108                 : 
     109              31 : int OGRXPlaneDataSource::Open( const char * pszFilename, int bReadWholeFile )
     110                 : 
     111                 : {
     112              31 :     Reset();
     113                 : 
     114              31 :     this->bReadWholeFile = bReadWholeFile;
     115                 : 
     116              31 :     const char* pszShortFilename = CPLGetFilename(pszFilename);
     117              32 :     if (EQUAL(pszShortFilename, "nav.dat") ||
     118                 :         EQUAL(pszShortFilename, "earth_nav.dat"))
     119                 :     {
     120               1 :         poReader = OGRXPlaneCreateNavFileReader(this);
     121                 :     }
     122              30 :     else if (EQUAL(pszShortFilename, "apt.dat"))
     123                 :     {
     124               1 :         poReader = OGRXPlaneCreateAptFileReader(this);
     125                 :     }
     126              30 :     else if (EQUAL(pszShortFilename, "fix.dat") ||
     127                 :              EQUAL(pszShortFilename, "earth_fix.dat"))
     128                 :     {
     129               1 :         poReader = OGRXPlaneCreateFixFileReader(this);
     130                 :     }
     131              28 :     else if (EQUAL(pszShortFilename, "awy.dat") ||
     132                 :              EQUAL(pszShortFilename, "earth_awy.dat"))
     133                 :     {
     134               1 :         poReader = OGRXPlaneCreateAwyFileReader(this);
     135                 :     }
     136                 : 
     137                 :     int bRet;
     138              31 :     if (poReader && poReader->StartParsing(pszFilename) == FALSE)
     139                 :     {
     140               0 :         delete poReader;
     141               0 :         poReader = NULL;
     142                 :     }
     143              31 :     if (poReader)
     144                 :     {
     145               4 :         pszName = CPLStrdup(pszFilename);
     146                 : 
     147               4 :         if (bReadWholeFile)
     148                 :         {
     149               4 :             poReader->ReadWholeFile();
     150              32 :             for( int i = 0; i < nLayers; i++ )
     151              28 :                 papoLayers[i]->AutoAdjustColumnsWidth();
     152                 :         }
     153                 :         else
     154                 :         {
     155               0 :             for( int i = 0; i < nLayers; i++ )
     156               0 :                 papoLayers[i]->SetReader(poReader->CloneForLayer(papoLayers[i]));
     157                 :         }
     158               4 :         bRet = TRUE;
     159                 :     }
     160                 :     else
     161              27 :         bRet = FALSE;
     162                 : 
     163              31 :     return bRet;
     164                 : }
     165                 : 
     166                 : /************************************************************************/
     167                 : /*                           TestCapability()                           */
     168                 : /************************************************************************/
     169                 : 
     170               0 : int OGRXPlaneDataSource::TestCapability( const char * pszCap )
     171                 : 
     172                 : {
     173               0 :     return FALSE;
     174                 : }

Generated by: LCOV version 1.7