LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/xplane - ogr_xplane_fix_reader.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 60 46 76.7 %
Date: 2011-12-18 Functions: 12 7 58.3 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogr_xplane_fix_reader.cpp
       3                 :  *
       4                 :  * Project:  X-Plane fix.dat file reader
       5                 :  * Purpose:  Implements OGRXPlaneFixReader 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_fix_reader.h"
      31                 : 
      32                 : CPL_CVSID("$Id: ogr_xplane_fix_reader.cpp 21634 2011-02-06 14:45:00Z rouault $");
      33                 : 
      34                 : /************************************************************************/
      35                 : /*                   OGRXPlaneCreateFixFileReader                       */
      36                 : /************************************************************************/
      37                 : 
      38               1 : OGRXPlaneReader* OGRXPlaneCreateFixFileReader( OGRXPlaneDataSource* poDataSource )
      39                 : {
      40               1 :     OGRXPlaneReader* poReader = new OGRXPlaneFixReader(poDataSource);
      41               1 :     return poReader;
      42                 : }
      43                 : 
      44                 : 
      45                 : /************************************************************************/
      46                 : /*                         OGRXPlaneFixReader()                         */
      47                 : /************************************************************************/
      48               0 : OGRXPlaneFixReader::OGRXPlaneFixReader()
      49                 : {
      50               0 :     poFIXLayer = NULL;
      51               0 : }
      52                 : 
      53                 : /************************************************************************/
      54                 : /*                          OGRXPlaneFixReader()                        */
      55                 : /************************************************************************/
      56                 : 
      57               1 : OGRXPlaneFixReader::OGRXPlaneFixReader( OGRXPlaneDataSource* poDataSource )
      58                 : {
      59               1 :     poFIXLayer = new OGRXPlaneFIXLayer();
      60                 : 
      61               1 :     poDataSource->RegisterLayer(poFIXLayer);
      62               1 : }
      63                 : 
      64                 : /************************************************************************/
      65                 : /*                        CloneForLayer()                               */
      66                 : /************************************************************************/
      67                 : 
      68               0 : OGRXPlaneReader* OGRXPlaneFixReader::CloneForLayer(OGRXPlaneLayer* poLayer)
      69                 : {
      70               0 :     OGRXPlaneFixReader* poReader = new OGRXPlaneFixReader();
      71                 : 
      72               0 :     poReader->poInterestLayer = poLayer;
      73                 : 
      74               0 :     SET_IF_INTEREST_LAYER(poFIXLayer);
      75                 : 
      76               0 :     if (pszFilename)
      77                 :     {
      78               0 :         poReader->pszFilename = CPLStrdup(pszFilename);
      79               0 :         poReader->fp = VSIFOpenL( pszFilename, "rt" );
      80                 :     }
      81                 : 
      82               0 :     return poReader;
      83                 : }
      84                 : 
      85                 : /************************************************************************/
      86                 : /*                         IsRecognizedVersion()                        */
      87                 : /************************************************************************/
      88                 : 
      89               1 : int OGRXPlaneFixReader::IsRecognizedVersion( const char* pszVersionString)
      90                 : {
      91               1 :     return EQUALN(pszVersionString, "600 Version", 11);
      92                 : }
      93                 : 
      94                 : /************************************************************************/
      95                 : /*                                Read()                                */
      96                 : /************************************************************************/
      97                 : 
      98               1 : void OGRXPlaneFixReader::Read()
      99                 : {
     100                 :     const char* pszLine;
     101               4 :     while((pszLine = CPLReadLineL(fp)) != NULL)
     102                 :     {
     103               3 :         papszTokens = CSLTokenizeString(pszLine);
     104               3 :         nTokens = CSLCount(papszTokens);
     105                 : 
     106               3 :         nLineNumber ++;
     107                 : 
     108               3 :         if (nTokens == 1 && strcmp(papszTokens[0], "99") == 0)
     109                 :         {
     110               1 :             CSLDestroy(papszTokens);
     111               1 :             papszTokens = NULL;
     112               1 :             bEOF = TRUE;
     113               1 :             return;
     114                 :         }
     115               2 :         else if (nTokens == 0 || assertMinCol(3) == FALSE)
     116                 :         {
     117               1 :             CSLDestroy(papszTokens);
     118               1 :             papszTokens = NULL;
     119               1 :             continue;
     120                 :         }
     121                 : 
     122               1 :         ParseRecord();
     123                 : 
     124               1 :         CSLDestroy(papszTokens);
     125               1 :         papszTokens = NULL;
     126                 : 
     127               1 :         if (poInterestLayer && poInterestLayer->IsEmpty() == FALSE)
     128               0 :             return;
     129                 :     }
     130                 : 
     131               0 :     papszTokens = NULL;
     132               0 :     bEOF = TRUE;
     133                 : }
     134                 : 
     135                 : /************************************************************************/
     136                 : /*                            ParseRecord()                             */
     137                 : /************************************************************************/
     138                 : 
     139               1 : void    OGRXPlaneFixReader::ParseRecord()
     140                 : {
     141                 :     double dfLat, dfLon;
     142               1 :     CPLString osName;
     143                 : 
     144               1 :     RET_IF_FAIL(readLatLon(&dfLat, &dfLon, 0));
     145               1 :     osName = readStringUntilEnd(2);
     146                 : 
     147               1 :     if (poFIXLayer)
     148               1 :         poFIXLayer->AddFeature(osName, dfLat, dfLon);
     149                 : }
     150                 : 
     151                 : 
     152                 : /************************************************************************/
     153                 : /*                           OGRXPlaneFIXLayer()                        */
     154                 : /************************************************************************/
     155                 : 
     156               1 : OGRXPlaneFIXLayer::OGRXPlaneFIXLayer() : OGRXPlaneLayer("FIX")
     157                 : {
     158               1 :     poFeatureDefn->SetGeomType( wkbPoint );
     159                 : 
     160               1 :     OGRFieldDefn oFieldName("fix_name", OFTString );
     161               1 :     oFieldName.SetPrecision(5);
     162               1 :     poFeatureDefn->AddFieldDefn( &oFieldName );
     163               1 : }
     164                 : 
     165                 : /************************************************************************/
     166                 : /*                           AddFeature()                               */
     167                 : /************************************************************************/
     168                 : 
     169                 : OGRFeature*
     170               1 :      OGRXPlaneFIXLayer::AddFeature(const char* pszFixName,
     171                 :                                    double dfLat,
     172                 :                                    double dfLon)
     173                 : {
     174               1 :     int nCount = 0;
     175               1 :     OGRFeature* poFeature = new OGRFeature(poFeatureDefn);
     176               2 :     poFeature->SetGeometryDirectly( new OGRPoint( dfLon, dfLat ) );
     177               1 :     poFeature->SetField( nCount++, pszFixName );
     178                 : 
     179               1 :     RegisterFeature(poFeature);
     180                 : 
     181               1 :     return poFeature;
     182                 : }

Generated by: LCOV version 1.7