LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/ngw - ogrngwfielddomain.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 0 62 0.0 %
Date: 2025-02-20 10:14:44 Functions: 0 5 0.0 %

          Line data    Source code
       1             : /*******************************************************************************
       2             :  *  Project: NextGIS Web Driver
       3             :  *  Purpose: Implements NextGIS Web Driver
       4             :  *  Author: Dmitry Baryshnikov, dmitry.baryshnikov@nextgis.com
       5             :  *  Language: C++
       6             :  *******************************************************************************
       7             :  *  The MIT License (MIT)
       8             :  *
       9             :  *  Copyright (c) 2025, NextGIS <info@nextgis.com>
      10             :  *
      11             :  * SPDX-License-Identifier: MIT
      12             :  *******************************************************************************/
      13             : 
      14             : #include "ogr_ngw.h"
      15             : 
      16             : /*
      17             :  * OGRNGWCodedFieldDomain()
      18             :  */
      19           0 : OGRNGWCodedFieldDomain::OGRNGWCodedFieldDomain(
      20           0 :     const CPLJSONObject &oResourceJsonObject)
      21             : {
      22           0 :     nResourceID = oResourceJsonObject.GetLong("resource/id", 0);
      23           0 :     nResourceParentID = oResourceJsonObject.GetLong("resource/parent/id", 0);
      24           0 :     osCreationDate = oResourceJsonObject.GetString("resource/creation_date");
      25           0 :     osDisplayName = oResourceJsonObject.GetString("resource/display_name");
      26           0 :     osKeyName = oResourceJsonObject.GetString("resource/keyname");
      27           0 :     osDescription = oResourceJsonObject.GetString("resource/description");
      28             : 
      29           0 :     std::set<GIntBig> keys;
      30             : 
      31           0 :     bool bOnlyDigitsKeys = true;
      32           0 :     std::vector<OGRCodedValue> aoDom1, aoDom2, aoDom3;
      33           0 :     auto oItems = oResourceJsonObject.GetObj("lookup_table/items");
      34           0 :     for (const auto &oItem : oItems.GetChildren())
      35             :     {
      36           0 :         if (bOnlyDigitsKeys)
      37             :         {
      38           0 :             auto nNum = CPLAtoGIntBig(oItem.GetName().c_str());
      39           0 :             if (keys.find(nNum) != keys.end())
      40             :             {
      41           0 :                 bOnlyDigitsKeys = false;
      42             :             }
      43             :             else
      44             :             {
      45           0 :                 keys.insert(nNum);
      46             :             }
      47             :         }
      48             : 
      49             :         OGRCodedValue cv1;
      50           0 :         cv1.pszCode = CPLStrdup(oItem.GetName().c_str());
      51           0 :         cv1.pszValue = CPLStrdup(oItem.ToString().c_str());
      52           0 :         aoDom1.emplace_back(cv1);
      53             : 
      54             :         OGRCodedValue cv2;
      55           0 :         cv2.pszCode = CPLStrdup(oItem.GetName().c_str());
      56           0 :         cv2.pszValue = CPLStrdup(oItem.ToString().c_str());
      57           0 :         aoDom2.emplace_back(cv2);
      58             : 
      59             :         OGRCodedValue cv3;
      60           0 :         cv3.pszCode = CPLStrdup(oItem.GetName().c_str());
      61           0 :         cv3.pszValue = CPLStrdup(oItem.ToString().c_str());
      62           0 :         aoDom3.emplace_back(cv3);
      63             :     }
      64             : 
      65           0 :     auto osName = osDisplayName;
      66             :     auto oDom = std::make_shared<OGRCodedFieldDomain>(
      67           0 :         osName, osDescription, OFTString, OFSTNone, std::move(aoDom1));
      68           0 :     apDomains[0] = std::move(oDom);
      69             : 
      70           0 :     if (bOnlyDigitsKeys)
      71             :     {
      72           0 :         osName = osDisplayName + " (number)";
      73           0 :         oDom = std::make_shared<OGRCodedFieldDomain>(
      74           0 :             osName, osDescription, OFTInteger, OFSTNone, std::move(aoDom2));
      75           0 :         apDomains[1] = std::move(oDom);
      76             : 
      77           0 :         osName = osDisplayName + " (bigint)";
      78           0 :         oDom = std::make_shared<OGRCodedFieldDomain>(
      79           0 :             osName, osDescription, OFTInteger64, OFSTNone, std::move(aoDom3));
      80           0 :         apDomains[2] = std::move(oDom);
      81             :     }
      82           0 : }
      83             : 
      84             : /*
      85             :  * ToFieldDomain()
      86             :  */
      87             : const OGRFieldDomain *
      88           0 : OGRNGWCodedFieldDomain::ToFieldDomain(OGRFieldType eFieldType) const
      89             : {
      90           0 :     for (size_t i = 0; i < apDomains.size(); ++i)
      91             :     {
      92           0 :         if (apDomains[i] && apDomains[i]->GetFieldType() == eFieldType)
      93             :         {
      94           0 :             return apDomains[i].get();
      95             :         }
      96             :     }
      97           0 :     return nullptr;
      98             : }
      99             : 
     100             : /*
     101             :  * GetID()
     102             :  */
     103           0 : GIntBig OGRNGWCodedFieldDomain::GetID() const
     104             : {
     105           0 :     return nResourceID;
     106             : }
     107             : 
     108             : /*
     109             :  * GetDomainsNames()
     110             :  */
     111           0 : std::string OGRNGWCodedFieldDomain::GetDomainsNames() const
     112             : {
     113           0 :     std::string osOut;
     114           0 :     for (size_t i = 0; i < apDomains.size(); ++i)
     115             :     {
     116           0 :         if (apDomains[i])
     117             :         {
     118           0 :             if (osOut.empty())
     119             :             {
     120           0 :                 osOut = apDomains[i]->GetName();
     121             :             }
     122             :             else
     123             :             {
     124           0 :                 osOut += ", " + apDomains[i]->GetName();
     125             :             }
     126             :         }
     127             :     }
     128           0 :     return osOut;
     129             : }
     130             : 
     131             : /**
     132             :  * HasDomainName()
     133             :  */
     134           0 : bool OGRNGWCodedFieldDomain::HasDomainName(const std::string &osName) const
     135             : {
     136           0 :     if (osName.empty())
     137             :     {
     138           0 :         return false;
     139             :     }
     140           0 :     for (size_t i = 0; i < apDomains.size(); ++i)
     141             :     {
     142           0 :         if (apDomains[i] && apDomains[i]->GetName() == osName)
     143             :         {
     144           0 :             return true;
     145             :         }
     146             :     }
     147           0 :     return false;
     148             : }

Generated by: LCOV version 1.14