LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/ili - imdreader.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 54 55 98.2 %
Date: 2024-04-29 17:29:47 Functions: 11 11 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  * $Id$
       3             :  *
       4             :  * Project:  Interlis 1/2 Translator
       5             :  * Purpose:  IlisMeta model reader.
       6             :  * Author:   Pirmin Kalberer, Sourcepole AG
       7             :  *
       8             :  ******************************************************************************
       9             :  * Copyright (c) 2014, Pirmin Kalberer, Sourcepole AG
      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 IMDREADER_H_INCLUDED
      31             : #define IMDREADER_H_INCLUDED
      32             : 
      33             : #include "cpl_vsi.h"
      34             : #include "cpl_error.h"
      35             : #include "ogr_feature.h"
      36             : #include <list>
      37             : #include <map>
      38             : 
      39             : class GeomFieldInfo
      40             : {
      41             :     OGRFeatureDefn *geomTable; /* separate geometry table for Ili 1 */
      42             :   public:
      43             :     CPLString iliGeomType;
      44             : 
      45          74 :     GeomFieldInfo() : geomTable(nullptr)
      46             :     {
      47          74 :     }
      48             : 
      49         208 :     ~GeomFieldInfo()
      50         208 :     {
      51         208 :         if (geomTable)
      52          63 :             geomTable->Release();
      53         208 :     }
      54             : 
      55         134 :     GeomFieldInfo(const GeomFieldInfo &other)
      56         134 :     {
      57         134 :         geomTable = other.geomTable;
      58         134 :         if (geomTable)
      59          47 :             geomTable->Reference();
      60         134 :         iliGeomType = other.iliGeomType;
      61         134 :     }
      62             : 
      63             :     GeomFieldInfo &operator=(const GeomFieldInfo &other)
      64             :     {
      65             :         if (this != &other)
      66             :         {
      67             :             if (geomTable)
      68             :                 geomTable->Release();
      69             :             geomTable = other.geomTable;
      70             :             if (geomTable)
      71             :                 geomTable->Reference();
      72             :             iliGeomType = other.iliGeomType;
      73             :         }
      74             :         return *this;
      75             :     }
      76             : 
      77          50 :     OGRFeatureDefn *GetGeomTableDefnRef() const
      78             :     {
      79          50 :         return geomTable;
      80             :     }
      81             : 
      82          16 :     void SetGeomTableDefn(OGRFeatureDefn *geomTableIn)
      83             :     {
      84          16 :         CPLAssert(geomTable == nullptr);
      85          16 :         geomTable = geomTableIn;
      86          16 :         if (geomTable)
      87          16 :             geomTable->Reference();
      88          16 :     }
      89             : };
      90             : 
      91             : typedef std::map<CPLString, GeomFieldInfo>
      92             :     GeomFieldInfos; /* key: geom field name, value: ILI geom field info */
      93             : typedef std::map<CPLString, CPLString>
      94             :     StructFieldInfos; /* key: struct field name, value: struct table */
      95             : 
      96             : class FeatureDefnInfo
      97             : {
      98             :     OGRFeatureDefn *poTableDefn;
      99             : 
     100             :   public:
     101             :     GeomFieldInfos poGeomFieldInfos;
     102             :     StructFieldInfos poStructFieldInfos;
     103             : 
     104         660 :     FeatureDefnInfo() : poTableDefn(nullptr)
     105             :     {
     106         660 :     }
     107             : 
     108         746 :     ~FeatureDefnInfo()
     109         746 :     {
     110         746 :         if (poTableDefn)
     111         475 :             poTableDefn->Release();
     112         746 :     }
     113             : 
     114          86 :     FeatureDefnInfo(const FeatureDefnInfo &other)
     115          86 :     {
     116          86 :         poTableDefn = other.poTableDefn;
     117          86 :         if (poTableDefn)
     118          86 :             poTableDefn->Reference();
     119          86 :         poGeomFieldInfos = other.poGeomFieldInfos;
     120          86 :         poStructFieldInfos = other.poStructFieldInfos;
     121          86 :     }
     122             : 
     123           4 :     FeatureDefnInfo &operator=(const FeatureDefnInfo &other)
     124             :     {
     125           4 :         if (this != &other)
     126             :         {
     127           4 :             if (poTableDefn)
     128           0 :                 poTableDefn->Release();
     129           4 :             poTableDefn = other.poTableDefn;
     130           4 :             if (poTableDefn)
     131           4 :                 poTableDefn->Reference();
     132           4 :             poGeomFieldInfos = other.poGeomFieldInfos;
     133           4 :             poStructFieldInfos = other.poStructFieldInfos;
     134             :         }
     135           4 :         return *this;
     136             :     }
     137             : 
     138         209 :     OGRFeatureDefn *GetTableDefnRef() const
     139             :     {
     140         209 :         return poTableDefn;
     141             :     }
     142             : 
     143         385 :     void SetTableDefn(OGRFeatureDefn *poTableDefnIn)
     144             :     {
     145         385 :         CPLAssert(poTableDefn == nullptr);
     146         385 :         poTableDefn = poTableDefnIn;
     147         385 :         if (poTableDefn)
     148         385 :             poTableDefn->Reference();
     149         385 :     }
     150             : };
     151             : 
     152             : typedef std::list<FeatureDefnInfo> FeatureDefnInfos;
     153             : 
     154             : class IliModelInfo
     155             : {
     156             :   public:
     157             :     CPLString name;
     158             :     CPLString version;
     159             :     CPLString uri;
     160             : };
     161             : 
     162             : typedef std::list<IliModelInfo> IliModelInfos;
     163             : 
     164             : class ImdReader
     165             : {
     166             :   public:           // TODO(schwehr): Private?
     167             :     int iliVersion; /* 1 or 2 */
     168             :     IliModelInfos modelInfos;
     169             :     CPLString mainModelName;
     170             :     CPLString mainBasketName;
     171             :     CPLString mainTopicName;
     172             :     FeatureDefnInfos featureDefnInfos;
     173             :     char codeBlank;
     174             :     char codeUndefined;
     175             :     char codeContinue;
     176             : 
     177             :   public:
     178             :     explicit ImdReader(int iliVersion);
     179             :     ~ImdReader();
     180             :     void ReadModel(const char *pszFilename);
     181             :     FeatureDefnInfo GetFeatureDefnInfo(const char *pszLayerName);
     182             : };
     183             : 
     184             : #endif /* IMDREADER_H_INCLUDED */

Generated by: LCOV version 1.14