LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/xplane - ogrxplanedatasource.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 64 57 89.1 %
Date: 2011-12-18 Functions: 11 7 63.6 %

       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 18548 2010-01-14 22:01:35Z rouault $");
      34                 : 
      35                 : /************************************************************************/
      36                 : /*                          OGRXPlaneDataSource()                          */
      37                 : /************************************************************************/
      38                 : 
      39             117 : OGRXPlaneDataSource::OGRXPlaneDataSource()
      40                 : 
      41                 : {
      42             117 :     pszName = NULL;
      43             117 :     papoLayers = NULL;
      44             117 :     nLayers = 0;
      45             117 :     poReader = NULL;
      46             117 :     bReadWholeFile = TRUE;
      47             117 :     bWholeFiledReadingDone = FALSE;
      48             117 : }
      49                 : 
      50                 : /************************************************************************/
      51                 : /*                         ~OGRXPlaneDataSource()                       */
      52                 : /************************************************************************/
      53                 : 
      54             117 : OGRXPlaneDataSource::~OGRXPlaneDataSource()
      55                 : 
      56                 : {
      57             117 :     Reset();
      58             117 : }
      59                 : 
      60                 : /************************************************************************/
      61                 : /*                              Reset()                                 */
      62                 : /************************************************************************/
      63                 : 
      64             234 : void OGRXPlaneDataSource::Reset()
      65                 : {
      66             234 :     if ( poReader != NULL)
      67                 :     {
      68               5 :         delete poReader;
      69               5 :         poReader = NULL;
      70                 :     }
      71                 : 
      72             234 :     CPLFree( pszName );
      73             234 :     pszName = NULL;
      74                 : 
      75             280 :     for( int i = 0; i < nLayers; i++ )
      76              46 :         delete papoLayers[i];
      77             234 :     CPLFree( papoLayers );
      78             234 :     papoLayers = NULL;
      79             234 :     nLayers = 0;
      80             234 : }
      81                 : 
      82                 : /************************************************************************/
      83                 : /*                              GetLayer()                              */
      84                 : /************************************************************************/
      85                 : 
      86             374 : OGRLayer *OGRXPlaneDataSource::GetLayer( int iLayer )
      87                 : 
      88                 : {
      89             374 :     if( iLayer < 0 || iLayer >= nLayers )
      90               0 :         return NULL;
      91                 :     else
      92             374 :         return papoLayers[iLayer];
      93                 : }
      94                 : 
      95                 : /************************************************************************/
      96                 : /*                           RegisterLayer()                            */
      97                 : /************************************************************************/
      98                 : 
      99              46 : void OGRXPlaneDataSource::RegisterLayer(OGRXPlaneLayer* poLayer)
     100                 : {
     101              46 :     poLayer->SetDataSource(this);
     102                 : 
     103                 :     papoLayers = (OGRXPlaneLayer**) CPLRealloc(papoLayers,
     104              46 :                                     (nLayers + 1) * sizeof(OGRXPlaneLayer*));
     105              46 :     papoLayers[nLayers++] = poLayer;
     106              46 : }
     107                 : 
     108                 : /************************************************************************/
     109                 : /*                                Open()                                */
     110                 : /************************************************************************/
     111                 : 
     112             117 : int OGRXPlaneDataSource::Open( const char * pszFilename, int bReadWholeFile )
     113                 : 
     114                 : {
     115             117 :     Reset();
     116                 : 
     117             117 :     this->bReadWholeFile = bReadWholeFile;
     118                 : 
     119             117 :     const char* pszShortFilename = CPLGetFilename(pszFilename);
     120             118 :     if (EQUAL(pszShortFilename, "nav.dat") ||
     121                 :         EQUAL(pszShortFilename, "earth_nav.dat"))
     122                 :     {
     123               1 :         poReader = OGRXPlaneCreateNavFileReader(this);
     124                 :     }
     125             116 :     else if (EQUAL(pszShortFilename, "apt.dat"))
     126                 :     {
     127               2 :         poReader = OGRXPlaneCreateAptFileReader(this);
     128                 :     }
     129             115 :     else if (EQUAL(pszShortFilename, "fix.dat") ||
     130                 :              EQUAL(pszShortFilename, "earth_fix.dat"))
     131                 :     {
     132               1 :         poReader = OGRXPlaneCreateFixFileReader(this);
     133                 :     }
     134             113 :     else if (EQUAL(pszShortFilename, "awy.dat") ||
     135                 :              EQUAL(pszShortFilename, "earth_awy.dat"))
     136                 :     {
     137               1 :         poReader = OGRXPlaneCreateAwyFileReader(this);
     138                 :     }
     139                 : 
     140                 :     int bRet;
     141             117 :     if (poReader && poReader->StartParsing(pszFilename) == FALSE)
     142                 :     {
     143               0 :         delete poReader;
     144               0 :         poReader = NULL;
     145                 :     }
     146             117 :     if (poReader)
     147                 :     {
     148               5 :         pszName = CPLStrdup(pszFilename);
     149                 : 
     150               5 :         if ( !bReadWholeFile )
     151                 :         {
     152               0 :             for( int i = 0; i < nLayers; i++ )
     153               0 :                 papoLayers[i]->SetReader(poReader->CloneForLayer(papoLayers[i]));
     154                 :         }
     155               5 :         bRet = TRUE;
     156                 :     }
     157                 :     else
     158             112 :         bRet = FALSE;
     159                 : 
     160             117 :     return bRet;
     161                 : }
     162                 : 
     163                 : /************************************************************************/
     164                 : /*                           TestCapability()                           */
     165                 : /************************************************************************/
     166                 : 
     167               0 : int OGRXPlaneDataSource::TestCapability( const char * pszCap )
     168                 : 
     169                 : {
     170               0 :     return FALSE;
     171                 : }
     172                 : 
     173                 : /************************************************************************/
     174                 : /*                     ReadWholeFileIfNecessary()                       */
     175                 : /************************************************************************/
     176                 : 
     177             466 : void OGRXPlaneDataSource::ReadWholeFileIfNecessary()
     178                 : {
     179             466 :     if (bReadWholeFile && !bWholeFiledReadingDone)
     180                 :     {
     181               5 :         poReader->ReadWholeFile();
     182              51 :         for( int i = 0; i < nLayers; i++ )
     183              46 :             papoLayers[i]->AutoAdjustColumnsWidth();
     184               5 :         bWholeFiledReadingDone = TRUE;
     185                 :     }
     186             466 : }

Generated by: LCOV version 1.7