LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/jml - ogr_jml.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 14 14 100.0 %
Date: 2024-05-04 12:52:34 Functions: 7 7 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  * $Id$
       3             :  *
       4             :  * Project:  JML .jml Translator
       5             :  * Purpose:  Definition of classes for OGR JML driver.
       6             :  * Author:   Even Rouault, even dot rouault at spatialys dot com
       7             :  *
       8             :  ******************************************************************************
       9             :  * Copyright (c) 2014, Even Rouault <even dot rouault at spatialys dot 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_JML_H_INCLUDED
      31             : #define OGR_JML_H_INCLUDED
      32             : 
      33             : #include "ogrsf_frmts.h"
      34             : #include "ogr_p.h"
      35             : 
      36             : #ifdef HAVE_EXPAT
      37             : #include "ogr_expat.h"
      38             : #endif
      39             : 
      40             : #include <vector>
      41             : 
      42             : class OGRJMLDataset;
      43             : 
      44             : #ifdef HAVE_EXPAT
      45             : 
      46             : /************************************************************************/
      47             : /*                            OGRJMLColumn                              */
      48             : /************************************************************************/
      49             : 
      50             : class OGRJMLColumn
      51             : {
      52             :   public:
      53             :     CPLString osName;
      54             :     CPLString osType;
      55             :     CPLString osElementName;
      56             :     CPLString osAttributeName;
      57             :     CPLString osAttributeValue;
      58             :     bool bIsBody; /* if false: attribute */
      59             : 
      60          42 :     OGRJMLColumn() : bIsBody(false)
      61             :     {
      62          42 :     }
      63             : };
      64             : 
      65             : /************************************************************************/
      66             : /*                             OGRJMLLayer                              */
      67             : /************************************************************************/
      68             : 
      69             : class OGRJMLLayer final : public OGRLayer
      70             : {
      71             :     GDALDataset *m_poDS = nullptr;
      72             :     OGRFeatureDefn *poFeatureDefn;
      73             : 
      74             :     int nNextFID;
      75             :     VSILFILE *fp;
      76             :     bool bHasReadSchema;
      77             : 
      78             :     XML_Parser oParser;
      79             : 
      80             :     int currentDepth;
      81             :     bool bStopParsing;
      82             :     int nWithoutEventCounter;
      83             :     int nDataHandlerCounter;
      84             : 
      85             :     bool bAccumulateElementValue;
      86             :     char *pszElementValue;
      87             :     int nElementValueLen;
      88             :     int nElementValueAlloc;
      89             : 
      90             :     OGRFeature *poFeature;
      91             :     OGRFeature **ppoFeatureTab;
      92             :     int nFeatureTabLength;
      93             :     int nFeatureTabIndex;
      94             : 
      95             :     bool bSchemaFinished;
      96             :     int nJCSGMLInputTemplateDepth;
      97             :     int nCollectionElementDepth;
      98             :     int nFeatureCollectionDepth;
      99             :     CPLString osCollectionElement;
     100             :     int nFeatureElementDepth;
     101             :     CPLString osFeatureElement;
     102             :     int nGeometryElementDepth;
     103             :     CPLString osGeometryElement;
     104             :     int nColumnDepth;
     105             :     int nNameDepth;
     106             :     int nTypeDepth;
     107             :     int nAttributeElementDepth;
     108             :     int iAttr;
     109             :     int iRGBField;
     110             :     CPLString osSRSName;
     111             : 
     112             :     OGRJMLColumn oCurColumn;
     113             :     std::vector<OGRJMLColumn> aoColumns;
     114             : 
     115             :     void AddStringToElementValue(const char *data, int nLen);
     116             :     void StopAccumulate();
     117             : 
     118             :     void LoadSchema();
     119             : 
     120             :   public:
     121             :     OGRJMLLayer(const char *pszLayerName, OGRJMLDataset *poDS, VSILFILE *fp);
     122             :     ~OGRJMLLayer();
     123             : 
     124          28 :     const char *GetName() override
     125             :     {
     126          28 :         return poFeatureDefn->GetName();
     127             :     }
     128             : 
     129             :     void ResetReading() override;
     130             :     OGRFeature *GetNextFeature() override;
     131             : 
     132             :     OGRFeatureDefn *GetLayerDefn() override;
     133             : 
     134             :     int TestCapability(const char *) override;
     135             : 
     136           1 :     GDALDataset *GetDataset() override
     137             :     {
     138           1 :         return m_poDS;
     139             :     }
     140             : 
     141             :     void startElementCbk(const char *pszName, const char **ppszAttr);
     142             :     void endElementCbk(const char *pszName);
     143             :     void dataHandlerCbk(const char *data, int nLen);
     144             : 
     145             :     void startElementLoadSchemaCbk(const char *pszName, const char **ppszAttr);
     146             :     void endElementLoadSchemaCbk(const char *pszName);
     147             : };
     148             : 
     149             : #endif /* HAVE_EXPAT */
     150             : 
     151             : /************************************************************************/
     152             : /*                          OGRJMLWriterLayer                           */
     153             : /************************************************************************/
     154             : 
     155             : class OGRJMLWriterLayer final : public OGRLayer
     156             : {
     157             :     OGRJMLDataset *poDS;
     158             :     OGRFeatureDefn *poFeatureDefn;
     159             :     VSILFILE *fp;
     160             :     bool bFeaturesWritten;
     161             :     bool bAddRGBField;
     162             :     bool bAddOGRStyleField;
     163             :     bool bClassicGML;
     164             :     int nNextFID;
     165             :     CPLString osSRSAttr;
     166             :     OGREnvelope sLayerExtent;
     167             :     vsi_l_offset nBBoxOffset;
     168             : 
     169             :     void WriteColumnDeclaration(const char *pszName, const char *pszType);
     170             : 
     171             :   public:
     172             :     OGRJMLWriterLayer(const char *pszLayerName, OGRSpatialReference *poSRS,
     173             :                       OGRJMLDataset *poDSIn, VSILFILE *fp, bool bAddRGBField,
     174             :                       bool bAddOGRStyleField, bool bClassicGML);
     175             :     ~OGRJMLWriterLayer();
     176             : 
     177          17 :     void ResetReading() override
     178             :     {
     179          17 :     }
     180             : 
     181          17 :     OGRFeature *GetNextFeature() override
     182             :     {
     183          17 :         return nullptr;
     184             :     }
     185             : 
     186             :     OGRErr ICreateFeature(OGRFeature *poFeature) override;
     187             :     OGRErr CreateField(const OGRFieldDefn *poField, int bApproxOK) override;
     188             : 
     189         309 :     OGRFeatureDefn *GetLayerDefn() override
     190             :     {
     191         309 :         return poFeatureDefn;
     192             :     }
     193             : 
     194             :     int TestCapability(const char *) override;
     195             : 
     196             :     GDALDataset *GetDataset() override;
     197             : };
     198             : 
     199             : /************************************************************************/
     200             : /*                            OGRJMLDataset                             */
     201             : /************************************************************************/
     202             : 
     203             : class OGRJMLDataset final : public GDALDataset
     204             : {
     205             :     OGRLayer *poLayer;
     206             : 
     207             :     VSILFILE *fp; /* Virtual file API */
     208             :     bool bWriteMode;
     209             : 
     210             :   public:
     211             :     OGRJMLDataset();
     212             :     ~OGRJMLDataset();
     213             : 
     214          31 :     int GetLayerCount() override
     215             :     {
     216          31 :         return poLayer != nullptr ? 1 : 0;
     217             :     }
     218             : 
     219             :     OGRLayer *GetLayer(int) override;
     220             : 
     221             :     OGRLayer *ICreateLayer(const char *pszName,
     222             :                            const OGRGeomFieldDefn *poGeomFieldDefn,
     223             :                            CSLConstList papszOptions) override;
     224             : 
     225             :     int TestCapability(const char *) override;
     226             : 
     227             :     static int Identify(GDALOpenInfo *poOpenInfo);
     228             :     static GDALDataset *Open(GDALOpenInfo *poOpenInfo);
     229             :     static GDALDataset *Create(const char *pszFilename, int nBands, int nXSize,
     230             :                                int nYSize, GDALDataType eDT,
     231             :                                char **papszOptions);
     232             : };
     233             : 
     234             : #endif /* ndef OGR_JML_H_INCLUDED */

Generated by: LCOV version 1.14