LCOV - code coverage report
Current view: top level - ogr - ogrfielddefn.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 509 592 86.0 %
Date: 2025-01-18 12:42:00 Functions: 83 91 91.2 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  OpenGIS Simple Features Reference Implementation
       4             :  * Purpose:  The OGRFieldDefn class implementation.
       5             :  * Author:   Frank Warmerdam, warmerda@home.com
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 1999,  Les Technologies SoftMap Inc.
       9             :  * Copyright (c) 2009-2013, Even Rouault <even dot rouault at spatialys.com>
      10             :  *
      11             :  * SPDX-License-Identifier: MIT
      12             :  ****************************************************************************/
      13             : 
      14             : #include "cpl_port.h"
      15             : #include "ogr_feature.h"
      16             : 
      17             : #include <cstring>
      18             : 
      19             : #include "ogr_api.h"
      20             : #include "ogr_core.h"
      21             : #include "ogr_p.h"
      22             : #include "ograpispy.h"
      23             : #include "cpl_conv.h"
      24             : #include "cpl_error.h"
      25             : #include "cpl_string.h"
      26             : 
      27             : /************************************************************************/
      28             : /*                            OGRFieldDefn()                            */
      29             : /************************************************************************/
      30             : 
      31             : /**
      32             :  * \brief Constructor.
      33             :  *
      34             :  * By default, fields have no width, precision, are nullable and not ignored.
      35             :  *
      36             :  * @param pszNameIn the name of the new field.
      37             :  * @param eTypeIn the type of the new field.
      38             :  */
      39             : 
      40      620852 : OGRFieldDefn::OGRFieldDefn(const char *pszNameIn, OGRFieldType eTypeIn)
      41      620852 :     : pszName(CPLStrdup(pszNameIn)), pszAlternativeName(CPLStrdup("")),
      42             :       eType(eTypeIn), eJustify(OJUndefined),
      43             :       // Should nWidth & nPrecision be defined in some particular way for
      44             :       // numbers?
      45             :       nWidth(0), nPrecision(0), pszDefault(nullptr), bIgnore(FALSE),
      46      620852 :       eSubType(OFSTNone), bNullable(TRUE), bUnique(FALSE)
      47             : {
      48      620852 : }
      49             : 
      50             : /************************************************************************/
      51             : /*                            OGRFieldDefn()                            */
      52             : /************************************************************************/
      53             : 
      54             : /**
      55             :  * \brief Constructor.
      56             :  *
      57             :  * Create by cloning an existing field definition.
      58             :  *
      59             :  * @param poPrototype the field definition to clone.
      60             :  */
      61             : 
      62      725661 : OGRFieldDefn::OGRFieldDefn(const OGRFieldDefn *poPrototype)
      63      725661 :     : pszName(CPLStrdup(poPrototype->GetNameRef())),
      64      725661 :       pszAlternativeName(CPLStrdup(poPrototype->GetAlternativeNameRef())),
      65     1451320 :       eType(poPrototype->GetType()), eJustify(poPrototype->GetJustify()),
      66     1451320 :       nWidth(poPrototype->GetWidth()), nPrecision(poPrototype->GetPrecision()),
      67             :       pszDefault(nullptr),
      68             :       bIgnore(FALSE),  // TODO(schwehr): Can we use IsIgnored()?
      69     1451320 :       eSubType(poPrototype->GetSubType()), bNullable(poPrototype->IsNullable()),
      70      725661 :       bUnique(poPrototype->IsUnique()),
      71      725661 :       m_osDomainName(poPrototype->m_osDomainName),
      72      725661 :       m_osComment(poPrototype->GetComment()),
      73     1451320 :       m_nTZFlag(poPrototype->GetTZFlag())
      74             : {
      75      725661 :     SetDefault(poPrototype->GetDefault());
      76      725661 : }
      77             : 
      78             : /************************************************************************/
      79             : /*                           OGR_Fld_Create()                           */
      80             : /************************************************************************/
      81             : /**
      82             :  * \brief Create a new field definition.
      83             :  *
      84             :  * By default, fields have no width, precision, are nullable and not ignored.
      85             :  *
      86             :  * This function is the same as the CPP method OGRFieldDefn::OGRFieldDefn().
      87             :  *
      88             :  * @param pszName the name of the new field definition.
      89             :  * @param eType the type of the new field definition.
      90             :  * @return handle to the new field definition.
      91             :  */
      92             : 
      93       78134 : OGRFieldDefnH OGR_Fld_Create(const char *pszName, OGRFieldType eType)
      94             : 
      95             : {
      96       78134 :     return OGRFieldDefn::ToHandle(new OGRFieldDefn(pszName, eType));
      97             : }
      98             : 
      99             : /************************************************************************/
     100             : /*                           ~OGRFieldDefn()                            */
     101             : /************************************************************************/
     102             : 
     103     1347400 : OGRFieldDefn::~OGRFieldDefn()
     104             : 
     105             : {
     106     1347400 :     CPLFree(pszName);
     107     1347400 :     CPLFree(pszAlternativeName);
     108     1347400 :     CPLFree(pszDefault);
     109     1347400 : }
     110             : 
     111             : /************************************************************************/
     112             : /*                             OGRFieldDefn::OGRFieldDefn()             */
     113             : /************************************************************************/
     114             : 
     115             : /**
     116             :  * @brief OGRFieldDefn::OGRFieldDefn copy constructor.
     117             :  * @param oOther the object to copy.
     118             :  * @since GDAL 3.11
     119             :  */
     120         953 : OGRFieldDefn::OGRFieldDefn(const OGRFieldDefn &oOther)
     121         953 :     : pszName(CPLStrdup(oOther.pszName)),
     122        1906 :       pszAlternativeName(CPLStrdup(oOther.pszAlternativeName)),
     123         953 :       eType(oOther.eType), eJustify(oOther.eJustify), nWidth(oOther.nWidth),
     124         953 :       nPrecision(oOther.nPrecision),
     125         953 :       pszDefault(oOther.pszDefault ? CPLStrdup(oOther.pszDefault) : nullptr),
     126         953 :       bIgnore(oOther.bIgnore), eSubType(oOther.eSubType),
     127         953 :       bNullable(oOther.bNullable), bUnique(oOther.bUnique),
     128        1906 :       m_osDomainName(oOther.m_osDomainName), m_osComment(oOther.m_osComment),
     129        1906 :       m_nTZFlag(oOther.m_nTZFlag), m_bSealed(oOther.m_bSealed)
     130             : {
     131         953 : }
     132             : 
     133             : /************************************************************************/
     134             : /*                           OGRFieldDefn::operator=()                  */
     135             : /************************************************************************/
     136             : 
     137             : /**
     138             :  * @brief OGRFieldDefn::operator = assignment operator.
     139             :  * @param oOther the object to copy.
     140             :  * @return the current object.
     141             :  * @since GDAL 3.11
     142             :  */
     143           4 : OGRFieldDefn &OGRFieldDefn::operator=(const OGRFieldDefn &oOther)
     144             : {
     145           4 :     if (&oOther != this)
     146             :     {
     147           4 :         CPLFree(pszName);
     148           4 :         pszName = CPLStrdup(oOther.pszName);
     149           4 :         CPLFree(pszAlternativeName);
     150           4 :         pszAlternativeName = CPLStrdup(oOther.pszAlternativeName);
     151           4 :         eType = oOther.eType;
     152           4 :         eJustify = oOther.eJustify;
     153           4 :         nWidth = oOther.nWidth;
     154           4 :         nPrecision = oOther.nPrecision;
     155           4 :         CPLFree(pszDefault);
     156           4 :         pszDefault = oOther.pszDefault ? CPLStrdup(oOther.pszDefault) : nullptr;
     157           4 :         bIgnore = oOther.bIgnore;
     158           4 :         eSubType = oOther.eSubType;
     159           4 :         bNullable = oOther.bNullable;
     160           4 :         bUnique = oOther.bUnique;
     161           4 :         m_osDomainName = oOther.m_osDomainName;
     162           4 :         m_osComment = oOther.m_osComment;
     163           4 :         m_nTZFlag = oOther.m_nTZFlag;
     164           4 :         m_bSealed = oOther.m_bSealed;
     165             :     }
     166           4 :     return *this;
     167             : }
     168             : 
     169             : /************************************************************************/
     170             : /*                          OGR_Fld_Destroy()                           */
     171             : /************************************************************************/
     172             : /**
     173             :  * \brief Destroy a field definition.
     174             :  *
     175             :  * @param hDefn handle to the field definition to destroy.
     176             :  */
     177             : 
     178       78117 : void OGR_Fld_Destroy(OGRFieldDefnH hDefn)
     179             : 
     180             : {
     181       78117 :     delete OGRFieldDefn::FromHandle(hDefn);
     182       78117 : }
     183             : 
     184             : /************************************************************************/
     185             : /*                              SetName()                               */
     186             : /************************************************************************/
     187             : 
     188             : /**
     189             :  * \brief Reset the name of this field.
     190             :  *
     191             :  * This method is the same as the C function OGR_Fld_SetName().
     192             :  *
     193             :  * Note that once a OGRFieldDefn has been added to a layer definition with
     194             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
     195             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
     196             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
     197             :  * OGRFieldDefn, for drivers that support AlterFieldDefn.
     198             :  *
     199             :  * @param pszNameIn the new name to apply.
     200             :  */
     201             : 
     202      110431 : void OGRFieldDefn::SetName(const char *pszNameIn)
     203             : 
     204             : {
     205      110431 :     if (m_bSealed)
     206             :     {
     207           5 :         CPLError(CE_Failure, CPLE_AppDefined,
     208             :                  "OGRFieldDefn::SetName() not allowed on a sealed object");
     209           5 :         return;
     210             :     }
     211      110426 :     if (pszName != pszNameIn)
     212             :     {
     213      110419 :         CPLFree(pszName);
     214      110419 :         pszName = CPLStrdup(pszNameIn);
     215             :     }
     216             : }
     217             : 
     218             : /************************************************************************/
     219             : /*                          OGR_Fld_SetName()                           */
     220             : /************************************************************************/
     221             : /**
     222             :  * \brief Reset the name of this field.
     223             :  *
     224             :  * This function is the same as the CPP method OGRFieldDefn::SetName().
     225             :  *
     226             :  * Note that once a OGRFieldDefn has been added to a layer definition with
     227             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
     228             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
     229             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
     230             :  * OGRFieldDefn, for drivers that support AlterFieldDefn.
     231             :  *
     232             :  * @param hDefn handle to the field definition to apply the new name to.
     233             :  * @param pszName the new name to apply.
     234             :  */
     235             : 
     236           2 : void OGR_Fld_SetName(OGRFieldDefnH hDefn, const char *pszName)
     237             : 
     238             : {
     239           2 :     OGRFieldDefn::FromHandle(hDefn)->SetName(pszName);
     240           2 : }
     241             : 
     242             : /************************************************************************/
     243             : /*                             GetNameRef()                             */
     244             : /************************************************************************/
     245             : 
     246             : /**
     247             :  * \fn const char *OGRFieldDefn::GetNameRef();
     248             :  *
     249             :  * \brief Fetch name of this field.
     250             :  *
     251             :  * This method is the same as the C function OGR_Fld_GetNameRef().
     252             :  *
     253             :  * @return pointer to an internal name string that should not be freed or
     254             :  * modified.
     255             :  */
     256             : 
     257             : /************************************************************************/
     258             : /*                         OGR_Fld_GetNameRef()                         */
     259             : /************************************************************************/
     260             : /**
     261             :  * \brief Fetch name of this field.
     262             :  *
     263             :  * This function is the same as the CPP method OGRFieldDefn::GetNameRef().
     264             :  *
     265             :  * @param hDefn handle to the field definition.
     266             :  * @return the name of the field definition.
     267             :  *
     268             :  */
     269             : 
     270      214775 : const char *OGR_Fld_GetNameRef(OGRFieldDefnH hDefn)
     271             : 
     272             : {
     273             : 
     274             : #ifdef OGRAPISPY_ENABLED
     275      214775 :     if (bOGRAPISpyEnabled)
     276           2 :         OGRAPISpy_Fld_GetXXXX(hDefn, "GetNameRef");
     277             : #endif
     278             : 
     279      214775 :     return OGRFieldDefn::FromHandle(hDefn)->GetNameRef();
     280             : }
     281             : 
     282             : /************************************************************************/
     283             : /*                              SetAlternativeName()                    */
     284             : /************************************************************************/
     285             : 
     286             : /**
     287             :  * \brief Reset the alternative name (or "alias") for this field.
     288             :  *
     289             :  * The alternative name is an optional attribute for a field which can provide
     290             :  * a more user-friendly, descriptive name of a field which is not subject to
     291             :  * the usual naming constraints defined by the data provider.
     292             :  *
     293             :  * This is a metadata style attribute only: the alternative name cannot
     294             :  * be used in place of the actual field name during SQL queries or other
     295             :  * field name dependent API calls.
     296             :  *
     297             :  * This method is the same as the C function OGR_Fld_SetAlternativeName().
     298             :  *
     299             :  * Note that once a OGRFieldDefn has been added to a layer definition with
     300             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
     301             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
     302             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
     303             :  * OGRFieldDefn, for drivers that support AlterFieldDefn.
     304             :  *
     305             :  * @param pszAlternativeNameIn the new alternative name to apply.
     306             :  *
     307             :  * @since GDAL 3.2
     308             :  */
     309             : 
     310       71257 : void OGRFieldDefn::SetAlternativeName(const char *pszAlternativeNameIn)
     311             : 
     312             : {
     313       71257 :     if (m_bSealed)
     314             :     {
     315           1 :         CPLError(CE_Failure, CPLE_AppDefined,
     316             :                  "OGRFieldDefn::SetAlternativeName() not allowed on a sealed "
     317             :                  "object");
     318           1 :         return;
     319             :     }
     320       71256 :     if (pszAlternativeName != pszAlternativeNameIn)
     321             :     {
     322       71256 :         CPLFree(pszAlternativeName);
     323       71256 :         pszAlternativeName = CPLStrdup(pszAlternativeNameIn);
     324             :     }
     325             : }
     326             : 
     327             : /************************************************************************/
     328             : /*                          OGR_Fld_SetAlternativeName()                */
     329             : /************************************************************************/
     330             : /**
     331             :  * \brief Reset the alternative name (or "alias") for this field.
     332             :  *
     333             :  * The alternative name is an optional attribute for a field which can provide
     334             :  * a more user-friendly, descriptive name of a field which is not subject to
     335             :  * the usual naming constraints defined by the data provider.
     336             :  *
     337             :  * This is a metadata style attribute only: the alternative name cannot
     338             :  * be used in place of the actual field name during SQL queries or other
     339             :  * field name dependent API calls.
     340             :  *
     341             :  * This function is the same as the CPP method
     342             :  * OGRFieldDefn::SetAlternativeName().
     343             :  *
     344             :  * Note that once a OGRFieldDefn has been added to a layer definition with
     345             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
     346             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
     347             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
     348             :  * OGRFieldDefn, for drivers that support AlterFieldDefn.
     349             :  *
     350             :  * @param hDefn handle to the field definition to apply the new alternative name
     351             :  * to.
     352             :  * @param pszAlternativeName the new alternative name to apply.
     353             :  *
     354             :  * @since GDAL 3.2
     355             :  */
     356             : 
     357          19 : void OGR_Fld_SetAlternativeName(OGRFieldDefnH hDefn,
     358             :                                 const char *pszAlternativeName)
     359             : 
     360             : {
     361          19 :     OGRFieldDefn::FromHandle(hDefn)->SetAlternativeName(pszAlternativeName);
     362          19 : }
     363             : 
     364             : /************************************************************************/
     365             : /*                             GetAlternativeNameRef()                  */
     366             : /************************************************************************/
     367             : 
     368             : /**
     369             :  * \fn const char *OGRFieldDefn::GetAlternativeNameRef();
     370             :  *
     371             :  * \brief Fetch the alternative name (or "alias") for this field.
     372             :  *
     373             :  * The alternative name is an optional attribute for a field which can provide
     374             :  * a more user-friendly, descriptive name of a field which is not subject to
     375             :  * the usual naming constraints defined by the data provider.
     376             :  *
     377             :  * This is a metadata style attribute only: the alternative name cannot
     378             :  * be used in place of the actual field name during SQL queries or other
     379             :  * field name dependent API calls.
     380             :  *
     381             :  * This method is the same as the C function OGR_Fld_GetAlternativeNameRef().
     382             :  *
     383             :  * @return pointer to an internal alternative name string that should not be
     384             :  * freed or modified.
     385             :  *
     386             :  * @since GDAL 3.2
     387             :  */
     388             : 
     389             : /************************************************************************/
     390             : /*                         OGR_Fld_GetAlternativeNameRef()              */
     391             : /************************************************************************/
     392             : /**
     393             :  * \brief Fetch the alternative name (or "alias") for this field.
     394             :  *
     395             :  * The alternative name is an optional attribute for a field which can provide
     396             :  * a more user-friendly, descriptive name of a field which is not subject to
     397             :  * the usual naming constraints defined by the data provider.
     398             :  *
     399             :  * This is a metadata style attribute only: the alternative name cannot
     400             :  * be used in place of the actual field name during SQL queries or other
     401             :  * field name dependent API calls.
     402             :  *
     403             :  * This function is the same as the CPP method
     404             :  * OGRFieldDefn::GetAlternativeNameRef().
     405             :  *
     406             :  * @param hDefn handle to the field definition.
     407             :  * @return the alternative name of the field definition.
     408             :  *
     409             :  * @since GDAL 3.2
     410             :  */
     411             : 
     412          60 : const char *OGR_Fld_GetAlternativeNameRef(OGRFieldDefnH hDefn)
     413             : 
     414             : {
     415             : 
     416             : #ifdef OGRAPISPY_ENABLED
     417          60 :     if (bOGRAPISpyEnabled)
     418           0 :         OGRAPISpy_Fld_GetXXXX(hDefn, "GetAlternativeNameRef");
     419             : #endif
     420             : 
     421          60 :     return OGRFieldDefn::FromHandle(hDefn)->GetAlternativeNameRef();
     422             : }
     423             : 
     424             : /************************************************************************/
     425             : /*                              GetType()                               */
     426             : /************************************************************************/
     427             : 
     428             : /**
     429             :  * \fn OGRFieldType OGRFieldDefn::GetType() const;
     430             :  *
     431             :  * \brief Fetch type of this field.
     432             :  *
     433             :  * This method is the same as the C function OGR_Fld_GetType().
     434             :  *
     435             :  * @return field type.
     436             :  */
     437             : 
     438             : /************************************************************************/
     439             : /*                          OGR_Fld_GetType()                           */
     440             : /************************************************************************/
     441             : /**
     442             :  * \brief Fetch type of this field.
     443             :  *
     444             :  * This function is the same as the CPP method OGRFieldDefn::GetType().
     445             :  *
     446             :  * @param hDefn handle to the field definition to get type from.
     447             :  * @return field type.
     448             :  */
     449             : 
     450      105926 : OGRFieldType OGR_Fld_GetType(OGRFieldDefnH hDefn)
     451             : 
     452             : {
     453             : 
     454             : #ifdef OGRAPISPY_ENABLED
     455      105926 :     if (bOGRAPISpyEnabled)
     456           2 :         OGRAPISpy_Fld_GetXXXX(hDefn, "GetType");
     457             : #endif
     458             : 
     459      105926 :     return OGRFieldDefn::FromHandle(hDefn)->GetType();
     460             : }
     461             : 
     462             : /************************************************************************/
     463             : /*                              SetType()                               */
     464             : /************************************************************************/
     465             : 
     466             : /**
     467             :  * \brief Set the type of this field.
     468             :  * This should never be done to an OGRFieldDefn
     469             :  * that is already part of an OGRFeatureDefn.
     470             :  *
     471             :  * This method is the same as the C function OGR_Fld_SetType().
     472             :  *
     473             :  * Note that once a OGRFieldDefn has been added to a layer definition with
     474             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
     475             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
     476             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
     477             :  * OGRFieldDefn, for drivers that support AlterFieldDefn.
     478             :  *
     479             :  * @param eTypeIn the new field type.
     480             :  */
     481             : 
     482      274700 : void OGRFieldDefn::SetType(OGRFieldType eTypeIn)
     483             : {
     484      274700 :     if (m_bSealed)
     485             :     {
     486           1 :         CPLError(CE_Failure, CPLE_AppDefined,
     487             :                  "OGRFieldDefn::SetType() not allowed on a sealed object");
     488           1 :         return;
     489             :     }
     490      274699 :     if (!OGR_AreTypeSubTypeCompatible(eTypeIn, eSubType))
     491             :     {
     492           0 :         CPLError(CE_Warning, CPLE_AppDefined,
     493             :                  "Type and subtype of field definition are not compatible. "
     494             :                  "Resetting to OFSTNone");
     495           0 :         eSubType = OFSTNone;
     496             :     }
     497      274699 :     eType = eTypeIn;
     498             : }
     499             : 
     500             : /************************************************************************/
     501             : /*                          OGR_Fld_SetType()                           */
     502             : /************************************************************************/
     503             : /**
     504             :  * \brief Set the type of this field.
     505             :  * This should never be done to an OGRFieldDefn
     506             :  * that is already part of an OGRFeatureDefn.
     507             :  *
     508             :  * This function is the same as the CPP method OGRFieldDefn::SetType().
     509             :  *
     510             :  * Note that once a OGRFieldDefn has been added to a layer definition with
     511             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
     512             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
     513             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
     514             :  * OGRFieldDefn, for drivers that support AlterFieldDefn.
     515             :  *
     516             :  * @param hDefn handle to the field definition to set type to.
     517             :  * @param eType the new field type.
     518             :  */
     519             : 
     520           0 : void OGR_Fld_SetType(OGRFieldDefnH hDefn, OGRFieldType eType)
     521             : 
     522             : {
     523           0 :     OGRFieldDefn::FromHandle(hDefn)->SetType(eType);
     524           0 : }
     525             : 
     526             : /************************************************************************/
     527             : /*                             GetSubType()                             */
     528             : /************************************************************************/
     529             : 
     530             : /**
     531             :  * \fn OGRFieldSubType OGRFieldDefn::GetSubType() const;
     532             :  *
     533             :  * \brief Fetch subtype of this field.
     534             :  *
     535             :  * This method is the same as the C function OGR_Fld_GetSubType().
     536             :  *
     537             :  * @return field subtype.
     538             :  * @since GDAL 2.0
     539             :  */
     540             : 
     541             : /************************************************************************/
     542             : /*                         OGR_Fld_GetSubType()                         */
     543             : /************************************************************************/
     544             : /**
     545             :  * \brief Fetch subtype of this field.
     546             :  *
     547             :  * This function is the same as the CPP method OGRFieldDefn::GetSubType().
     548             :  *
     549             :  * @param hDefn handle to the field definition to get subtype from.
     550             :  * @return field subtype.
     551             :  * @since GDAL 2.0
     552             :  */
     553             : 
     554       88544 : OGRFieldSubType OGR_Fld_GetSubType(OGRFieldDefnH hDefn)
     555             : 
     556             : {
     557             : 
     558             : #ifdef OGRAPISPY_ENABLED
     559       88544 :     if (bOGRAPISpyEnabled)
     560           2 :         OGRAPISpy_Fld_GetXXXX(hDefn, "GetSubType");
     561             : #endif
     562             : 
     563       88544 :     return OGRFieldDefn::FromHandle(hDefn)->GetSubType();
     564             : }
     565             : 
     566             : /************************************************************************/
     567             : /*                             SetSubType()                             */
     568             : /************************************************************************/
     569             : 
     570             : /**
     571             :  * \brief Set the subtype of this field.
     572             :  * This should never be done to an OGRFieldDefn
     573             :  * that is already part of an OGRFeatureDefn.
     574             :  *
     575             :  * This method is the same as the C function OGR_Fld_SetSubType().
     576             :  *
     577             :  * Note that once a OGRFieldDefn has been added to a layer definition with
     578             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
     579             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
     580             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
     581             :  * OGRFieldDefn, for drivers that support AlterFieldDefn.
     582             :  *
     583             :  * @param eSubTypeIn the new field subtype.
     584             :  * @since GDAL 2.0
     585             :  */
     586      311522 : void OGRFieldDefn::SetSubType(OGRFieldSubType eSubTypeIn)
     587             : {
     588      311522 :     if (m_bSealed)
     589             :     {
     590           1 :         CPLError(CE_Failure, CPLE_AppDefined,
     591             :                  "OGRFieldDefn::SetSubType() not allowed on a sealed object");
     592           1 :         return;
     593             :     }
     594      311521 :     if (!OGR_AreTypeSubTypeCompatible(eType, eSubTypeIn))
     595             :     {
     596           3 :         CPLError(CE_Warning, CPLE_AppDefined,
     597             :                  "Type and subtype of field definition are not compatible. "
     598             :                  "Resetting to OFSTNone");
     599           3 :         eSubType = OFSTNone;
     600             :     }
     601             :     else
     602             :     {
     603      311518 :         eSubType = eSubTypeIn;
     604             :     }
     605             : }
     606             : 
     607             : /************************************************************************/
     608             : /*                         OGR_Fld_SetSubType()                         */
     609             : /************************************************************************/
     610             : /**
     611             :  * \brief Set the subtype of this field.
     612             :  * This should never be done to an OGRFieldDefn
     613             :  * that is already part of an OGRFeatureDefn.
     614             :  *
     615             :  * This function is the same as the CPP method OGRFieldDefn::SetSubType().
     616             :  *
     617             :  * Note that once a OGRFieldDefn has been added to a layer definition with
     618             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
     619             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
     620             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
     621             :  * OGRFieldDefn, for drivers that support AlterFieldDefn.
     622             :  *
     623             :  * @param hDefn handle to the field definition to set type to.
     624             :  * @param eSubType the new field subtype.
     625             :  * @since GDAL 2.0
     626             :  */
     627             : 
     628         555 : void OGR_Fld_SetSubType(OGRFieldDefnH hDefn, OGRFieldSubType eSubType)
     629             : 
     630             : {
     631         555 :     OGRFieldDefn::FromHandle(hDefn)->SetSubType(eSubType);
     632         555 : }
     633             : 
     634             : /************************************************************************/
     635             : /*                             SetDefault()                             */
     636             : /************************************************************************/
     637             : 
     638             : /**
     639             :  * \brief Set default field value.
     640             :  *
     641             :  * The default field value is taken into account by drivers (generally those
     642             :  * with a SQL interface) that support it at field creation time. OGR will
     643             :  * generally not automatically set the default field value to null fields by
     644             :  * itself when calling OGRFeature::CreateFeature() / OGRFeature::SetFeature(),
     645             :  * but will let the low-level layers to do the job. So retrieving the feature
     646             :  * from the layer is recommended.
     647             :  *
     648             :  * The accepted values are NULL, a numeric value, a literal value enclosed
     649             :  * between single quote characters (and inner single quote characters escaped by
     650             :  * repetition of the single quote character),
     651             :  * CURRENT_TIMESTAMP, CURRENT_TIME, CURRENT_DATE or
     652             :  * a driver specific expression (that might be ignored by other drivers).
     653             :  * For a datetime literal value, format should be 'YYYY/MM/DD HH:MM:SS[.sss]'
     654             :  * (considered as UTC time).
     655             :  *
     656             :  * Drivers that support writing DEFAULT clauses will advertise the
     657             :  * GDAL_DCAP_DEFAULT_FIELDS driver metadata item.
     658             :  *
     659             :  * This function is the same as the C function OGR_Fld_SetDefault().
     660             :  *
     661             :  * Note that once a OGRFieldDefn has been added to a layer definition with
     662             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
     663             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
     664             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
     665             :  * OGRFieldDefn, for drivers that support AlterFieldDefn.
     666             :  *
     667             :  * @param pszDefaultIn new default field value or NULL pointer.
     668             :  *
     669             :  * @since GDAL 2.0
     670             :  */
     671             : 
     672      726999 : void OGRFieldDefn::SetDefault(const char *pszDefaultIn)
     673             : 
     674             : {
     675      726999 :     if (m_bSealed)
     676             :     {
     677           1 :         CPLError(CE_Failure, CPLE_AppDefined,
     678             :                  "OGRFieldDefn::SetDefault() not allowed on a sealed object");
     679           1 :         return;
     680             :     }
     681      726998 :     CPLFree(pszDefault);
     682      726998 :     pszDefault = nullptr;
     683             : 
     684      726998 :     if (pszDefaultIn && pszDefaultIn[0] == '\'' &&
     685        1672 :         pszDefaultIn[strlen(pszDefaultIn) - 1] == '\'')
     686             :     {
     687        1671 :         const char *pszPtr = pszDefaultIn + 1;  // Used after for.
     688       16182 :         for (; *pszPtr != '\0'; pszPtr++)
     689             :         {
     690       16181 :             if (*pszPtr == '\'')
     691             :             {
     692        1722 :                 if (pszPtr[1] == '\0')
     693        1669 :                     break;
     694          53 :                 if (pszPtr[1] != '\'')
     695             :                 {
     696           1 :                     CPLError(CE_Failure, CPLE_AppDefined,
     697             :                              "Incorrectly quoted string literal");
     698           1 :                     return;
     699             :                 }
     700          52 :                 pszPtr++;
     701             :             }
     702             :         }
     703        1670 :         if (*pszPtr == '\0')
     704             :         {
     705           1 :             CPLError(CE_Failure, CPLE_AppDefined,
     706             :                      "Incorrectly quoted string literal");
     707           1 :             return;
     708             :         }
     709             :     }
     710             : 
     711      726996 :     pszDefault = pszDefaultIn ? CPLStrdup(pszDefaultIn) : nullptr;
     712             : }
     713             : 
     714             : /************************************************************************/
     715             : /*                         OGR_Fld_SetDefault()                         */
     716             : /************************************************************************/
     717             : 
     718             : /**
     719             :  * \brief Set default field value.
     720             :  *
     721             :  * The default field value is taken into account by drivers (generally those
     722             :  * with a SQL interface) that support it at field creation time. OGR will
     723             :  * generally not automatically set the default field value to null fields by
     724             :  * itself when calling OGRFeature::CreateFeature() / OGRFeature::SetFeature(),
     725             :  * but will let the low-level layers to do the job. So retrieving the feature
     726             :  * from the layer is recommended.
     727             :  *
     728             :  * The accepted values are NULL, a numeric value, a literal value enclosed
     729             :  * between single quote characters (and inner single quote characters escaped by
     730             :  * repetition of the single quote character),
     731             :  * CURRENT_TIMESTAMP, CURRENT_TIME, CURRENT_DATE or
     732             :  * a driver specific expression (that might be ignored by other drivers).
     733             :  * For a datetime literal value, format should be 'YYYY/MM/DD HH:MM:SS[.sss]'
     734             :  * (considered as UTC time).
     735             :  *
     736             :  * Drivers that support writing DEFAULT clauses will advertise the
     737             :  * GDAL_DCAP_DEFAULT_FIELDS driver metadata item.
     738             :  *
     739             :  * This function is the same as the C++ method OGRFieldDefn::SetDefault().
     740             :  *
     741             :  * Note that once a OGRFieldDefn has been added to a layer definition with
     742             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
     743             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
     744             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
     745             :  * OGRFieldDefn, for drivers that support AlterFieldDefn.
     746             :  *
     747             :  * @param hDefn handle to the field definition.
     748             :  * @param pszDefault new default field value or NULL pointer.
     749             :  *
     750             :  * @since GDAL 2.0
     751             :  */
     752             : 
     753         154 : void CPL_DLL OGR_Fld_SetDefault(OGRFieldDefnH hDefn, const char *pszDefault)
     754             : {
     755         154 :     OGRFieldDefn::FromHandle(hDefn)->SetDefault(pszDefault);
     756         154 : }
     757             : 
     758             : /************************************************************************/
     759             : /*                             GetDefault()                             */
     760             : /************************************************************************/
     761             : 
     762             : /**
     763             :  * \brief Get default field value.
     764             :  *
     765             :  * This function is the same as the C function OGR_Fld_GetDefault().
     766             :  *
     767             :  * @return default field value or NULL.
     768             :  * @since GDAL 2.0
     769             :  */
     770             : 
     771      760098 : const char *OGRFieldDefn::GetDefault() const
     772             : 
     773             : {
     774      760098 :     return pszDefault;
     775             : }
     776             : 
     777             : /************************************************************************/
     778             : /*                         OGR_Fld_GetDefault()                         */
     779             : /************************************************************************/
     780             : 
     781             : /**
     782             :  * \brief Get default field value.
     783             :  *
     784             :  * This function is the same as the C++ method OGRFieldDefn::GetDefault().
     785             :  *
     786             :  * @param hDefn handle to the field definition.
     787             :  * @return default field value or NULL.
     788             :  * @since GDAL 2.0
     789             :  */
     790             : 
     791         141 : const char *OGR_Fld_GetDefault(OGRFieldDefnH hDefn)
     792             : {
     793         141 :     return OGRFieldDefn::FromHandle(hDefn)->GetDefault();
     794             : }
     795             : 
     796             : /************************************************************************/
     797             : /*                        IsDefaultDriverSpecific()                     */
     798             : /************************************************************************/
     799             : 
     800             : /**
     801             :  * \brief Returns whether the default value is driver specific.
     802             :  *
     803             :  * Driver specific default values are those that are *not* NULL, a
     804             :  * numeric value, a literal value enclosed between single quote
     805             :  * characters, CURRENT_TIMESTAMP, CURRENT_TIME, CURRENT_DATE or
     806             :  * datetime literal value.
     807             :  *
     808             :  * This method is the same as the C function
     809             :  * OGR_Fld_IsDefaultDriverSpecific().
     810             :  *
     811             :  * @return TRUE if the default value is driver specific.
     812             :  * @since GDAL 2.0
     813             :  */
     814             : 
     815         216 : int OGRFieldDefn::IsDefaultDriverSpecific() const
     816             : {
     817         216 :     if (pszDefault == nullptr)
     818           1 :         return FALSE;
     819             : 
     820         215 :     if (EQUAL(pszDefault, "NULL") || EQUAL(pszDefault, "CURRENT_TIMESTAMP") ||
     821         195 :         EQUAL(pszDefault, "CURRENT_TIME") || EQUAL(pszDefault, "CURRENT_DATE"))
     822          31 :         return FALSE;
     823             : 
     824         184 :     if (pszDefault[0] == '\'' && pszDefault[strlen(pszDefault) - 1] == '\'')
     825          80 :         return FALSE;
     826             : 
     827         104 :     char *pszEnd = nullptr;
     828         104 :     CPLStrtod(pszDefault, &pszEnd);
     829         104 :     if (*pszEnd == '\0')
     830          73 :         return FALSE;
     831             : 
     832          31 :     return TRUE;
     833             : }
     834             : 
     835             : /************************************************************************/
     836             : /*                     OGR_Fld_IsDefaultDriverSpecific()                */
     837             : /************************************************************************/
     838             : 
     839             : /**
     840             :  * \brief Returns whether the default value is driver specific.
     841             :  *
     842             :  * Driver specific default values are those that are *not* NULL, a
     843             :  * numeric value, a literal value enclosed between single quote
     844             :  * characters, CURRENT_TIMESTAMP, CURRENT_TIME, CURRENT_DATE or
     845             :  * datetime literal value.
     846             :  *
     847             :  * This function is the same as the C++ method
     848             :  * OGRFieldDefn::IsDefaultDriverSpecific().
     849             :  *
     850             :  * @param hDefn handle to the field definition
     851             :  * @return TRUE if the default value is driver specific.
     852             :  * @since GDAL 2.0
     853             :  */
     854             : 
     855           3 : int OGR_Fld_IsDefaultDriverSpecific(OGRFieldDefnH hDefn)
     856             : {
     857           3 :     return OGRFieldDefn::FromHandle(hDefn)->IsDefaultDriverSpecific();
     858             : }
     859             : 
     860             : /************************************************************************/
     861             : /*                          GetFieldTypeName()                          */
     862             : /************************************************************************/
     863             : 
     864             : /**
     865             :  * \brief Fetch human readable name for a field type.
     866             :  *
     867             :  * This static method is the same as the C function OGR_GetFieldTypeName().
     868             :  *
     869             :  * @param eType the field type to get name for.
     870             :  *
     871             :  * @return pointer to an internal static name string. It should not be
     872             :  * modified or freed.
     873             :  */
     874             : 
     875       14077 : const char *OGRFieldDefn::GetFieldTypeName(OGRFieldType eType)
     876             : 
     877             : {
     878       14077 :     switch (eType)
     879             :     {
     880        2796 :         case OFTInteger:
     881        2796 :             return "Integer";
     882             : 
     883         975 :         case OFTInteger64:
     884         975 :             return "Integer64";
     885             : 
     886        1256 :         case OFTReal:
     887        1256 :             return "Real";
     888             : 
     889        5615 :         case OFTString:
     890        5615 :             return "String";
     891             : 
     892         873 :         case OFTIntegerList:
     893         873 :             return "IntegerList";
     894             : 
     895         209 :         case OFTInteger64List:
     896         209 :             return "Integer64List";
     897             : 
     898         628 :         case OFTRealList:
     899         628 :             return "RealList";
     900             : 
     901         343 :         case OFTStringList:
     902         343 :             return "StringList";
     903             : 
     904         244 :         case OFTBinary:
     905         244 :             return "Binary";
     906             : 
     907         245 :         case OFTDate:
     908         245 :             return "Date";
     909             : 
     910         192 :         case OFTTime:
     911         192 :             return "Time";
     912             : 
     913         431 :         case OFTDateTime:
     914         431 :             return "DateTime";
     915             : 
     916         270 :         case OFTWideString:
     917             :         case OFTWideStringList:
     918         270 :             break;
     919             :     }
     920             : 
     921         270 :     return "(unknown)";
     922             : }
     923             : 
     924             : /************************************************************************/
     925             : /*                          GetFieldTypeByName()                        */
     926             : /************************************************************************/
     927             : /**
     928             :  * \brief Fetch field type by name.
     929             :  * @param pszName the name of the field type.
     930             :  * @return the field type or OFTString if there is no match with known type names.
     931             :  * @since GDAL 3.11.0
     932             :  */
     933          52 : OGRFieldType OGRFieldDefn::GetFieldTypeByName(const char *pszName)
     934             : {
     935          52 :     if (EQUAL(pszName, "integer"))
     936          12 :         return OFTInteger;
     937          40 :     if (EQUAL(pszName, "integer64"))
     938           1 :         return OFTInteger64;
     939          39 :     if (EQUAL(pszName, "real"))
     940          19 :         return OFTReal;
     941          20 :     if (EQUAL(pszName, "string"))
     942           8 :         return OFTString;
     943          12 :     if (EQUAL(pszName, "integerlist"))
     944           1 :         return OFTIntegerList;
     945          11 :     if (EQUAL(pszName, "integer64list"))
     946           0 :         return OFTInteger64List;
     947          11 :     if (EQUAL(pszName, "reallist"))
     948           1 :         return OFTRealList;
     949          10 :     if (EQUAL(pszName, "stringlist"))
     950           1 :         return OFTStringList;
     951           9 :     if (EQUAL(pszName, "binary"))
     952           1 :         return OFTBinary;
     953           8 :     if (EQUAL(pszName, "date"))
     954           1 :         return OFTDate;
     955           7 :     if (EQUAL(pszName, "time"))
     956           1 :         return OFTTime;
     957           6 :     if (EQUAL(pszName, "datetime"))
     958           1 :         return OFTDateTime;
     959             : 
     960           5 :     return OFTString;
     961             : }
     962             : 
     963             : /************************************************************************/
     964             : /*                       OGR_GetFieldTypeByName()                       */
     965             : /************************************************************************/
     966             : /**
     967             :  * \brief Fetch field type by name.
     968             :  *
     969             :  * This function is the same as the CPP method
     970             :  * OGRFieldDefn::GetFieldTypeByName().
     971             :  *
     972             :  * @param pszName the name of the field type.
     973             :  * @return the field type or OFTString if there is no match with known type names.
     974             :  * @since GDAL 3.9.4
     975             :  */
     976           0 : OGRFieldType OGR_GetFieldTypeByName(const char *pszName)
     977             : {
     978           0 :     return OGRFieldDefn::GetFieldTypeByName(pszName);
     979             : }
     980             : 
     981             : /************************************************************************/
     982             : /*                        OGR_GetFieldTypeName()                        */
     983             : /************************************************************************/
     984             : /**
     985             :  * \brief Fetch human readable name for a field type.
     986             :  *
     987             :  * This function is the same as the CPP method
     988             :  * OGRFieldDefn::GetFieldTypeName().
     989             :  *
     990             :  * @param eType the field type to get name for.
     991             :  * @return the name.
     992             :  */
     993             : 
     994        2206 : const char *OGR_GetFieldTypeName(OGRFieldType eType)
     995             : 
     996             : {
     997        2206 :     return OGRFieldDefn::GetFieldTypeName(eType);
     998             : }
     999             : 
    1000             : /************************************************************************/
    1001             : /*                        GetFieldSubTypeName()                         */
    1002             : /************************************************************************/
    1003             : 
    1004             : /**
    1005             :  * \brief Fetch human readable name for a field subtype.
    1006             :  *
    1007             :  * This static method is the same as the C function OGR_GetFieldSubTypeName().
    1008             :  *
    1009             :  * @param eSubType the field subtype to get name for.
    1010             :  *
    1011             :  * @return pointer to an internal static name string. It should not be
    1012             :  * modified or freed.
    1013             :  *
    1014             :  * @since GDAL 2.0
    1015             :  */
    1016             : 
    1017        3324 : const char *OGRFieldDefn::GetFieldSubTypeName(OGRFieldSubType eSubType)
    1018             : 
    1019             : {
    1020        3324 :     switch (eSubType)
    1021             :     {
    1022        1140 :         case OFSTNone:
    1023        1140 :             break;
    1024             : 
    1025         556 :         case OFSTBoolean:
    1026         556 :             return "Boolean";
    1027             : 
    1028         899 :         case OFSTInt16:
    1029         899 :             return "Int16";
    1030             : 
    1031         211 :         case OFSTFloat32:
    1032         211 :             return "Float32";
    1033             : 
    1034         511 :         case OFSTJSON:
    1035         511 :             return "JSON";
    1036             : 
    1037           7 :         case OFSTUUID:
    1038           7 :             return "UUID";
    1039             :     }
    1040        1140 :     return "None";
    1041             : }
    1042             : 
    1043             : /************************************************************************/
    1044             : /*                        GetFieldSubTypeByName()                       */
    1045             : /************************************************************************/
    1046             : /**
    1047             :  * \brief Fetch field subtype by name.
    1048             :  * @param pszName the name of the field subtype.
    1049             :  * @return the field subtype.
    1050             :  * @since GDAL 3.11.0
    1051             :  */
    1052          24 : OGRFieldSubType OGRFieldDefn::GetFieldSubTypeByName(const char *pszName)
    1053             : {
    1054          24 :     if (EQUAL(pszName, "boolean"))
    1055           6 :         return OFSTBoolean;
    1056          18 :     if (EQUAL(pszName, "int16"))
    1057           6 :         return OFSTInt16;
    1058          12 :     if (EQUAL(pszName, "float32"))
    1059           1 :         return OFSTFloat32;
    1060          11 :     if (EQUAL(pszName, "json"))
    1061           4 :         return OFSTJSON;
    1062           7 :     if (EQUAL(pszName, "uuid"))
    1063           6 :         return OFSTUUID;
    1064             : 
    1065           1 :     return OFSTNone;
    1066             : }
    1067             : 
    1068             : /************************************************************************/
    1069             : /*                       OGR_GetFieldSubTypeByName()                    */
    1070             : /************************************************************************/
    1071             : /**
    1072             :  * \brief Fetch field subtype by name.
    1073             :  *
    1074             :  * This function is the same as the CPP method
    1075             :  * OGRFieldDefn::GetFieldSubTypeByName().
    1076             :  *
    1077             :  * @param pszName the name of the field subtype.
    1078             :  * @return the field subtype.
    1079             :  * @since GDAL 3.11.0
    1080             :  */
    1081           0 : OGRFieldSubType OGR_GetFieldSubTypeByName(const char *pszName)
    1082             : {
    1083           0 :     return OGRFieldDefn::GetFieldSubTypeByName(pszName);
    1084             : }
    1085             : 
    1086             : /************************************************************************/
    1087             : /*                       OGR_GetFieldSubTypeName()                      */
    1088             : /************************************************************************/
    1089             : /**
    1090             :  * \brief Fetch human readable name for a field subtype.
    1091             :  *
    1092             :  * This function is the same as the CPP method
    1093             :  * OGRFieldDefn::GetFieldSubTypeName().
    1094             :  *
    1095             :  * @param eSubType the field subtype to get name for.
    1096             :  * @return the name.
    1097             :  *
    1098             :  * @since GDAL 2.0
    1099             :  */
    1100             : 
    1101        2281 : const char *OGR_GetFieldSubTypeName(OGRFieldSubType eSubType)
    1102             : 
    1103             : {
    1104        2281 :     return OGRFieldDefn::GetFieldSubTypeName(eSubType);
    1105             : }
    1106             : 
    1107             : /************************************************************************/
    1108             : /*                       OGR_IsValidTypeAndSubType()                    */
    1109             : /************************************************************************/
    1110             : /**
    1111             :  * \brief Return if type and subtype are compatible
    1112             :  *
    1113             :  * @param eType the field type.
    1114             :  * @param eSubType the field subtype.
    1115             :  * @return TRUE if type and subtype are compatible
    1116             :  *
    1117             :  * @since GDAL 2.0
    1118             :  */
    1119             : 
    1120      586226 : int OGR_AreTypeSubTypeCompatible(OGRFieldType eType, OGRFieldSubType eSubType)
    1121             : {
    1122      586226 :     if (eSubType == OFSTNone)
    1123      567867 :         return TRUE;
    1124       18359 :     if (eSubType == OFSTBoolean || eSubType == OFSTInt16)
    1125        6620 :         return eType == OFTInteger || eType == OFTIntegerList;
    1126       11739 :     if (eSubType == OFSTFloat32)
    1127        3164 :         return eType == OFTReal || eType == OFTRealList;
    1128        8575 :     if (eSubType == OFSTJSON)
    1129        8562 :         return eType == OFTString;
    1130          13 :     if (eSubType == OFSTUUID)
    1131          13 :         return eType == OFTString;
    1132           0 :     return FALSE;
    1133             : }
    1134             : 
    1135             : /************************************************************************/
    1136             : /*                             GetJustify()                             */
    1137             : /************************************************************************/
    1138             : 
    1139             : /**
    1140             :  * \fn OGRJustification OGRFieldDefn::GetJustify() const;
    1141             :  *
    1142             :  * \brief Get the justification for this field.
    1143             :  *
    1144             :  * Note: no driver is know to use the concept of field justification.
    1145             :  *
    1146             :  * This method is the same as the C function OGR_Fld_GetJustify().
    1147             :  *
    1148             :  * @return the justification.
    1149             :  */
    1150             : 
    1151             : /************************************************************************/
    1152             : /*                         OGR_Fld_GetJustify()                         */
    1153             : /************************************************************************/
    1154             : /**
    1155             :  * \brief Get the justification for this field.
    1156             :  *
    1157             :  * This function is the same as the CPP method OGRFieldDefn::GetJustify().
    1158             :  *
    1159             :  * Note: no driver is know to use the concept of field justification.
    1160             :  *
    1161             :  * @param hDefn handle to the field definition to get justification from.
    1162             :  * @return the justification.
    1163             :  */
    1164             : 
    1165           0 : OGRJustification OGR_Fld_GetJustify(OGRFieldDefnH hDefn)
    1166             : 
    1167             : {
    1168           0 :     return OGRFieldDefn::FromHandle(hDefn)->GetJustify();
    1169             : }
    1170             : 
    1171             : /************************************************************************/
    1172             : /*                             SetJustify()                             */
    1173             : /************************************************************************/
    1174             : 
    1175             : /**
    1176             :  * \fn void OGRFieldDefn::SetJustify( OGRJustification eJustify );
    1177             :  *
    1178             :  * \brief Set the justification for this field.
    1179             :  *
    1180             :  * Note: no driver is know to use the concept of field justification.
    1181             :  *
    1182             :  * This method is the same as the C function OGR_Fld_SetJustify().
    1183             :  *
    1184             :  * @param eJustify the new justification.
    1185             :  */
    1186             : 
    1187             : /************************************************************************/
    1188             : /*                         OGR_Fld_SetJustify()                         */
    1189             : /************************************************************************/
    1190             : /**
    1191             :  * \brief Set the justification for this field.
    1192             :  *
    1193             :  * Note: no driver is know to use the concept of field justification.
    1194             :  *
    1195             :  * This function is the same as the CPP method OGRFieldDefn::SetJustify().
    1196             :  *
    1197             :  * @param hDefn handle to the field definition to set justification to.
    1198             :  * @param eJustify the new justification.
    1199             :  */
    1200             : 
    1201           0 : void OGR_Fld_SetJustify(OGRFieldDefnH hDefn, OGRJustification eJustify)
    1202             : 
    1203             : {
    1204           0 :     OGRFieldDefn::FromHandle(hDefn)->SetJustify(eJustify);
    1205           0 : }
    1206             : 
    1207             : /************************************************************************/
    1208             : /*                              GetWidth()                              */
    1209             : /************************************************************************/
    1210             : 
    1211             : /**
    1212             :  * \fn int OGRFieldDefn::GetWidth() const;
    1213             :  *
    1214             :  * \brief Get the formatting width for this field.
    1215             :  *
    1216             :  * This method is the same as the C function OGR_Fld_GetWidth().
    1217             :  *
    1218             :  * @return the width, zero means no specified width.
    1219             :  */
    1220             : 
    1221             : /************************************************************************/
    1222             : /*                          OGR_Fld_GetWidth()                          */
    1223             : /************************************************************************/
    1224             : /**
    1225             :  * \brief Get the formatting width for this field.
    1226             :  *
    1227             :  * This function is the same as the CPP method OGRFieldDefn::GetWidth().
    1228             :  *
    1229             :  * @param hDefn handle to the field definition to get width from.
    1230             :  * @return the width, zero means no specified width.
    1231             :  */
    1232             : 
    1233        2763 : int OGR_Fld_GetWidth(OGRFieldDefnH hDefn)
    1234             : 
    1235             : {
    1236        2763 :     return OGRFieldDefn::FromHandle(hDefn)->GetWidth();
    1237             : }
    1238             : 
    1239             : /************************************************************************/
    1240             : /*                              SetWidth()                              */
    1241             : /************************************************************************/
    1242             : 
    1243             : /**
    1244             :  * \brief Set the formatting width for this field in characters.
    1245             :  *
    1246             :  * This method is the same as the C function OGR_Fld_SetWidth().
    1247             :  *
    1248             :  * Note that once a OGRFieldDefn has been added to a layer definition with
    1249             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
    1250             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
    1251             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
    1252             :  * OGRFieldDefn, for drivers that support AlterFieldDefn.
    1253             :  *
    1254             :  * @param nWidthIn the new width.
    1255             :  */
    1256      393056 : void OGRFieldDefn::SetWidth(int nWidthIn)
    1257             : {
    1258      393056 :     if (m_bSealed)
    1259             :     {
    1260           1 :         CPLError(CE_Failure, CPLE_AppDefined,
    1261             :                  "OGRFieldDefn::SetWidth() not allowed on a sealed object");
    1262           1 :         return;
    1263             :     }
    1264      393055 :     nWidth = MAX(0, nWidthIn);
    1265             : }
    1266             : 
    1267             : /************************************************************************/
    1268             : /*                          OGR_Fld_SetWidth()                          */
    1269             : /************************************************************************/
    1270             : /**
    1271             :  * \brief Set the formatting width for this field in characters.
    1272             :  *
    1273             :  * This function is the same as the CPP method OGRFieldDefn::SetWidth().
    1274             :  *
    1275             :  * Note that once a OGRFieldDefn has been added to a layer definition with
    1276             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
    1277             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
    1278             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
    1279             :  * OGRFieldDefn, for drivers that support AlterFieldDefn.
    1280             :  *
    1281             :  * @param hDefn handle to the field definition to set width to.
    1282             :  * @param nNewWidth the new width.
    1283             :  */
    1284             : 
    1285         346 : void OGR_Fld_SetWidth(OGRFieldDefnH hDefn, int nNewWidth)
    1286             : 
    1287             : {
    1288         346 :     OGRFieldDefn::FromHandle(hDefn)->SetWidth(nNewWidth);
    1289         346 : }
    1290             : 
    1291             : /************************************************************************/
    1292             : /*                            GetPrecision()                            */
    1293             : /************************************************************************/
    1294             : 
    1295             : /**
    1296             :  * \fn int OGRFieldDefn::GetPrecision() const;
    1297             :  *
    1298             :  * \brief Get the formatting precision for this field.
    1299             :  * This should normally be
    1300             :  * zero for fields of types other than OFTReal.
    1301             :  *
    1302             :  * This method is the same as the C function OGR_Fld_GetPrecision().
    1303             :  *
    1304             :  * @return the precision.
    1305             :  */
    1306             : 
    1307             : /************************************************************************/
    1308             : /*                        OGR_Fld_GetPrecision()                        */
    1309             : /************************************************************************/
    1310             : /**
    1311             :  * \brief Get the formatting precision for this field.
    1312             :  * This should normally be
    1313             :  * zero for fields of types other than OFTReal.
    1314             :  *
    1315             :  * This function is the same as the CPP method OGRFieldDefn::GetPrecision().
    1316             :  *
    1317             :  * @param hDefn handle to the field definition to get precision from.
    1318             :  * @return the precision.
    1319             :  */
    1320             : 
    1321        1636 : int OGR_Fld_GetPrecision(OGRFieldDefnH hDefn)
    1322             : 
    1323             : {
    1324        1636 :     return OGRFieldDefn::FromHandle(hDefn)->GetPrecision();
    1325             : }
    1326             : 
    1327             : /************************************************************************/
    1328             : /*                            SetPrecision()                            */
    1329             : /************************************************************************/
    1330             : 
    1331             : /**
    1332             :  * \brief Set the formatting precision for this field in characters.
    1333             :  *
    1334             :  * This should normally be zero for fields of types other than OFTReal.
    1335             :  *
    1336             :  * This method is the same as the C function OGR_Fld_SetPrecision().
    1337             :  *
    1338             :  * Note that once a OGRFieldDefn has been added to a layer definition with
    1339             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
    1340             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
    1341             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
    1342             :  * OGRFieldDefn, for drivers that support AlterFieldDefn.
    1343             :  *
    1344             :  * @param nPrecisionIn the new precision.
    1345             :  */
    1346      185127 : void OGRFieldDefn::SetPrecision(int nPrecisionIn)
    1347             : {
    1348      185127 :     if (m_bSealed)
    1349             :     {
    1350           1 :         CPLError(CE_Failure, CPLE_AppDefined,
    1351             :                  "OGRFieldDefn::SetPrecision() not allowed on a sealed object");
    1352           1 :         return;
    1353             :     }
    1354      185126 :     nPrecision = nPrecisionIn;
    1355             : }
    1356             : 
    1357             : /************************************************************************/
    1358             : /*                        OGR_Fld_SetPrecision()                        */
    1359             : /************************************************************************/
    1360             : /**
    1361             :  * \brief Set the formatting precision for this field in characters.
    1362             :  *
    1363             :  * This should normally be zero for fields of types other than OFTReal.
    1364             :  *
    1365             :  * This function is the same as the CPP method OGRFieldDefn::SetPrecision().
    1366             :  *
    1367             :  * Note that once a OGRFieldDefn has been added to a layer definition with
    1368             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
    1369             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
    1370             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
    1371             :  * OGRFieldDefn, for drivers that support AlterFieldDefn.
    1372             :  *
    1373             :  * @param hDefn handle to the field definition to set precision to.
    1374             :  * @param nPrecision the new precision.
    1375             :  */
    1376             : 
    1377          27 : void OGR_Fld_SetPrecision(OGRFieldDefnH hDefn, int nPrecision)
    1378             : 
    1379             : {
    1380          27 :     OGRFieldDefn::FromHandle(hDefn)->SetPrecision(nPrecision);
    1381          27 : }
    1382             : 
    1383             : /************************************************************************/
    1384             : /*                            GetTZFlag()                               */
    1385             : /************************************************************************/
    1386             : 
    1387             : /**
    1388             :  * \fn int OGRFieldDefn::GetTZFlag() const;
    1389             :  *
    1390             :  * \brief Get the time zone flag.
    1391             :  *
    1392             :  * Only applies to OFTTime, OFTDate and OFTDateTime fields.
    1393             :  *
    1394             :  * Cf OGR_TZFLAG_UNKNOWN, OGR_TZFLAG_LOCALTIME, OGR_TZFLAG_MIXED_TZ and
    1395             :  * OGR_TZFLAG_UTC
    1396             :  *
    1397             :  * This method is the same as the C function OGR_Fld_GetTZFlag().
    1398             :  *
    1399             :  * @return the time zone flag.
    1400             :  * @since GDAL 3.8
    1401             :  */
    1402             : 
    1403             : /************************************************************************/
    1404             : /*                        OGR_Fld_GetTZFlag()                           */
    1405             : /************************************************************************/
    1406             : /**
    1407             :  * \brief Get the time zone flag.
    1408             :  *
    1409             :  * Only applies to OFTTime, OFTDate and OFTDateTime fields.
    1410             :  *
    1411             :  * Cf OGR_TZFLAG_UNKNOWN, OGR_TZFLAG_LOCALTIME, OGR_TZFLAG_MIXED_TZ and
    1412             :  * OGR_TZFLAG_UTC
    1413             :  *
    1414             :  * @param hDefn handle to the field definition .
    1415             :  * @return the time zone flag.
    1416             :  * @since GDAL 3.8
    1417             :  */
    1418             : 
    1419           0 : int OGR_Fld_GetTZFlag(OGRFieldDefnH hDefn)
    1420             : 
    1421             : {
    1422           0 :     return OGRFieldDefn::FromHandle(hDefn)->GetTZFlag();
    1423             : }
    1424             : 
    1425             : /************************************************************************/
    1426             : /*                             SetTZFlag()                              */
    1427             : /************************************************************************/
    1428             : 
    1429             : /**
    1430             :  * \brief Set the time zone flag.
    1431             :  *
    1432             :  * Only applies to OFTTime, OFTDate and OFTDateTime fields.
    1433             :  *
    1434             :  * Cf OGR_TZFLAG_UNKNOWN, OGR_TZFLAG_LOCALTIME, OGR_TZFLAG_MIXED_TZ and
    1435             :  * OGR_TZFLAG_UTC
    1436             :  *
    1437             :  * This method is the same as the C function OGR_Fld_SetTZFlag().
    1438             :  *
    1439             :  * Note that once a OGRFieldDefn has been added to a layer definition with
    1440             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
    1441             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
    1442             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
    1443             :  * OGRFieldDefn, for drivers that support AlterFieldDefn.
    1444             :  *
    1445             :  * @param nTZFlag the new time zone flag.
    1446             :  * @since GDAL 3.8
    1447             :  */
    1448        3183 : void OGRFieldDefn::SetTZFlag(int nTZFlag)
    1449             : {
    1450        3183 :     if (m_bSealed)
    1451             :     {
    1452           1 :         CPLError(CE_Failure, CPLE_AppDefined,
    1453             :                  "OGRFieldDefn::SetTZFlag() not allowed on a sealed object");
    1454           1 :         return;
    1455             :     }
    1456        3182 :     m_nTZFlag = nTZFlag;
    1457             : }
    1458             : 
    1459             : /************************************************************************/
    1460             : /*                         OGR_Fld_SetTZFlag()                          */
    1461             : /************************************************************************/
    1462             : /**
    1463             :  * \brief Set the formatting precision for this field in characters.
    1464             :  *
    1465             :  * Set the time zone flag.
    1466             :  *
    1467             :  * Only applies to OFTTime, OFTDate and OFTDateTime fields.
    1468             :  *
    1469             :  * Cf OGR_TZFLAG_UNKNOWN, OGR_TZFLAG_LOCALTIME, OGR_TZFLAG_MIXED_TZ and
    1470             :  * OGR_TZFLAG_UTC
    1471             :  *
    1472             :  * Note that once a OGRFieldDefn has been added to a layer definition with
    1473             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
    1474             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
    1475             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
    1476             :  * OGRFieldDefn, for drivers that support AlterFieldDefn.
    1477             :  *
    1478             :  * @param hDefn handle to the field definition to set precision to.
    1479             :  * @param nTZFlag the new time zone flag.
    1480             :  * @since GDAL 3.8
    1481             :  */
    1482             : 
    1483           6 : void OGR_Fld_SetTZFlag(OGRFieldDefnH hDefn, int nTZFlag)
    1484             : 
    1485             : {
    1486           6 :     OGRFieldDefn::FromHandle(hDefn)->SetTZFlag(nTZFlag);
    1487           6 : }
    1488             : 
    1489             : /************************************************************************/
    1490             : /*                                Set()                                 */
    1491             : /************************************************************************/
    1492             : 
    1493             : /**
    1494             :  * \brief Set defining parameters for a field in one call.
    1495             :  *
    1496             :  * This method is the same as the C function OGR_Fld_Set().
    1497             :  *
    1498             :  * Note that once a OGRFieldDefn has been added to a layer definition with
    1499             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
    1500             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
    1501             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
    1502             :  * OGRFieldDefn, for drivers that support AlterFieldDefn.
    1503             :  *
    1504             :  * @param pszNameIn the new name to assign.
    1505             :  * @param eTypeIn the new type (one of the OFT values like OFTInteger).
    1506             :  * @param nWidthIn the preferred formatting width.  Defaults to zero indicating
    1507             :  * undefined.
    1508             :  * @param nPrecisionIn number of decimals places for formatting, defaults to
    1509             :  * zero indicating undefined.
    1510             :  * @param eJustifyIn the formatting justification (OJLeft or OJRight), defaults
    1511             :  * to OJUndefined.
    1512             :  */
    1513             : 
    1514       85769 : void OGRFieldDefn::Set(const char *pszNameIn, OGRFieldType eTypeIn,
    1515             :                        int nWidthIn, int nPrecisionIn,
    1516             :                        OGRJustification eJustifyIn)
    1517             : {
    1518       85769 :     if (m_bSealed)
    1519             :     {
    1520           0 :         CPLError(CE_Failure, CPLE_AppDefined,
    1521             :                  "OGRFieldDefn::Set() not allowed on a sealed object");
    1522           0 :         return;
    1523             :     }
    1524       85769 :     SetName(pszNameIn);
    1525       85769 :     SetType(eTypeIn);
    1526       85769 :     SetWidth(nWidthIn);
    1527       85769 :     SetPrecision(nPrecisionIn);
    1528       85769 :     SetJustify(eJustifyIn);
    1529             : }
    1530             : 
    1531             : /************************************************************************/
    1532             : /*                            OGR_Fld_Set()                             */
    1533             : /************************************************************************/
    1534             : /**
    1535             :  * \brief Set defining parameters for a field in one call.
    1536             :  *
    1537             :  * This function is the same as the CPP method OGRFieldDefn::Set().
    1538             :  *
    1539             :  * Note that once a OGRFieldDefn has been added to a layer definition with
    1540             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
    1541             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
    1542             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
    1543             :  * OGRFieldDefn, for drivers that support AlterFieldDefn.
    1544             :  *
    1545             :  * @param hDefn handle to the field definition to set to.
    1546             :  * @param pszNameIn the new name to assign.
    1547             :  * @param eTypeIn the new type (one of the OFT values like OFTInteger).
    1548             :  * @param nWidthIn the preferred formatting width.  Defaults to zero indicating
    1549             :  * undefined.
    1550             :  * @param nPrecisionIn number of decimals places for formatting, defaults to
    1551             :  * zero indicating undefined.
    1552             :  * @param eJustifyIn the formatting justification (OJLeft or OJRight), defaults
    1553             :  * to OJUndefined.
    1554             :  */
    1555             : 
    1556           0 : void OGR_Fld_Set(OGRFieldDefnH hDefn, const char *pszNameIn,
    1557             :                  OGRFieldType eTypeIn, int nWidthIn, int nPrecisionIn,
    1558             :                  OGRJustification eJustifyIn)
    1559             : 
    1560             : {
    1561           0 :     OGRFieldDefn::FromHandle(hDefn)->Set(pszNameIn, eTypeIn, nWidthIn,
    1562             :                                          nPrecisionIn, eJustifyIn);
    1563           0 : }
    1564             : 
    1565             : /************************************************************************/
    1566             : /*                             IsIgnored()                              */
    1567             : /************************************************************************/
    1568             : 
    1569             : /**
    1570             :  * \fn int OGRFieldDefn::IsIgnored() const;
    1571             :  *
    1572             :  * \brief Return whether this field should be omitted when fetching features
    1573             :  *
    1574             :  * This method is the same as the C function OGR_Fld_IsIgnored().
    1575             :  *
    1576             :  * @return ignore state
    1577             :  */
    1578             : 
    1579             : /************************************************************************/
    1580             : /*                         OGR_Fld_IsIgnored()                          */
    1581             : /************************************************************************/
    1582             : 
    1583             : /**
    1584             :  * \brief Return whether this field should be omitted when fetching features
    1585             :  *
    1586             :  * This method is the same as the C++ method OGRFieldDefn::IsIgnored().
    1587             :  *
    1588             :  * @param hDefn handle to the field definition
    1589             :  * @return ignore state
    1590             :  */
    1591             : 
    1592           6 : int OGR_Fld_IsIgnored(OGRFieldDefnH hDefn)
    1593             : {
    1594           6 :     return OGRFieldDefn::FromHandle(hDefn)->IsIgnored();
    1595             : }
    1596             : 
    1597             : /************************************************************************/
    1598             : /*                            SetIgnored()                              */
    1599             : /************************************************************************/
    1600             : 
    1601             : /**
    1602             :  * \fn void OGRFieldDefn::SetIgnored( int ignore );
    1603             :  *
    1604             :  * \brief Set whether this field should be omitted when fetching features
    1605             :  *
    1606             :  * This method is the same as the C function OGR_Fld_SetIgnored().
    1607             :  *
    1608             :  * This method should not be called on a object returned with
    1609             :  * OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead, the
    1610             :  * OGRLayer::SetIgnoredFields() method should be called.
    1611             :  *
    1612             :  * @param ignore ignore state
    1613             :  */
    1614             : 
    1615             : /************************************************************************/
    1616             : /*                        OGR_Fld_SetIgnored()                          */
    1617             : /************************************************************************/
    1618             : 
    1619             : /**
    1620             :  * \brief Set whether this field should be omitted when fetching features
    1621             :  *
    1622             :  * This method is the same as the C++ method OGRFieldDefn::SetIgnored().
    1623             :  *
    1624             :  * This method should not be called on a object returned with
    1625             :  * OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead, the
    1626             :  * OGRLayer::SetIgnoredFields() method should be called.
    1627             :  *
    1628             :  * @param hDefn handle to the field definition
    1629             :  * @param ignore ignore state
    1630             :  */
    1631             : 
    1632           0 : void OGR_Fld_SetIgnored(OGRFieldDefnH hDefn, int ignore)
    1633             : {
    1634           0 :     OGRFieldDefn::FromHandle(hDefn)->SetIgnored(ignore);
    1635           0 : }
    1636             : 
    1637             : /************************************************************************/
    1638             : /*                             IsSame()                                 */
    1639             : /************************************************************************/
    1640             : 
    1641             : /**
    1642             :  * \brief Test if the field definition is identical to the other one.
    1643             :  *
    1644             :  * @param poOtherFieldDefn the other field definition to compare to.
    1645             :  * @return TRUE if the field definition is identical to the other one.
    1646             :  */
    1647             : 
    1648         621 : int OGRFieldDefn::IsSame(const OGRFieldDefn *poOtherFieldDefn) const
    1649             : {
    1650        1241 :     return strcmp(pszName, poOtherFieldDefn->pszName) == 0 &&
    1651         620 :            strcmp(pszAlternativeName, poOtherFieldDefn->pszAlternativeName) ==
    1652         619 :                0 &&
    1653         619 :            eType == poOtherFieldDefn->eType &&
    1654         619 :            eSubType == poOtherFieldDefn->eSubType &&
    1655         619 :            nWidth == poOtherFieldDefn->nWidth &&
    1656         618 :            nPrecision == poOtherFieldDefn->nPrecision &&
    1657        1236 :            bNullable == poOtherFieldDefn->bNullable &&
    1658        1859 :            m_osComment == poOtherFieldDefn->m_osComment &&
    1659        1238 :            m_nTZFlag == poOtherFieldDefn->m_nTZFlag;
    1660             : }
    1661             : 
    1662             : /************************************************************************/
    1663             : /*                             IsNullable()                             */
    1664             : /************************************************************************/
    1665             : 
    1666             : /**
    1667             :  * \fn int OGRFieldDefn::IsNullable() const
    1668             :  *
    1669             :  * \brief Return whether this field can receive null values.
    1670             :  *
    1671             :  * By default, fields are nullable.
    1672             :  *
    1673             :  * Even if this method returns FALSE (i.e not-nullable field), it doesn't mean
    1674             :  * that OGRFeature::IsFieldSet() will necessary return TRUE, as fields can be
    1675             :  * temporary unset and null/not-null validation is usually done when
    1676             :  * OGRLayer::CreateFeature()/SetFeature() is called.
    1677             :  *
    1678             :  * This method is the same as the C function OGR_Fld_IsNullable().
    1679             :  *
    1680             :  * @return TRUE if the field is authorized to be null.
    1681             :  * @since GDAL 2.0
    1682             :  */
    1683             : 
    1684             : /************************************************************************/
    1685             : /*                         OGR_Fld_IsNullable()                         */
    1686             : /************************************************************************/
    1687             : 
    1688             : /**
    1689             :  * \brief Return whether this field can receive null values.
    1690             :  *
    1691             :  * By default, fields are nullable.
    1692             :  *
    1693             :  * Even if this method returns FALSE (i.e not-nullable field), it doesn't mean
    1694             :  * that OGRFeature::IsFieldSet() will necessary return TRUE, as fields can be
    1695             :  * temporary unset and null/not-null validation is usually done when
    1696             :  * OGRLayer::CreateFeature()/SetFeature() is called.
    1697             :  *
    1698             :  * This method is the same as the C++ method OGRFieldDefn::IsNullable().
    1699             :  *
    1700             :  * @param hDefn handle to the field definition
    1701             :  * @return TRUE if the field is authorized to be null.
    1702             :  * @since GDAL 2.0
    1703             :  */
    1704             : 
    1705          80 : int OGR_Fld_IsNullable(OGRFieldDefnH hDefn)
    1706             : {
    1707          80 :     return OGRFieldDefn::FromHandle(hDefn)->IsNullable();
    1708             : }
    1709             : 
    1710             : /************************************************************************/
    1711             : /*                            SetNullable()                             */
    1712             : /************************************************************************/
    1713             : 
    1714             : /**
    1715             :  * \fn void OGRFieldDefn::SetNullable( int bNullableIn );
    1716             :  *
    1717             :  * \brief Set whether this field can receive null values.
    1718             :  *
    1719             :  * By default, fields are nullable, so this method is generally called with
    1720             :  * FALSE to set a not-null constraint.
    1721             :  *
    1722             :  * Drivers that support writing not-null constraint will advertise the
    1723             :  * GDAL_DCAP_NOTNULL_FIELDS driver metadata item.
    1724             :  *
    1725             :  * This method is the same as the C function OGR_Fld_SetNullable().
    1726             :  *
    1727             :  * Note that once a OGRFieldDefn has been added to a layer definition with
    1728             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
    1729             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
    1730             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
    1731             :  * OGRFieldDefn, for drivers that support AlterFieldDefn().
    1732             :  *
    1733             :  * @param bNullableIn FALSE if the field must have a not-null constraint.
    1734             :  * @since GDAL 2.0
    1735             :  */
    1736      183251 : void OGRFieldDefn::SetNullable(int bNullableIn)
    1737             : {
    1738      183251 :     if (m_bSealed)
    1739             :     {
    1740           1 :         CPLError(CE_Failure, CPLE_AppDefined,
    1741             :                  "OGRFieldDefn::SetNullable() not allowed on a sealed object");
    1742           1 :         return;
    1743             :     }
    1744      183250 :     bNullable = bNullableIn;
    1745             : }
    1746             : 
    1747             : /************************************************************************/
    1748             : /*                        OGR_Fld_SetNullable()                          */
    1749             : /************************************************************************/
    1750             : 
    1751             : /**
    1752             :  * \brief Set whether this field can receive null values.
    1753             :  *
    1754             :  * By default, fields are nullable, so this method is generally called with
    1755             :  * FALSE to set a not-null constraint.
    1756             :  *
    1757             :  * Drivers that support writing not-null constraint will advertise the
    1758             :  * GDAL_DCAP_NOTNULL_FIELDS driver metadata item.
    1759             :  *
    1760             :  * This method is the same as the C++ method OGRFieldDefn::SetNullable().
    1761             :  *
    1762             :  * Note that once a OGRFieldDefn has been added to a layer definition with
    1763             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
    1764             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
    1765             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
    1766             :  * OGRFieldDefn, for drivers that support AlterFieldDefn().
    1767             :  *
    1768             :  * @param hDefn handle to the field definition
    1769             :  * @param bNullableIn FALSE if the field must have a not-null constraint.
    1770             :  * @since GDAL 2.0
    1771             :  */
    1772             : 
    1773         190 : void OGR_Fld_SetNullable(OGRFieldDefnH hDefn, int bNullableIn)
    1774             : {
    1775         190 :     OGRFieldDefn::FromHandle(hDefn)->SetNullable(bNullableIn);
    1776         190 : }
    1777             : 
    1778             : /************************************************************************/
    1779             : /*                             IsUnique()                               */
    1780             : /************************************************************************/
    1781             : 
    1782             : /**
    1783             :  * \fn int OGRFieldDefn::IsUnique() const
    1784             :  *
    1785             :  * \brief Return whether this field has a unique constraint.
    1786             :  *
    1787             :  * By default, fields have no unique constraint.
    1788             :  *
    1789             :  * This method is the same as the C function OGR_Fld_IsUnique().
    1790             :  *
    1791             :  * @return TRUE if the field has a unique constraint.
    1792             :  * @since GDAL 3.2
    1793             :  */
    1794             : 
    1795             : /************************************************************************/
    1796             : /*                         OGR_Fld_IsUnique()                         */
    1797             : /************************************************************************/
    1798             : 
    1799             : /**
    1800             :  * \brief Return whether this field has a unique constraint.
    1801             :  *
    1802             :  * By default, fields have no unique constraint.
    1803             :  *
    1804             :  * This method is the same as the C++ method OGRFieldDefn::IsUnique().
    1805             :  *
    1806             :  * @param hDefn handle to the field definition
    1807             :  * @return TRUE if the field has a unique constraint.
    1808             :  * @since GDAL 3.2
    1809             :  */
    1810             : 
    1811          80 : int OGR_Fld_IsUnique(OGRFieldDefnH hDefn)
    1812             : {
    1813          80 :     return OGRFieldDefn::FromHandle(hDefn)->IsUnique();
    1814             : }
    1815             : 
    1816             : /*********************************************************  ***************/
    1817             : /*                            SetUnique()                             */
    1818             : /************************************************************************/
    1819             : 
    1820             : /**
    1821             :  * \brief Set whether this field has a unique constraint.
    1822             :  *
    1823             :  * By default, fields have no unique constraint, so this method is generally
    1824             :  * called with TRUE to set a unique constraint.
    1825             :  *
    1826             :  * Drivers that support writing unique constraint will advertise the
    1827             :  * GDAL_DCAP_UNIQUE_FIELDS driver metadata item.
    1828             :  *
    1829             :  * This method is the same as the C function OGR_Fld_SetUnique().
    1830             :  *
    1831             :  * Note that once a OGRFieldDefn has been added to a layer definition with
    1832             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
    1833             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
    1834             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
    1835             :  * OGRFieldDefn, for drivers that support AlterFieldDefn().
    1836             :  *
    1837             :  * @param bUniqueIn TRUE if the field must have a unique constraint.
    1838             :  * @since GDAL 3.2
    1839             :  */
    1840       68195 : void OGRFieldDefn::SetUnique(int bUniqueIn)
    1841             : {
    1842       68195 :     if (m_bSealed)
    1843             :     {
    1844           1 :         CPLError(CE_Failure, CPLE_AppDefined,
    1845             :                  "OGRFieldDefn::SetUnique() not allowed on a sealed object");
    1846           1 :         return;
    1847             :     }
    1848       68194 :     bUnique = bUniqueIn;
    1849             : }
    1850             : 
    1851             : /************************************************************************/
    1852             : /*                        OGR_Fld_SetUnique()                            */
    1853             : /************************************************************************/
    1854             : 
    1855             : /**
    1856             :  * \brief Set whether this field has a unique constraint.
    1857             :  *
    1858             :  * By default, fields have no unique constraint, so this method is generally
    1859             :  *called with TRUE to set a unique constraint.
    1860             :  *
    1861             :  * Drivers that support writing unique constraint will advertise the
    1862             :  * GDAL_DCAP_UNIQUE_FIELDS driver metadata item.
    1863             :  *field can receive null values.
    1864             :  *
    1865             :  * This method is the same as the C++ method OGRFieldDefn::SetUnique().
    1866             :  *
    1867             :  * Note that once a OGRFieldDefn has been added to a layer definition with
    1868             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
    1869             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
    1870             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
    1871             :  * OGRFieldDefn, for drivers that support AlterFieldDefn().
    1872             :  *
    1873             :  * @param hDefn handle to the field definition
    1874             :  * @param bUniqueIn TRUE if the field must have a unique constraint.
    1875             :  * @since GDAL 3.2
    1876             :  */
    1877             : 
    1878          28 : void OGR_Fld_SetUnique(OGRFieldDefnH hDefn, int bUniqueIn)
    1879             : {
    1880          28 :     OGRFieldDefn::FromHandle(hDefn)->SetUnique(bUniqueIn);
    1881          28 : }
    1882             : 
    1883             : /************************************************************************/
    1884             : /*                           GetDomainName()                            */
    1885             : /************************************************************************/
    1886             : 
    1887             : /**
    1888             :  * \fn const std::string& OGRFieldDefn::GetDomainName() const
    1889             :  *
    1890             :  * \brief Return the name of the field domain for this field.
    1891             :  *
    1892             :  * By default, none (empty string) is returned.
    1893             :  *
    1894             :  * Field domains (OGRFieldDomain class) are attached at the GDALDataset level
    1895             :  * and should be retrieved with GDALDataset::GetFieldDomain().
    1896             :  *
    1897             :  * This method is the same as the C function OGR_Fld_GetDomainName().
    1898             :  *
    1899             :  * @return the field domain name, or an empty string if there is none.
    1900             :  * @since GDAL 3.3
    1901             :  */
    1902             : 
    1903             : /************************************************************************/
    1904             : /*                      OGR_Fld_GetDomainName()                         */
    1905             : /************************************************************************/
    1906             : 
    1907             : /**
    1908             :  * \brief Return the name of the field domain for this field.
    1909             :  *
    1910             :  * By default, none (empty string) is returned.
    1911             :  *
    1912             :  * Field domains (OGRFieldDomain class) are attached at the GDALDataset level
    1913             :  * and should be retrieved with GDALDatasetGetFieldDomain().
    1914             :  *
    1915             :  * This method is the same as the C++ method OGRFieldDefn::GetDomainName().
    1916             :  *
    1917             :  * @param hDefn handle to the field definition
    1918             :  * @return the field domain name, or an empty string if there is none.
    1919             :  * @since GDAL 3.3
    1920             :  */
    1921             : 
    1922          34 : const char *OGR_Fld_GetDomainName(OGRFieldDefnH hDefn)
    1923             : {
    1924          34 :     return OGRFieldDefn::FromHandle(hDefn)->GetDomainName().c_str();
    1925             : }
    1926             : 
    1927             : /************************************************************************/
    1928             : /*                           SetDomainName()                            */
    1929             : /************************************************************************/
    1930             : 
    1931             : /**
    1932             :  * \brief Set the name of the field domain for this field.
    1933             :  *
    1934             :  * Field domains (OGRFieldDomain) are attached at the GDALDataset level.
    1935             :  *
    1936             :  * This method is the same as the C function OGR_Fld_SetDomainName().
    1937             :  *
    1938             :  * Note that once a OGRFieldDefn has been added to a layer definition with
    1939             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
    1940             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
    1941             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
    1942             :  * OGRFieldDefn, for drivers that support AlterFieldDefn().
    1943             :  *
    1944             :  * @param osDomainName Field domain name.
    1945             :  * @since GDAL 3.3
    1946             :  */
    1947       13647 : void OGRFieldDefn::SetDomainName(const std::string &osDomainName)
    1948             : {
    1949       13647 :     if (m_bSealed)
    1950             :     {
    1951           1 :         CPLError(
    1952             :             CE_Failure, CPLE_AppDefined,
    1953             :             "OGRFieldDefn::SetDomainName() not allowed on a sealed object");
    1954           1 :         return;
    1955             :     }
    1956       13646 :     m_osDomainName = osDomainName;
    1957             : }
    1958             : 
    1959             : /************************************************************************/
    1960             : /*                      OGR_Fld_SetDomainName()                         */
    1961             : /************************************************************************/
    1962             : 
    1963             : /**
    1964             :  * \brief Set the name of the field domain for this field.
    1965             :  *
    1966             :  * Field domains (OGRFieldDomain) are attached at the GDALDataset level.
    1967             :  *
    1968             :  * This method is the same as the C++ method OGRFieldDefn::SetDomainName().
    1969             :  *
    1970             :  * Note that once a OGRFieldDefn has been added to a layer definition with
    1971             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
    1972             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
    1973             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
    1974             :  * OGRFieldDefn, for drivers that support AlterFieldDefn().
    1975             :  *
    1976             :  * @param hDefn handle to the field definition
    1977             :  * @param pszFieldName Field domain name.
    1978             :  * @since GDAL 3.3
    1979             :  */
    1980             : 
    1981          21 : void OGR_Fld_SetDomainName(OGRFieldDefnH hDefn, const char *pszFieldName)
    1982             : {
    1983          21 :     OGRFieldDefn::FromHandle(hDefn)->SetDomainName(pszFieldName ? pszFieldName
    1984             :                                                                 : "");
    1985          21 : }
    1986             : 
    1987             : /************************************************************************/
    1988             : /*                           GetComment()                               */
    1989             : /************************************************************************/
    1990             : 
    1991             : /**
    1992             :  * \fn const std::string& OGRFieldDefn::GetComment() const
    1993             :  *
    1994             :  * \brief Return the (optional) comment for this field.
    1995             :  *
    1996             :  * By default, none (empty string) is returned.
    1997             :  *
    1998             :  * This method is the same as the C function OGR_Fld_GetComment().
    1999             :  *
    2000             :  * @return the field comment, or an empty string if there is none.
    2001             :  * @since GDAL 3.7
    2002             :  */
    2003             : 
    2004             : /************************************************************************/
    2005             : /*                      OGR_Fld_GetComment()                            */
    2006             : /************************************************************************/
    2007             : 
    2008             : /**
    2009             :  * \brief Return the (optional) comment for this field.
    2010             :  *
    2011             :  * By default, none (empty string) is returned.
    2012             :  *
    2013             :  * This method is the same as the C++ method OGRFieldDefn::GetComment().
    2014             :  *
    2015             :  * @param hDefn handle to the field definition
    2016             :  * @return the comment, or an empty string if there is none.
    2017             :  * @since GDAL 3.7
    2018             :  */
    2019             : 
    2020          58 : const char *OGR_Fld_GetComment(OGRFieldDefnH hDefn)
    2021             : {
    2022          58 :     return OGRFieldDefn::FromHandle(hDefn)->GetComment().c_str();
    2023             : }
    2024             : 
    2025             : /************************************************************************/
    2026             : /*                           SetComment()                               */
    2027             : /************************************************************************/
    2028             : 
    2029             : /**
    2030             :  * \brief Set the comment for this field.
    2031             :  *
    2032             :  * This method is the same as the C function OGR_Fld_SetComment().
    2033             :  *
    2034             :  * Note that once a OGRFieldDefn has been added to a layer definition with
    2035             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
    2036             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
    2037             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
    2038             :  * OGRFieldDefn, for drivers that support AlterFieldDefn().
    2039             :  *
    2040             :  * @param osComment Field comment.
    2041             :  * @since GDAL 3.7
    2042             :  */
    2043        2985 : void OGRFieldDefn::SetComment(const std::string &osComment)
    2044             : {
    2045        2985 :     if (m_bSealed)
    2046             :     {
    2047           1 :         CPLError(CE_Failure, CPLE_AppDefined,
    2048             :                  "OGRFieldDefn::SetComment() not allowed on a sealed object");
    2049           1 :         return;
    2050             :     }
    2051        2984 :     m_osComment = osComment;
    2052             : }
    2053             : 
    2054             : /************************************************************************/
    2055             : /*                      OGR_Fld_SetComment()                            */
    2056             : /************************************************************************/
    2057             : 
    2058             : /**
    2059             :  * \brief Set the comment for this field.
    2060             :  *
    2061             :  * This method is the same as the C++ method OGRFieldDefn::SetComment().
    2062             :  *
    2063             :  * Note that once a OGRFieldDefn has been added to a layer definition with
    2064             :  * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
    2065             :  * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
    2066             :  * OGRLayer::AlterFieldDefn() should be called on a new instance of
    2067             :  * OGRFieldDefn, for drivers that support AlterFieldDefn().
    2068             :  *
    2069             :  * @param hDefn handle to the field definition
    2070             :  * @param pszComment Field comment.
    2071             :  * @since GDAL 3.7
    2072             :  */
    2073             : 
    2074          32 : void OGR_Fld_SetComment(OGRFieldDefnH hDefn, const char *pszComment)
    2075             : {
    2076          32 :     OGRFieldDefn::FromHandle(hDefn)->SetComment(pszComment ? pszComment : "");
    2077          32 : }
    2078             : 
    2079             : /************************************************************************/
    2080             : /*                        OGRUpdateFieldType()                          */
    2081             : /************************************************************************/
    2082             : 
    2083             : /**
    2084             :  * \brief Update the type of a field definition by "merging" its existing type
    2085             :  * with a new type.
    2086             :  *
    2087             :  * The update is done such as broadening the type. For example a OFTInteger
    2088             :  * updated with OFTInteger64 will be promoted to OFTInteger64.
    2089             :  *
    2090             :  * @param poFDefn the field definition whose type must be updated.
    2091             :  * @param eNewType the new field type to merge into the existing type.
    2092             :  * @param eNewSubType the new field subtype to merge into the existing subtype.
    2093             :  * @since GDAL 2.1
    2094             :  */
    2095             : 
    2096          32 : void OGRUpdateFieldType(OGRFieldDefn *poFDefn, OGRFieldType eNewType,
    2097             :                         OGRFieldSubType eNewSubType)
    2098             : {
    2099          32 :     OGRFieldType eType = poFDefn->GetType();
    2100          32 :     if (eType == OFTInteger)
    2101             :     {
    2102           2 :         if (eNewType == OFTInteger && poFDefn->GetSubType() == OFSTBoolean &&
    2103             :             eNewSubType != OFSTBoolean)
    2104             :         {
    2105           0 :             poFDefn->SetSubType(OFSTNone);
    2106             :         }
    2107           2 :         else if (eNewType == OFTInteger64 || eNewType == OFTReal)
    2108             :         {
    2109           0 :             poFDefn->SetSubType(OFSTNone);
    2110           0 :             poFDefn->SetType(eNewType);
    2111             :         }
    2112           2 :         else if (eNewType == OFTIntegerList || eNewType == OFTInteger64List ||
    2113           2 :                  eNewType == OFTRealList || eNewType == OFTStringList)
    2114             :         {
    2115           0 :             if (eNewType != OFTIntegerList || eNewSubType != OFSTBoolean)
    2116           0 :                 poFDefn->SetSubType(OFSTNone);
    2117           0 :             poFDefn->SetType(eNewType);
    2118             :         }
    2119           2 :         else if (eNewType != OFTInteger)
    2120             :         {
    2121           0 :             poFDefn->SetSubType(OFSTNone);
    2122           0 :             poFDefn->SetType(OFTString);
    2123             :         }
    2124             :     }
    2125          30 :     else if (eType == OFTInteger64)
    2126             :     {
    2127           1 :         if (eNewType == OFTReal)
    2128             :         {
    2129           0 :             poFDefn->SetSubType(OFSTNone);
    2130           0 :             poFDefn->SetType(eNewType);
    2131             :         }
    2132           1 :         else if (eNewType == OFTIntegerList)
    2133             :         {
    2134           0 :             poFDefn->SetSubType(OFSTNone);
    2135           0 :             poFDefn->SetType(OFTInteger64List);
    2136             :         }
    2137           1 :         else if (eNewType == OFTInteger64List || eNewType == OFTRealList ||
    2138             :                  eNewType == OFTStringList)
    2139             :         {
    2140           0 :             poFDefn->SetSubType(OFSTNone);
    2141           0 :             poFDefn->SetType(eNewType);
    2142             :         }
    2143           1 :         else if (eNewType != OFTInteger && eNewType != OFTInteger64)
    2144             :         {
    2145           0 :             poFDefn->SetSubType(OFSTNone);
    2146           0 :             poFDefn->SetType(OFTString);
    2147             :         }
    2148             :     }
    2149          29 :     else if (eType == OFTReal)
    2150             :     {
    2151           2 :         if (eNewType == OFTIntegerList || eNewType == OFTInteger64List ||
    2152             :             eNewType == OFTRealList)
    2153             :         {
    2154           0 :             poFDefn->SetType(OFTRealList);
    2155             :         }
    2156           2 :         else if (eNewType == OFTStringList)
    2157             :         {
    2158           0 :             poFDefn->SetType(OFTStringList);
    2159             :         }
    2160           2 :         else if (eNewType != OFTInteger && eNewType != OFTInteger64 &&
    2161             :                  eNewType != OFTReal)
    2162             :         {
    2163           0 :             poFDefn->SetSubType(OFSTNone);
    2164           0 :             poFDefn->SetType(OFTString);
    2165             :         }
    2166             :     }
    2167          27 :     else if (eType == OFTIntegerList)
    2168             :     {
    2169           1 :         if (eNewType == OFTIntegerList &&
    2170           2 :             poFDefn->GetSubType() == OFSTBoolean && eNewSubType != OFSTBoolean)
    2171             :         {
    2172           0 :             poFDefn->SetSubType(OFSTNone);
    2173             :         }
    2174           1 :         else if (eNewType == OFTInteger64 || eNewType == OFTInteger64List)
    2175             :         {
    2176           0 :             poFDefn->SetSubType(OFSTNone);
    2177           0 :             poFDefn->SetType(OFTInteger64List);
    2178             :         }
    2179           1 :         else if (eNewType == OFTReal || eNewType == OFTRealList)
    2180             :         {
    2181           0 :             poFDefn->SetSubType(OFSTNone);
    2182           0 :             poFDefn->SetType(OFTRealList);
    2183             :         }
    2184           1 :         else if (eNewType != OFTInteger && eNewType != OFTIntegerList)
    2185             :         {
    2186           0 :             poFDefn->SetSubType(OFSTNone);
    2187           0 :             poFDefn->SetType(OFTStringList);
    2188             :         }
    2189             :     }
    2190          26 :     else if (eType == OFTInteger64List)
    2191             :     {
    2192           1 :         if (eNewType == OFTReal || eNewType == OFTRealList)
    2193           0 :             poFDefn->SetType(OFTRealList);
    2194           1 :         else if (eNewType != OFTInteger && eNewType != OFTInteger64 &&
    2195           1 :                  eNewType != OFTIntegerList && eNewType != OFTInteger64List)
    2196             :         {
    2197           0 :             poFDefn->SetSubType(OFSTNone);
    2198           0 :             poFDefn->SetType(OFTStringList);
    2199             :         }
    2200             :     }
    2201          25 :     else if (eType == OFTRealList)
    2202             :     {
    2203           1 :         if (eNewType != OFTInteger && eNewType != OFTInteger64 &&
    2204           1 :             eNewType != OFTReal && eNewType != OFTIntegerList &&
    2205           1 :             eNewType != OFTInteger64List && eNewType != OFTRealList)
    2206             :         {
    2207           0 :             poFDefn->SetSubType(OFSTNone);
    2208           0 :             poFDefn->SetType(OFTStringList);
    2209             :         }
    2210             :     }
    2211          24 :     else if (eType == OFTDateTime)
    2212             :     {
    2213           1 :         if (eNewType != OFTDateTime && eNewType != OFTDate)
    2214             :         {
    2215           0 :             poFDefn->SetType(OFTString);
    2216             :         }
    2217             :     }
    2218          23 :     else if (eType == OFTDate || eType == OFTTime)
    2219             :     {
    2220           2 :         if (eNewType == OFTDateTime)
    2221           0 :             poFDefn->SetType(OFTDateTime);
    2222           2 :         else if (eNewType != eType)
    2223           0 :             poFDefn->SetType(OFTString);
    2224             :     }
    2225          21 :     else if (eType == OFTString && eNewType == OFTStringList)
    2226             :     {
    2227           0 :         poFDefn->SetType(OFTStringList);
    2228             :     }
    2229          32 : }
    2230             : 
    2231             : /************************************************************************/
    2232             : /*                        OGRFieldDefn::Seal()                          */
    2233             : /************************************************************************/
    2234             : 
    2235             : /** Seal a OGRFieldDefn.
    2236             :  *
    2237             :  * A sealed OGRFieldDefn can not be modified while it is sealed.
    2238             :  *
    2239             :  * This method should only be called by driver implementations.
    2240             :  *
    2241             :  * @since GDAL 3.9
    2242             :  */
    2243     4709880 : void OGRFieldDefn::Seal()
    2244             : {
    2245     4709880 :     m_bSealed = true;
    2246     4709880 : }
    2247             : 
    2248             : /************************************************************************/
    2249             : /*                        OGRFieldDefn::Unseal()                        */
    2250             : /************************************************************************/
    2251             : 
    2252             : /** Unseal a OGRFieldDefn.
    2253             :  *
    2254             :  * Undo OGRFieldDefn::Seal()
    2255             :  *
    2256             :  * Using GetTemporaryUnsealer() is recommended for most use cases.
    2257             :  *
    2258             :  * This method should only be called by driver implementations.
    2259             :  *
    2260             :  * @since GDAL 3.9
    2261             :  */
    2262     4672440 : void OGRFieldDefn::Unseal()
    2263             : {
    2264     4672440 :     m_bSealed = false;
    2265     4672440 : }
    2266             : 
    2267             : /************************************************************************/
    2268             : /*                    OGRFieldDefn::GetTemporaryUnsealer()              */
    2269             : /************************************************************************/
    2270             : 
    2271             : /** Return an object that temporary unseals the OGRFieldDefn
    2272             :  *
    2273             :  * The returned object calls Unseal() initially, and when it is destroyed
    2274             :  * it calls Seal().
    2275             :  *
    2276             :  * This method should only be called by driver implementations.
    2277             :  *
    2278             :  * It is also possible to use the helper method whileUnsealing(). Example:
    2279             :  * whileUnsealing(poFieldDefn)->some_method()
    2280             :  *
    2281             :  * @since GDAL 3.9
    2282             :  */
    2283         184 : OGRFieldDefn::TemporaryUnsealer OGRFieldDefn::GetTemporaryUnsealer()
    2284             : {
    2285         184 :     return TemporaryUnsealer(this);
    2286             : }
    2287             : 
    2288             : /************************************************************************/
    2289             : /*                          OGRFieldDomain()                            */
    2290             : /************************************************************************/
    2291             : 
    2292             : /*! @cond Doxygen_Suppress */
    2293        1292 : OGRFieldDomain::OGRFieldDomain(const std::string &osName,
    2294             :                                const std::string &osDescription,
    2295             :                                OGRFieldDomainType eDomainType,
    2296             :                                OGRFieldType eFieldType,
    2297        1292 :                                OGRFieldSubType eFieldSubType)
    2298             :     : m_osName(osName), m_osDescription(osDescription),
    2299             :       m_eDomainType(eDomainType), m_eFieldType(eFieldType),
    2300        1292 :       m_eFieldSubType(eFieldSubType)
    2301             : {
    2302        1292 : }
    2303             : 
    2304             : /*! @endcond */
    2305             : 
    2306             : /************************************************************************/
    2307             : /*                         ~OGRFieldDomain()                            */
    2308             : /************************************************************************/
    2309             : 
    2310             : OGRFieldDomain::~OGRFieldDomain() = default;
    2311             : 
    2312             : /************************************************************************/
    2313             : /*                         ~OGRFieldDomain()                            */
    2314             : /************************************************************************/
    2315             : 
    2316             : /** Destroy a field domain.
    2317             :  *
    2318             :  * This is the same as the C++ method OGRFieldDomain::~OGRFieldDomain()
    2319             :  *
    2320             :  * @param hFieldDomain the field domain.
    2321             :  * @since GDAL 3.3
    2322             :  */
    2323          44 : void OGR_FldDomain_Destroy(OGRFieldDomainH hFieldDomain)
    2324             : {
    2325          44 :     delete OGRFieldDomain::FromHandle(hFieldDomain);
    2326          44 : }
    2327             : 
    2328             : /************************************************************************/
    2329             : /*                        OGRCodedFieldDomain()                         */
    2330             : /************************************************************************/
    2331             : 
    2332        1196 : OGRCodedFieldDomain::OGRCodedFieldDomain(const std::string &osName,
    2333             :                                          const std::string &osDescription,
    2334             :                                          OGRFieldType eFieldType,
    2335             :                                          OGRFieldSubType eFieldSubType,
    2336        1196 :                                          std::vector<OGRCodedValue> &&asValues)
    2337             :     : OGRFieldDomain(osName, osDescription, OFDT_CODED, eFieldType,
    2338             :                      eFieldSubType),
    2339        1196 :       m_asValues(std::move(asValues))
    2340             : {
    2341             :     // Guard
    2342        1196 :     if (m_asValues.empty() || m_asValues.back().pszCode != nullptr)
    2343             :     {
    2344             :         OGRCodedValue cv;
    2345        1134 :         cv.pszCode = nullptr;
    2346        1134 :         cv.pszValue = nullptr;
    2347        1134 :         m_asValues.emplace_back(cv);
    2348             :     }
    2349        1196 : }
    2350             : 
    2351             : /************************************************************************/
    2352             : /*                     OGR_CodedFldDomain_Create()                      */
    2353             : /************************************************************************/
    2354             : 
    2355             : /** Creates a new coded field domain.
    2356             :  *
    2357             :  * This is the same as the C++ method OGRCodedFieldDomain::OGRCodedFieldDomain()
    2358             :  * (except that the C function copies the enumeration, whereas the C++
    2359             :  * method moves it)
    2360             :  *
    2361             :  * @param pszName        Domain name. Should not be NULL.
    2362             :  * @param pszDescription Domain description (can be NULL)
    2363             :  * @param eFieldType     Field type. Generally numeric. Potentially OFTDateTime
    2364             :  * @param eFieldSubType  Field subtype.
    2365             :  * @param enumeration    Enumeration as (code, value) pairs. Should not be
    2366             :  *                       NULL. The end of the enumeration is marked by a code
    2367             :  *                       set to NULL. The enumeration will be copied.
    2368             :  *                       Each code should appear only once, but it is the
    2369             :  *                       responsibility of the user to check it.
    2370             :  * @return a new handle that should be freed with OGR_FldDomain_Destroy(),
    2371             :  *         or NULL in case of error.
    2372             :  * @since GDAL 3.3
    2373             :  */
    2374          61 : OGRFieldDomainH OGR_CodedFldDomain_Create(const char *pszName,
    2375             :                                           const char *pszDescription,
    2376             :                                           OGRFieldType eFieldType,
    2377             :                                           OGRFieldSubType eFieldSubType,
    2378             :                                           const OGRCodedValue *enumeration)
    2379             : {
    2380          61 :     VALIDATE_POINTER1(pszName, __func__, nullptr);
    2381          61 :     VALIDATE_POINTER1(enumeration, __func__, nullptr);
    2382          61 :     size_t count = 0;
    2383         207 :     for (int i = 0; enumeration[i].pszCode != nullptr; ++i)
    2384             :     {
    2385         146 :         ++count;
    2386             :     }
    2387         122 :     std::vector<OGRCodedValue> asValues;
    2388             :     try
    2389             :     {
    2390          61 :         asValues.reserve(count + 1);
    2391             :     }
    2392           0 :     catch (const std::exception &e)
    2393             :     {
    2394           0 :         CPLError(CE_Failure, CPLE_OutOfMemory, "%s", e.what());
    2395           0 :         return nullptr;
    2396             :     }
    2397          61 :     bool error = false;
    2398         207 :     for (int i = 0; enumeration[i].pszCode != nullptr; ++i)
    2399             :     {
    2400             :         OGRCodedValue cv;
    2401         146 :         cv.pszCode = VSI_STRDUP_VERBOSE(enumeration[i].pszCode);
    2402         146 :         if (cv.pszCode == nullptr)
    2403             :         {
    2404           0 :             error = true;
    2405           0 :             break;
    2406             :         }
    2407         146 :         if (enumeration[i].pszValue)
    2408             :         {
    2409         122 :             cv.pszValue = VSI_STRDUP_VERBOSE(enumeration[i].pszValue);
    2410         122 :             if (cv.pszValue == nullptr)
    2411             :             {
    2412           0 :                 VSIFree(cv.pszCode);
    2413           0 :                 error = true;
    2414           0 :                 break;
    2415             :             }
    2416             :         }
    2417             :         else
    2418             :         {
    2419          24 :             cv.pszValue = nullptr;
    2420             :         }
    2421         146 :         asValues.emplace_back(cv);
    2422             :     }
    2423          61 :     if (error)
    2424             :     {
    2425           0 :         for (auto &cv : asValues)
    2426             :         {
    2427           0 :             VSIFree(cv.pszCode);
    2428           0 :             VSIFree(cv.pszValue);
    2429             :         }
    2430           0 :         return nullptr;
    2431             :     }
    2432             :     // Add guard
    2433             :     {
    2434             :         OGRCodedValue cv;
    2435          61 :         cv.pszCode = nullptr;
    2436          61 :         cv.pszValue = nullptr;
    2437          61 :         asValues.emplace_back(cv);
    2438             :     }
    2439         183 :     return OGRFieldDomain::ToHandle(new OGRCodedFieldDomain(
    2440             :         pszName, pszDescription ? pszDescription : "", eFieldType,
    2441         122 :         eFieldSubType, std::move(asValues)));
    2442             : }
    2443             : 
    2444             : /************************************************************************/
    2445             : /*                   OGRCodedFieldDomain::Clone()                       */
    2446             : /************************************************************************/
    2447             : 
    2448          40 : OGRCodedFieldDomain *OGRCodedFieldDomain::Clone() const
    2449             : {
    2450          80 :     auto poDomain = cpl::down_cast<OGRCodedFieldDomain *>(
    2451             :         OGRFieldDomain::FromHandle(OGR_CodedFldDomain_Create(
    2452          40 :             m_osName.c_str(), m_osDescription.c_str(), m_eFieldType,
    2453          40 :             m_eFieldSubType, m_asValues.data())));
    2454          40 :     poDomain->SetMergePolicy(m_eMergePolicy);
    2455          40 :     poDomain->SetSplitPolicy(m_eSplitPolicy);
    2456          40 :     return poDomain;
    2457             : }
    2458             : 
    2459             : /************************************************************************/
    2460             : /*                      ~OGRCodedFieldDomain()                          */
    2461             : /************************************************************************/
    2462             : 
    2463        2389 : OGRCodedFieldDomain::~OGRCodedFieldDomain()
    2464             : {
    2465       19705 :     for (auto &cv : m_asValues)
    2466             :     {
    2467       18510 :         CPLFree(cv.pszCode);
    2468       18510 :         CPLFree(cv.pszValue);
    2469             :     }
    2470        2389 : }
    2471             : 
    2472             : /************************************************************************/
    2473             : /*                       OGRRangeFieldDomain()                          */
    2474             : /************************************************************************/
    2475             : 
    2476             : // cppcheck-suppress uninitMemberVar
    2477          62 : OGRRangeFieldDomain::OGRRangeFieldDomain(
    2478             :     const std::string &osName, const std::string &osDescription,
    2479             :     OGRFieldType eFieldType, OGRFieldSubType eFieldSubType,
    2480             :     const OGRField &sMin, bool bMinIsInclusive, const OGRField &sMax,
    2481          62 :     bool bMaxIsInclusive)
    2482             :     : OGRFieldDomain(osName, osDescription, OFDT_RANGE, eFieldType,
    2483             :                      eFieldSubType),
    2484             :       m_sMin(sMin), m_sMax(sMax), m_bMinIsInclusive(bMinIsInclusive),
    2485          62 :       m_bMaxIsInclusive(bMaxIsInclusive)
    2486             : {
    2487          62 :     CPLAssert(eFieldType == OFTInteger || eFieldType == OFTInteger64 ||
    2488             :               eFieldType == OFTReal || eFieldType == OFTDateTime);
    2489          62 : }
    2490             : 
    2491             : /************************************************************************/
    2492             : /*                     OGR_RangeFldDomain_Create()                      */
    2493             : /************************************************************************/
    2494             : 
    2495          12 : static OGRField GetUnsetField()
    2496             : {
    2497             :     OGRField sUnset;
    2498          12 :     OGR_RawField_SetUnset(&sUnset);
    2499          12 :     return sUnset;
    2500             : }
    2501             : 
    2502             : /** Creates a new range field domain.
    2503             :  *
    2504             :  * This is the same as the C++ method
    2505             :  * OGRRangeFieldDomain::OGRRangeFieldDomain().
    2506             :  *
    2507             :  * @param pszName        Domain name. Should not be NULL.
    2508             :  * @param pszDescription Domain description (can be NULL)
    2509             :  * @param eFieldType     Field type. Among OFTInteger, OFTInteger64, OFTReal
    2510             :  *                       and OFTDateTime.
    2511             :  * @param eFieldSubType  Field subtype.
    2512             :  * @param psMin          Minimum value (can be NULL). The member in the union
    2513             :  *                       that is read is consistent with eFieldType
    2514             :  * @param bMinIsInclusive Whether the minimum value is included in the range.
    2515             :  * @param psMax          Maximum value (can be NULL). The member in the union
    2516             :  *                       that is read is consistent with eFieldType
    2517             :  * @param bMaxIsInclusive Whether the maximum value is included in the range.
    2518             :  * @return a new handle that should be freed with OGR_FldDomain_Destroy()
    2519             :  * @since GDAL 3.3
    2520             :  */
    2521          12 : OGRFieldDomainH OGR_RangeFldDomain_Create(
    2522             :     const char *pszName, const char *pszDescription, OGRFieldType eFieldType,
    2523             :     OGRFieldSubType eFieldSubType, const OGRField *psMin, bool bMinIsInclusive,
    2524             :     const OGRField *psMax, bool bMaxIsInclusive)
    2525             : {
    2526          12 :     VALIDATE_POINTER1(pszName, __func__, nullptr);
    2527          12 :     if (eFieldType != OFTInteger && eFieldType != OFTInteger64 &&
    2528           2 :         eFieldType != OFTReal && eFieldType != OFTDateTime)
    2529             :     {
    2530           0 :         CPLError(CE_Failure, CPLE_NotSupported, "Unsupported field type");
    2531           0 :         return nullptr;
    2532             :     }
    2533          12 :     const OGRField unsetField = GetUnsetField();
    2534          36 :     return OGRFieldDomain::ToHandle(new OGRRangeFieldDomain(
    2535             :         pszName, pszDescription ? pszDescription : "", eFieldType,
    2536             :         eFieldSubType, psMin ? *psMin : unsetField, bMinIsInclusive,
    2537          24 :         psMax ? *psMax : unsetField, bMaxIsInclusive));
    2538             : }
    2539             : 
    2540             : /************************************************************************/
    2541             : /*                        OGRGlobFieldDomain()                          */
    2542             : /************************************************************************/
    2543             : 
    2544          34 : OGRGlobFieldDomain::OGRGlobFieldDomain(const std::string &osName,
    2545             :                                        const std::string &osDescription,
    2546             :                                        OGRFieldType eFieldType,
    2547             :                                        OGRFieldSubType eFieldSubType,
    2548          34 :                                        const std::string &osGlob)
    2549             :     : OGRFieldDomain(osName, osDescription, OFDT_GLOB, eFieldType,
    2550             :                      eFieldSubType),
    2551          34 :       m_osGlob(osGlob)
    2552             : {
    2553          34 : }
    2554             : 
    2555             : /************************************************************************/
    2556             : /*                       OGR_GlobFldDomain_Create()                     */
    2557             : /************************************************************************/
    2558             : 
    2559             : /** Creates a new glob field domain.
    2560             :  *
    2561             :  * This is the same as the C++ method OGRGlobFieldDomain::OGRGlobFieldDomain()
    2562             :  *
    2563             :  * @param pszName        Domain name. Should not be NULL.
    2564             :  * @param pszDescription Domain description (can be NULL)
    2565             :  * @param eFieldType     Field type.
    2566             :  * @param eFieldSubType  Field subtype.
    2567             :  * @param pszGlob        Glob expression. Should not be NULL.
    2568             :  * @return a new handle that should be freed with OGR_FldDomain_Destroy()
    2569             :  * @since GDAL 3.3
    2570             :  */
    2571          14 : OGRFieldDomainH OGR_GlobFldDomain_Create(const char *pszName,
    2572             :                                          const char *pszDescription,
    2573             :                                          OGRFieldType eFieldType,
    2574             :                                          OGRFieldSubType eFieldSubType,
    2575             :                                          const char *pszGlob)
    2576             : {
    2577          14 :     VALIDATE_POINTER1(pszName, __func__, nullptr);
    2578          14 :     VALIDATE_POINTER1(pszGlob, __func__, nullptr);
    2579          42 :     return OGRFieldDomain::ToHandle(
    2580             :         new OGRGlobFieldDomain(pszName, pszDescription ? pszDescription : "",
    2581          28 :                                eFieldType, eFieldSubType, pszGlob));
    2582             : }
    2583             : 
    2584             : /************************************************************************/
    2585             : /*                       OGR_FldDomain_GetName()                        */
    2586             : /************************************************************************/
    2587             : 
    2588             : /** Get the name of the field domain.
    2589             :  *
    2590             :  * This is the same as the C++ method OGRFieldDomain::GetName()
    2591             :  *
    2592             :  * @param hFieldDomain Field domain handle.
    2593             :  * @return the field domain name.
    2594             :  * @since GDAL 3.3
    2595             :  */
    2596          57 : const char *OGR_FldDomain_GetName(OGRFieldDomainH hFieldDomain)
    2597             : {
    2598          57 :     return OGRFieldDomain::FromHandle(hFieldDomain)->GetName().c_str();
    2599             : }
    2600             : 
    2601             : /************************************************************************/
    2602             : /*                     OGR_FldDomain_GetDescription()                   */
    2603             : /************************************************************************/
    2604             : 
    2605             : /** Get the description of the field domain.
    2606             :  *
    2607             :  * This is the same as the C++ method OGRFieldDomain::GetDescription()
    2608             :  *
    2609             :  * @param hFieldDomain Field domain handle.
    2610             :  * @return the field domain description (might be empty string).
    2611             :  * @since GDAL 3.3
    2612             :  */
    2613          61 : const char *OGR_FldDomain_GetDescription(OGRFieldDomainH hFieldDomain)
    2614             : {
    2615          61 :     return OGRFieldDomain::FromHandle(hFieldDomain)->GetDescription().c_str();
    2616             : }
    2617             : 
    2618             : /************************************************************************/
    2619             : /*                     OGR_FldDomain_GetDomainType()                    */
    2620             : /************************************************************************/
    2621             : 
    2622             : /** Get the type of the field domain.
    2623             :  *
    2624             :  * This is the same as the C++ method OGRFieldDomain::GetDomainType()
    2625             :  *
    2626             :  * @param hFieldDomain Field domain handle.
    2627             :  * @return the type of the field domain.
    2628             :  * @since GDAL 3.3
    2629             :  */
    2630          54 : OGRFieldDomainType OGR_FldDomain_GetDomainType(OGRFieldDomainH hFieldDomain)
    2631             : {
    2632          54 :     return OGRFieldDomain::FromHandle(hFieldDomain)->GetDomainType();
    2633             : }
    2634             : 
    2635             : /************************************************************************/
    2636             : /*                     OGR_FldDomain_GetFieldType()                     */
    2637             : /************************************************************************/
    2638             : 
    2639             : /** Get the field type of the field domain.
    2640             :  *
    2641             :  * This is the same as the C++ method OGRFieldDomain::GetFieldType()
    2642             :  *
    2643             :  * @param hFieldDomain Field domain handle.
    2644             :  * @return the field type of the field domain.
    2645             :  * @since GDAL 3.3
    2646             :  */
    2647          84 : OGRFieldType OGR_FldDomain_GetFieldType(OGRFieldDomainH hFieldDomain)
    2648             : {
    2649          84 :     return OGRFieldDomain::FromHandle(hFieldDomain)->GetFieldType();
    2650             : }
    2651             : 
    2652             : /************************************************************************/
    2653             : /*                   OGR_FldDomain_GetFieldSubType()                    */
    2654             : /************************************************************************/
    2655             : 
    2656             : /** Get the field subtype of the field domain.
    2657             :  *
    2658             :  * This is the same as OGRFieldDomain::GetFieldSubType()
    2659             :  *
    2660             :  * @param hFieldDomain Field domain handle.
    2661             :  * @return the field subtype of the field domain.
    2662             :  * @since GDAL 3.3
    2663             :  */
    2664          40 : OGRFieldSubType OGR_FldDomain_GetFieldSubType(OGRFieldDomainH hFieldDomain)
    2665             : {
    2666          40 :     return OGRFieldDomain::FromHandle(hFieldDomain)->GetFieldSubType();
    2667             : }
    2668             : 
    2669             : /************************************************************************/
    2670             : /*                    OGR_FldDomain_GetSplitPolicy()                    */
    2671             : /************************************************************************/
    2672             : 
    2673             : /** Get the split policy of the field domain.
    2674             :  *
    2675             :  * This is the same as the C++ method OGRFieldDomain::GetSplitPolicy()
    2676             :  *
    2677             :  * @param hFieldDomain Field domain handle.
    2678             :  * @return the split policy of the field domain.
    2679             :  * @since GDAL 3.3
    2680             :  */
    2681             : 
    2682             : OGRFieldDomainSplitPolicy
    2683           2 : OGR_FldDomain_GetSplitPolicy(OGRFieldDomainH hFieldDomain)
    2684             : {
    2685           2 :     return OGRFieldDomain::FromHandle(hFieldDomain)->GetSplitPolicy();
    2686             : }
    2687             : 
    2688             : /************************************************************************/
    2689             : /*                    OGR_FldDomain_SetSplitPolicy()                    */
    2690             : /************************************************************************/
    2691             : 
    2692             : /** Set the split policy of the field domain.
    2693             :  *
    2694             :  * This is the same as the C++ method OGRFieldDomain::SetSplitPolicy()
    2695             :  *
    2696             :  * @param hFieldDomain Field domain handle.
    2697             :  * @param policy the split policy of the field domain.
    2698             :  * @since GDAL 3.3
    2699             :  */
    2700             : 
    2701           1 : void OGR_FldDomain_SetSplitPolicy(OGRFieldDomainH hFieldDomain,
    2702             :                                   OGRFieldDomainSplitPolicy policy)
    2703             : {
    2704           1 :     OGRFieldDomain::FromHandle(hFieldDomain)->SetSplitPolicy(policy);
    2705           1 : }
    2706             : 
    2707             : /************************************************************************/
    2708             : /*                    OGR_FldDomain_GetMergePolicy()                    */
    2709             : /************************************************************************/
    2710             : 
    2711             : /** Get the merge policy of the field domain.
    2712             :  *
    2713             :  * This is the same as the C++ method OGRFieldDomain::GetMergePolicy()
    2714             :  *
    2715             :  * @param hFieldDomain Field domain handle.
    2716             :  * @return the merge policy of the field domain.
    2717             :  * @since GDAL 3.3
    2718             :  */
    2719             : 
    2720             : OGRFieldDomainMergePolicy
    2721           2 : OGR_FldDomain_GetMergePolicy(OGRFieldDomainH hFieldDomain)
    2722             : {
    2723           2 :     return OGRFieldDomain::FromHandle(hFieldDomain)->GetMergePolicy();
    2724             : }
    2725             : 
    2726             : /************************************************************************/
    2727             : /*                    OGR_FldDomain_SetMergePolicy()                    */
    2728             : /************************************************************************/
    2729             : 
    2730             : /** Set the merge policy of the field domain.
    2731             :  *
    2732             :  * This is the same as the C++ method OGRFieldDomain::SetMergePolicy()
    2733             :  *
    2734             :  * @param hFieldDomain Field domain handle.
    2735             :  * @param policy the merge policy of the field domain.
    2736             :  * @since GDAL 3.3
    2737             :  */
    2738             : 
    2739           1 : void OGR_FldDomain_SetMergePolicy(OGRFieldDomainH hFieldDomain,
    2740             :                                   OGRFieldDomainMergePolicy policy)
    2741             : {
    2742           1 :     OGRFieldDomain::FromHandle(hFieldDomain)->SetMergePolicy(policy);
    2743           1 : }
    2744             : 
    2745             : /************************************************************************/
    2746             : /*                  OGR_CodedFldDomain_GetEnumeration()                 */
    2747             : /************************************************************************/
    2748             : 
    2749             : /** Get the enumeration as (code, value) pairs.
    2750             :  *
    2751             :  * The end of the enumeration is signaled by code == NULL
    2752             :  *
    2753             :  * This is the same as the C++ method OGRCodedFieldDomain::GetEnumeration()
    2754             :  *
    2755             :  * @param hFieldDomain Field domain handle.
    2756             :  * @return the (code, value) pairs, or nullptr in case of error.
    2757             :  * @since GDAL 3.3
    2758             :  */
    2759             : const OGRCodedValue *
    2760          39 : OGR_CodedFldDomain_GetEnumeration(OGRFieldDomainH hFieldDomain)
    2761             : {
    2762             :     // The user should normally only call us with the right object type, but
    2763             :     // it doesn't hurt to check.
    2764          39 :     auto poFieldDomain = dynamic_cast<const OGRCodedFieldDomain *>(
    2765          78 :         OGRFieldDomain::FromHandle(hFieldDomain));
    2766          39 :     if (!poFieldDomain)
    2767             :     {
    2768           1 :         CPLError(
    2769             :             CE_Failure, CPLE_AppDefined,
    2770             :             "This function should be called with a coded field domain object");
    2771           1 :         return nullptr;
    2772             :     }
    2773          38 :     return poFieldDomain->GetEnumeration();
    2774             : }
    2775             : 
    2776             : /************************************************************************/
    2777             : /*                     OGR_RangeFldDomain_GetMin()                      */
    2778             : /************************************************************************/
    2779             : 
    2780             : /** Get the minimum value.
    2781             :  *
    2782             :  * Which member in the returned OGRField enum must be read depends on the field
    2783             :  * type.
    2784             :  *
    2785             :  * If no minimum value is set, the OGR_RawField_IsUnset() will return true when
    2786             :  * called on the result.
    2787             :  *
    2788             :  * This is the same as the C++ method OGRRangeFieldDomain::GetMin()
    2789             :  *
    2790             :  * @param hFieldDomain Field domain handle.
    2791             :  * @param pbIsInclusiveOut set to true if the minimum is included in the range.
    2792             :  * @return the minimum value.
    2793             :  * @since GDAL 3.3
    2794             :  */
    2795          21 : const OGRField *OGR_RangeFldDomain_GetMin(OGRFieldDomainH hFieldDomain,
    2796             :                                           bool *pbIsInclusiveOut)
    2797             : {
    2798             :     // The user should normally only call us with the right object type, but
    2799             :     // it doesn't hurt to check.
    2800          21 :     auto poFieldDomain = dynamic_cast<const OGRRangeFieldDomain *>(
    2801          42 :         OGRFieldDomain::FromHandle(hFieldDomain));
    2802          21 :     if (!poFieldDomain)
    2803             :     {
    2804           0 :         CPLError(
    2805             :             CE_Failure, CPLE_AppDefined,
    2806             :             "This function should be called with a range field domain object");
    2807           0 :         static const OGRField dummyField = GetUnsetField();
    2808           0 :         return &dummyField;
    2809             :     }
    2810          21 :     bool bIsInclusive = false;
    2811          21 :     const auto &ret = poFieldDomain->GetMin(bIsInclusive);
    2812          21 :     if (pbIsInclusiveOut)
    2813           7 :         *pbIsInclusiveOut = bIsInclusive;
    2814          21 :     return &ret;
    2815             : }
    2816             : 
    2817             : /************************************************************************/
    2818             : /*                     OGR_RangeFldDomain_GetMax()                      */
    2819             : /************************************************************************/
    2820             : 
    2821             : /** Get the maximum value.
    2822             :  *
    2823             :  * Which member in the returned OGRField enum must be read depends on the field
    2824             :  * type.
    2825             :  *
    2826             :  * If no maximum value is set, the OGR_RawField_IsUnset() will return true when
    2827             :  * called on the result.
    2828             :  *
    2829             :  * This is the same as the C++ method OGRRangeFieldDomain::GetMax()
    2830             :  *
    2831             :  * @param hFieldDomain Field domain handle.
    2832             :  * @param pbIsInclusiveOut set to true if the maximum is included in the range.
    2833             :  * @return the maximum value.
    2834             :  * @since GDAL 3.3
    2835             :  */
    2836          21 : const OGRField *OGR_RangeFldDomain_GetMax(OGRFieldDomainH hFieldDomain,
    2837             :                                           bool *pbIsInclusiveOut)
    2838             : {
    2839             :     // The user should normally only call us with the right object type, but
    2840             :     // it doesn't hurt to check.
    2841          21 :     auto poFieldDomain = dynamic_cast<const OGRRangeFieldDomain *>(
    2842          42 :         OGRFieldDomain::FromHandle(hFieldDomain));
    2843          21 :     if (!poFieldDomain)
    2844             :     {
    2845           0 :         CPLError(
    2846             :             CE_Failure, CPLE_AppDefined,
    2847             :             "This function should be called with a range field domain object");
    2848           0 :         static const OGRField dummyField = GetUnsetField();
    2849           0 :         return &dummyField;
    2850             :     }
    2851          21 :     bool bIsInclusive = false;
    2852          21 :     const auto &ret = poFieldDomain->GetMax(bIsInclusive);
    2853          21 :     if (pbIsInclusiveOut)
    2854           7 :         *pbIsInclusiveOut = bIsInclusive;
    2855          21 :     return &ret;
    2856             : }
    2857             : 
    2858             : /************************************************************************/
    2859             : /*                     OGR_GlobFldDomain_GetGlob()                      */
    2860             : /************************************************************************/
    2861             : 
    2862             : /** Get the glob expression.
    2863             :  *
    2864             :  * This is the same as the C++ method OGRGlobFieldDomain::GetGlob()
    2865             :  *
    2866             :  * @param hFieldDomain Field domain handle.
    2867             :  * @return the glob expression, or nullptr in case of error
    2868             :  * @since GDAL 3.3
    2869             :  */
    2870           9 : const char *OGR_GlobFldDomain_GetGlob(OGRFieldDomainH hFieldDomain)
    2871             : {
    2872             :     // The user should normally only call us with the right object type, but
    2873             :     // it doesn't hurt to check.
    2874           9 :     auto poFieldDomain = dynamic_cast<const OGRGlobFieldDomain *>(
    2875          18 :         OGRFieldDomain::FromHandle(hFieldDomain));
    2876           9 :     if (!poFieldDomain)
    2877             :     {
    2878           1 :         CPLError(
    2879             :             CE_Failure, CPLE_AppDefined,
    2880             :             "This function should be called with a glob field domain object");
    2881           1 :         return nullptr;
    2882             :     }
    2883           8 :     return poFieldDomain->GetGlob().c_str();
    2884             : }

Generated by: LCOV version 1.14