LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/vdv - ogr_vdv.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 13 13 100.0 %
Date: 2018-04-20 Functions: 11 11 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  * $Id$
       3             :  *
       4             :  * Project:  VDV Translator
       5             :  * Purpose:  Implements OGRVDVDriver.
       6             :  * Author:   Even Rouault, even.rouault at spatialys.com
       7             :  *
       8             :  ******************************************************************************
       9             :  * Copyright (c) 2015, Even Rouault <even.rouault at spatialys.com>
      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             : #ifndef OGR_VDV_H_INCLUDED
      31             : #define OGR_VDV_H_INCLUDED
      32             : 
      33             : #include "ogrsf_frmts.h"
      34             : #include <vector>
      35             : #include <map>
      36             : 
      37             : class OGRVDVDataSource;
      38             : 
      39             : /************************************************************************/
      40             : /*                        OGRIDFDataSource                              */
      41             : /************************************************************************/
      42             : 
      43             : class OGRIDFDataSource : public GDALDataset
      44             : {
      45             :     VSILFILE*           m_fpL;
      46             :     bool                m_bHasParsed;
      47             :     GDALDataset        *m_poMemDS;
      48             : 
      49             :     void                Parse();
      50             : 
      51             :   public:
      52             :     explicit            OGRIDFDataSource(VSILFILE* fpL);
      53             :                         virtual ~OGRIDFDataSource();
      54             : 
      55             :     virtual int                 GetLayerCount() override;
      56             :     virtual OGRLayer*           GetLayer( int ) override;
      57             : };
      58             : 
      59             : /************************************************************************/
      60             : /*                          OGRVDVLayer                                 */
      61             : /************************************************************************/
      62             : 
      63             : class OGRVDVLayer: public OGRLayer
      64             : {
      65             :     VSILFILE*           m_fpL;
      66             :     bool                m_bOwnFP;
      67             :     bool                m_bRecodeFromLatin1;
      68             :     vsi_l_offset        m_nStartOffset;
      69             :     vsi_l_offset        m_nCurOffset;
      70             :     GIntBig             m_nTotalFeatureCount;
      71             :     GIntBig             m_nFID;
      72             :     OGRFeatureDefn*     m_poFeatureDefn;
      73             :     bool                m_bEOF;
      74             :     int                 m_iLongitudeVDV452;
      75             :     int                 m_iLatitudeVDV452;
      76             : 
      77             :   public:
      78             :                         OGRVDVLayer(const CPLString& osTableName,
      79             :                                     VSILFILE* fpL,
      80             :                                     bool bOwnFP,
      81             :                                     bool bRecodeFromLatin1,
      82             :                                     vsi_l_offset nStartOffset);
      83             :                         virtual ~OGRVDVLayer();
      84             : 
      85             :         virtual void            ResetReading() override;
      86             :         virtual OGRFeature     *GetNextFeature() override;
      87             :         virtual GIntBig         GetFeatureCount(int bForce) override;
      88        1350 :         virtual OGRFeatureDefn *GetLayerDefn() override { return m_poFeatureDefn; }
      89             :         virtual int             TestCapability(const char* pszCap) override;
      90             : 
      91          67 :         void                    SetFeatureCount(GIntBig nTotalFeatureCount)
      92          67 :                             { m_nTotalFeatureCount = nTotalFeatureCount; }
      93             : };
      94             : 
      95        8799 : class OGRVDV452Field
      96             : {
      97             :     public:
      98             :         CPLString osEnglishName;
      99             :         CPLString osGermanName;
     100             :         CPLString osType;
     101             :         int       nWidth;
     102             : 
     103        1617 :             OGRVDV452Field() : nWidth(0) {}
     104             : };
     105             : 
     106         476 : class OGRVDV452Table
     107             : {
     108             :     public:
     109             :         CPLString osEnglishName;
     110             :         CPLString osGermanName;
     111             :         std::vector<OGRVDV452Field> aosFields;
     112             : };
     113             : 
     114             : class OGRVDV452Tables
     115             : {
     116             :     public:
     117             :         std::vector<OGRVDV452Table*> aosTables;
     118             :         std::map<CPLString, OGRVDV452Table*> oMapEnglish;
     119             :         std::map<CPLString, OGRVDV452Table*> oMapGerman;
     120             : 
     121         113 :             OGRVDV452Tables() {}
     122         113 :             ~OGRVDV452Tables()
     123         113 :             {
     124         351 :                 for(size_t i=0;i<aosTables.size();i++)
     125         238 :                     delete aosTables[i];
     126         113 :             }
     127             : };
     128             : 
     129             : /************************************************************************/
     130             : /*                          OGRVDVWriterLayer                           */
     131             : /************************************************************************/
     132             : 
     133             : class OGRVDVWriterLayer: public OGRLayer
     134             : {
     135             :     OGRVDVDataSource*   m_poDS;
     136             :     OGRFeatureDefn*     m_poFeatureDefn;
     137             :     bool                m_bWritePossible;
     138             :     VSILFILE*           m_fpL;
     139             :     bool                m_bOwnFP;
     140             :     GIntBig             m_nFeatureCount;
     141             :     OGRVDV452Table     *m_poVDV452Table;
     142             :     CPLString           m_osVDV452Lang;
     143             :     bool                m_bProfileStrict;
     144             :     int                 m_iLongitudeVDV452;
     145             :     int                 m_iLatitudeVDV452;
     146             : 
     147             :         bool                    WriteSchemaIfNeeded();
     148             : 
     149             :   public:
     150             :                         OGRVDVWriterLayer(OGRVDVDataSource *poDS,
     151             :                                           const char* pszName,
     152             :                                           VSILFILE* fpL,
     153             :                                           bool bOwnFP,
     154             :                                           OGRVDV452Table* poVDV452Table = nullptr,
     155             :                                           const CPLString& osVDV452Lang = "",
     156             :                                           bool bProfileStrict = false
     157             :                                           );
     158             :                         virtual ~OGRVDVWriterLayer();
     159             : 
     160             :         virtual void            ResetReading() override;
     161             :         virtual OGRFeature     *GetNextFeature() override;
     162         475 :         virtual OGRFeatureDefn *GetLayerDefn() override { return m_poFeatureDefn; }
     163             :         virtual int             TestCapability(const char* pszCap) override;
     164             :         virtual OGRErr          CreateField(OGRFieldDefn* poFieldDefn, int bApproxOK = TRUE) override;
     165             :         virtual OGRErr          ICreateFeature(OGRFeature* poFeature) override;
     166             :         virtual GIntBig         GetFeatureCount(int bForce = TRUE) override;
     167             : 
     168             :         void                    StopAsCurrentLayer();
     169             : };
     170             : 
     171             : /************************************************************************/
     172             : /*                        OGRVDVDataSource                              */
     173             : /************************************************************************/
     174             : 
     175             : class OGRVDVDataSource : public GDALDataset
     176             : {
     177             :     CPLString           m_osFilename;
     178             :     VSILFILE*           m_fpL;
     179             :     bool                m_bUpdate;
     180             :     bool                m_bSingleFile;
     181             :     bool                m_bNew;
     182             :     bool                m_bLayersDetected;
     183             :     int                 m_nLayerCount;
     184             :     OGRLayer          **m_papoLayers;
     185             :     OGRVDVWriterLayer  *m_poCurrentWriterLayer;
     186             :     bool                m_bMustWriteEof;
     187             :     bool                m_bVDV452Loaded;
     188             :     OGRVDV452Tables     m_oVDV452Tables;
     189             : 
     190             :     void                DetectLayers();
     191             : 
     192             :   public:
     193             :                         OGRVDVDataSource(const char* pszFilename,
     194             :                                          VSILFILE* fpL,
     195             :                                          bool bUpdate,
     196             :                                          bool bSingleFile,
     197             :                                          bool bNew);
     198             :                         virtual ~OGRVDVDataSource();
     199             : 
     200             :     virtual int                 GetLayerCount() override;
     201             :     virtual OGRLayer*           GetLayer( int ) override;
     202             :     virtual OGRLayer*           ICreateLayer( const char *pszLayerName,
     203             :                                       OGRSpatialReference * /*poSpatialRef*/,
     204             :                                       OGRwkbGeometryType /*eGType*/,
     205             :                                       char ** papszOptions  ) override;
     206             :     virtual int                 TestCapability( const char * pszCap ) override;
     207             : 
     208             :     void                        SetCurrentWriterLayer(OGRVDVWriterLayer* poLayer);
     209             : 
     210             :     static GDALDataset*    Open( GDALOpenInfo* poOpenInfo );
     211             :     static GDALDataset*    Create( const char * pszName,
     212             :                                         int /*nXSize*/, int /*nYSize*/, int /*nBands*/,
     213             :                                         GDALDataType /*eType*/,
     214             :                                         char ** papszOptions );
     215             : };
     216             : 
     217             : #endif /* ndef OGR_VDV_H_INCLUDED */

Generated by: LCOV version 1.10