Coverage Report

Created: 2026-04-01 06:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/ogr/ogr_feature.h
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Project:  OpenGIS Simple Features Reference Implementation
4
 * Purpose:  Class for representing a whole feature, and layer schemas.
5
 * Author:   Frank Warmerdam, warmerdam@pobox.com
6
 *
7
 ******************************************************************************
8
 * Copyright (c) 1999,  Les Technologies SoftMap Inc.
9
 * Copyright (c) 2008-2013, Even Rouault <even dot rouault at spatialys.com>
10
 *
11
 * SPDX-License-Identifier: MIT
12
 ****************************************************************************/
13
14
#ifndef OGR_FEATURE_H_INCLUDED
15
#define OGR_FEATURE_H_INCLUDED
16
17
#include "cpl_atomic_ops.h"
18
#include "gdal_fwd.h"
19
#include "ogr_featurestyle.h"
20
#include "ogr_geometry.h"
21
#include "ogr_geomcoordinateprecision.h"
22
23
#include <cstddef>
24
25
#include <exception>
26
#include <memory>
27
#include <string>
28
#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
29
#include <string_view>
30
#endif
31
#include <vector>
32
33
/**
34
 * \file ogr_feature.h
35
 *
36
 * Simple feature classes.
37
 */
38
39
class OGRStyleTable;
40
41
/************************************************************************/
42
/*                             OGRFieldDefn                             */
43
/************************************************************************/
44
45
/**
46
 * Definition of an attribute of an OGRFeatureDefn. A field is described by :
47
 * <ul>
48
 * <li>a name. See SetName() / GetNameRef()</li>
49
 * <li>an alternative name (optional): alternative descriptive name for the
50
 * field (sometimes referred to as an "alias"). See SetAlternativeName() /
51
 * GetAlternativeNameRef()</li> <li>a type: OFTString, OFTInteger, OFTReal, ...
52
 * See SetType() / GetType()</li> <li>a subtype (optional): OFSTBoolean, ... See
53
 * SetSubType() / GetSubType()</li> <li>a width (optional): maximal number of
54
 * characters. See SetWidth() / GetWidth()</li> <li>a precision (optional):
55
 * number of digits after decimal point. See SetPrecision() /
56
 * GetPrecision()</li> <li>a NOT NULL constraint (optional). See SetNullable() /
57
 * IsNullable()</li> <li>a UNIQUE constraint (optional). See SetUnique() /
58
 * IsUnique()</li> <li>a default value (optional).  See SetDefault() /
59
 * GetDefault()</li> <li>a boolean to indicate whether it should be ignored when
60
 * retrieving features.  See SetIgnored() / IsIgnored()</li> <li>a field domain
61
 * name (optional). See SetDomainName() / Get DomainName()</li>
62
 * </ul>
63
 *
64
 * Note that once a OGRFieldDefn has been added to a layer definition with
65
 * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
66
 * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
67
 * OGRLayer::AlterFieldDefn() should be called on a new instance of
68
 * OGRFieldDefn, for drivers that support AlterFieldDefn().
69
 */
70
71
class CPL_DLL OGRFieldDefn
72
{
73
  private:
74
    char *pszName;
75
    char *pszAlternativeName;
76
    OGRFieldType eType;
77
    OGRJustification eJustify;
78
    int nWidth;  // Zero is variable.
79
    int nPrecision;
80
    char *pszDefault;
81
82
    int bIgnore;
83
    OGRFieldSubType eSubType;
84
85
    int bNullable;
86
    int bUnique;
87
88
    // Used by drivers (GPKG) to track generated fields
89
    bool m_bGenerated = false;
90
91
    std::string m_osDomainName{};  // field domain name. Might be empty
92
93
    std::string m_osComment{};  // field comment. Might be empty
94
95
    int m_nTZFlag = OGR_TZFLAG_UNKNOWN;
96
    bool m_bSealed = false;
97
98
  public:
99
    OGRFieldDefn(const char *, OGRFieldType);
100
    explicit OGRFieldDefn(const OGRFieldDefn *);
101
    ~OGRFieldDefn();
102
103
    // Copy constructor
104
    OGRFieldDefn(const OGRFieldDefn &oOther);
105
106
    // Copy assignment operator
107
    OGRFieldDefn &operator=(const OGRFieldDefn &oOther);
108
109
    void SetName(const char *);
110
111
    const char *GetNameRef() const
112
0
    {
113
0
        return pszName;
114
0
    }
115
116
    void SetAlternativeName(const char *);
117
118
    const char *GetAlternativeNameRef() const
119
0
    {
120
0
        return pszAlternativeName;
121
0
    }
122
123
    OGRFieldType GetType() const
124
0
    {
125
0
        return eType;
126
0
    }
127
128
    void SetType(OGRFieldType eTypeIn);
129
    static const char *GetFieldTypeName(OGRFieldType);
130
    static OGRFieldType GetFieldTypeByName(const char *);
131
132
    OGRFieldSubType GetSubType() const
133
0
    {
134
0
        return eSubType;
135
0
    }
136
137
    void SetSubType(OGRFieldSubType eSubTypeIn);
138
    static const char *GetFieldSubTypeName(OGRFieldSubType);
139
    static OGRFieldSubType GetFieldSubTypeByName(const char *);
140
141
    OGRJustification GetJustify() const
142
0
    {
143
0
        return eJustify;
144
0
    }
145
146
    void SetJustify(OGRJustification eJustifyIn)
147
0
    {
148
0
        eJustify = eJustifyIn;
149
0
    }
150
151
    int GetWidth() const
152
0
    {
153
0
        return nWidth;
154
0
    }
155
156
    void SetWidth(int nWidthIn);
157
158
    int GetPrecision() const
159
0
    {
160
0
        return nPrecision;
161
0
    }
162
163
    void SetPrecision(int nPrecisionIn);
164
165
    int GetTZFlag() const
166
0
    {
167
0
        return m_nTZFlag;
168
0
    }
169
170
    void SetTZFlag(int nTZFlag);
171
172
    void Set(const char *, OGRFieldType, int = 0, int = 0,
173
             OGRJustification = OJUndefined);
174
175
    void SetDefault(const char *);
176
    const char *GetDefault() const;
177
    int IsDefaultDriverSpecific() const;
178
179
    int IsIgnored() const
180
0
    {
181
0
        return bIgnore;
182
0
    }
183
184
    void SetIgnored(int bIgnoreIn)
185
0
    {
186
0
        bIgnore = bIgnoreIn;
187
0
    }
188
189
    int IsNullable() const
190
0
    {
191
0
        return bNullable;
192
0
    }
193
194
    void SetNullable(int bNullableIn);
195
196
    int IsUnique() const
197
0
    {
198
0
        return bUnique;
199
0
    }
200
201
    /**
202
     * @brief Return whether the field is a generated field.
203
     *
204
     * At time of writing, only the GeoPackage and PG drivers fill that information. Consequently,
205
     * only a returned value equal to TRUE can be fully trusted.
206
     * @return TRUE if the field is a generated field, FALSE otherwise.
207
     * @since GDAL 3.11
208
     */
209
    bool IsGenerated() const
210
0
    {
211
0
        return m_bGenerated;
212
0
    }
213
214
    /**
215
     * @brief SetGenerated set the field generated status.
216
     * @param bGeneratedIn TRUE if the field is a generated field, FALSE otherwise.
217
     * @since GDAL 3.11
218
     */
219
    void SetGenerated(bool bGeneratedIn)
220
0
    {
221
0
        m_bGenerated = bGeneratedIn;
222
0
    }
223
224
    void SetUnique(int bUniqueIn);
225
226
    const std::string &GetDomainName() const
227
0
    {
228
0
        return m_osDomainName;
229
0
    }
230
231
    void SetDomainName(const std::string &osDomainName);
232
233
    const std::string &GetComment() const
234
0
    {
235
0
        return m_osComment;
236
0
    }
237
238
    void SetComment(const std::string &osComment);
239
240
    int IsSame(const OGRFieldDefn *) const;
241
242
    /** Convert a OGRFieldDefn* to a OGRFieldDefnH.
243
     */
244
    static inline OGRFieldDefnH ToHandle(OGRFieldDefn *poFieldDefn)
245
0
    {
246
0
        return reinterpret_cast<OGRFieldDefnH>(poFieldDefn);
247
0
    }
248
249
    /** Convert a OGRFieldDefnH to a OGRFieldDefn*.
250
     */
251
    static inline OGRFieldDefn *FromHandle(OGRFieldDefnH hFieldDefn)
252
0
    {
253
0
        return reinterpret_cast<OGRFieldDefn *>(hFieldDefn);
254
0
    }
Unexecuted instantiation: OGRFieldDefn::FromHandle(OGRFieldDefnHS*)
Unexecuted instantiation: OGRFieldDefn::FromHandle(void*)
255
256
    void Seal();
257
258
    void Unseal();
259
260
    /*! @cond Doxygen_Suppress */
261
    struct CPL_DLL TemporaryUnsealer
262
    {
263
      private:
264
        OGRFieldDefn *m_poFieldDefn = nullptr;
265
        CPL_DISALLOW_COPY_ASSIGN(TemporaryUnsealer)
266
      public:
267
        explicit TemporaryUnsealer(OGRFieldDefn *poFieldDefn)
268
0
            : m_poFieldDefn(poFieldDefn)
269
0
        {
270
0
            m_poFieldDefn->Unseal();
271
0
        }
272
273
        TemporaryUnsealer(TemporaryUnsealer &&) = default;
274
        TemporaryUnsealer &operator=(TemporaryUnsealer &&) = default;
275
276
        ~TemporaryUnsealer()
277
0
        {
278
0
            m_poFieldDefn->Seal();
279
0
        }
280
281
        OGRFieldDefn *operator->()
282
0
        {
283
0
            return m_poFieldDefn;
284
0
        }
285
    };
286
287
    /*! @endcond */
288
289
    TemporaryUnsealer GetTemporaryUnsealer();
290
};
291
292
#ifdef GDAL_COMPILATION
293
/** Return an object that temporary unseals the OGRFieldDefn.
294
 *
295
 * The returned object calls Unseal() initially, and when it is destroyed
296
 * it calls Seal().
297
 *
298
 * This method should only be called by driver implementations.
299
 *
300
 * Usage: whileUnsealing(poFieldDefn)->some_method();
301
 *
302
 * @since GDAL 3.9
303
 */
304
inline OGRFieldDefn::TemporaryUnsealer whileUnsealing(OGRFieldDefn *object)
305
0
{
306
0
    return object->GetTemporaryUnsealer();
307
0
}
308
#endif
309
310
/************************************************************************/
311
/*                           OGRGeomFieldDefn                           */
312
/************************************************************************/
313
314
/**
315
 * Definition of a geometry field of an OGRFeatureDefn. A geometry field is
316
 * described by :
317
 * <ul>
318
 * <li>a name. See SetName() / GetNameRef()</li>
319
 * <li>a type: wkbPoint, wkbLineString, ... See SetType() / GetType()</li>
320
 * <li>a spatial reference system (optional). See SetSpatialRef() /
321
 * GetSpatialRef()</li> <li>a NOT NULL constraint (optional). See SetNullable()
322
 * / IsNullable()</li> <li>a boolean to indicate whether it should be ignored
323
 * when retrieving features.  See SetIgnored() / IsIgnored()</li>
324
 * </ul>
325
 *
326
 * Note that once a OGRGeomFieldDefn has been added to a layer definition with
327
 * OGRLayer::AddGeomFieldDefn(), its setter methods should not be called on the
328
 * object returned with OGRLayer::GetLayerDefn()->GetGeomFieldDefn(). Instead,
329
 * OGRLayer::AlterGeomFieldDefn() should be called on a new instance of
330
 * OGRFieldDefn, for drivers that support AlterFieldDefn().
331
 *
332
 */
333
334
class CPL_DLL OGRGeomFieldDefn
335
{
336
  protected:
337
    //! @cond Doxygen_Suppress
338
    char *pszName = nullptr;
339
    OGRwkbGeometryType eGeomType =
340
        wkbUnknown; /* all values possible except wkbNone */
341
    mutable const OGRSpatialReference *poSRS = nullptr;
342
343
    int bIgnore = false;
344
    mutable int bNullable = true;
345
    bool m_bSealed = false;
346
    OGRGeomCoordinatePrecision m_oCoordPrecision{};
347
348
    void Initialize(const char *, OGRwkbGeometryType);
349
    //! @endcond
350
351
  public:
352
    OGRGeomFieldDefn(const char *pszNameIn, OGRwkbGeometryType eGeomTypeIn);
353
    explicit OGRGeomFieldDefn(const OGRGeomFieldDefn *);
354
    virtual ~OGRGeomFieldDefn();
355
356
    // Copy constructor
357
    OGRGeomFieldDefn(const OGRGeomFieldDefn &oOther);
358
359
    // Move constructor
360
    OGRGeomFieldDefn(OGRGeomFieldDefn &&oOther);
361
362
    // Copy assignment operator
363
    OGRGeomFieldDefn &operator=(const OGRGeomFieldDefn &oOther);
364
365
    // Move assignment operator
366
    OGRGeomFieldDefn &operator=(OGRGeomFieldDefn &&oOther);
367
368
    void SetName(const char *);
369
370
    const char *GetNameRef() const
371
0
    {
372
0
        return pszName;
373
0
    }
374
375
    OGRwkbGeometryType GetType() const
376
0
    {
377
0
        return eGeomType;
378
0
    }
379
380
    void SetType(OGRwkbGeometryType eTypeIn);
381
382
    virtual const OGRSpatialReference *GetSpatialRef() const;
383
    void SetSpatialRef(const OGRSpatialReference *poSRSIn);
384
385
    int IsIgnored() const
386
0
    {
387
0
        return bIgnore;
388
0
    }
389
390
    void SetIgnored(int bIgnoreIn)
391
0
    {
392
0
        bIgnore = bIgnoreIn;
393
0
    }
394
395
    int IsNullable() const
396
0
    {
397
0
        return bNullable;
398
0
    }
399
400
    void SetNullable(int bNullableIn);
401
402
    const OGRGeomCoordinatePrecision &GetCoordinatePrecision() const
403
0
    {
404
0
        return m_oCoordPrecision;
405
0
    }
406
407
    void SetCoordinatePrecision(const OGRGeomCoordinatePrecision &prec);
408
409
    int IsSame(const OGRGeomFieldDefn *) const;
410
411
    /** Convert a OGRGeomFieldDefn* to a OGRGeomFieldDefnH.
412
     */
413
    static inline OGRGeomFieldDefnH ToHandle(OGRGeomFieldDefn *poGeomFieldDefn)
414
0
    {
415
0
        return reinterpret_cast<OGRGeomFieldDefnH>(poGeomFieldDefn);
416
0
    }
417
418
    /** Convert a OGRGeomFieldDefnH to a OGRGeomFieldDefn*.
419
     */
420
    static inline OGRGeomFieldDefn *FromHandle(OGRGeomFieldDefnH hGeomFieldDefn)
421
0
    {
422
0
        return reinterpret_cast<OGRGeomFieldDefn *>(hGeomFieldDefn);
423
0
    }
424
425
    void Seal();
426
427
    void Unseal();
428
429
    /*! @cond Doxygen_Suppress */
430
    struct CPL_DLL TemporaryUnsealer
431
    {
432
      private:
433
        OGRGeomFieldDefn *m_poFieldDefn = nullptr;
434
        CPL_DISALLOW_COPY_ASSIGN(TemporaryUnsealer)
435
      public:
436
        explicit TemporaryUnsealer(OGRGeomFieldDefn *poFieldDefn)
437
0
            : m_poFieldDefn(poFieldDefn)
438
0
        {
439
0
            m_poFieldDefn->Unseal();
440
0
        }
441
442
        TemporaryUnsealer(TemporaryUnsealer &&) = default;
443
        TemporaryUnsealer &operator=(TemporaryUnsealer &&) = default;
444
445
        ~TemporaryUnsealer()
446
0
        {
447
0
            m_poFieldDefn->Seal();
448
0
        }
449
450
        OGRGeomFieldDefn *operator->()
451
0
        {
452
0
            return m_poFieldDefn;
453
0
        }
454
    };
455
456
    /*! @endcond */
457
458
    TemporaryUnsealer GetTemporaryUnsealer();
459
};
460
461
#ifdef GDAL_COMPILATION
462
/** Return an object that temporary unseals the OGRGeomFieldDefn.
463
 *
464
 * The returned object calls Unseal() initially, and when it is destroyed
465
 * it calls Seal().
466
 *
467
 * This method should only be called by driver implementations.
468
 *
469
 * Usage: whileUnsealing(poGeomFieldDefn)->some_method();
470
 *
471
 * @since GDAL 3.9
472
 */
473
inline OGRGeomFieldDefn::TemporaryUnsealer
474
whileUnsealing(OGRGeomFieldDefn *object)
475
0
{
476
0
    return object->GetTemporaryUnsealer();
477
0
}
478
#endif
479
480
/************************************************************************/
481
/*                            OGRFeatureDefn                            */
482
/************************************************************************/
483
484
/**
485
 * Definition of a feature class or feature layer.
486
 *
487
 * This object contains schema information for a set of OGRFeatures.  In
488
 * table based systems, an OGRFeatureDefn is essentially a layer.  In more
489
 * object oriented approaches (such as SF CORBA) this can represent a class
490
 * of features but doesn't necessarily relate to all of a layer, or just one
491
 * layer.
492
 *
493
 * This object also can contain some other information such as a name and
494
 * potentially other metadata.
495
 *
496
 * It is essentially a collection of field descriptions (OGRFieldDefn class).
497
 * In addition to attribute fields, it can also
498
 * contain multiple geometry fields (OGRGeomFieldDefn class).
499
 *
500
 * It is reasonable for different translators to derive classes from
501
 * OGRFeatureDefn with additional translator specific information.
502
 *
503
 * Note that adding, modifying, removing, reordering a OGRFieldDefn (or a
504
 * OGRGeomFieldDefn) from/to a OGRFeatureDefn that belongs to a OGRLayer should
505
 * not be done through the OGRFeatureDefn::AddFieldDefn(),
506
 * OGRFeatureDefn::DeleteFieldDefn() or OGRFeatureDefn::ReorderFieldDefns()
507
 * methods, but rather through OGRLayer::CreateField(),
508
 * OGRLayer::AlterFieldDefn() or OGRLayer::ReorderFields(), for drivers that
509
 * support those operations.
510
 */
511
512
class CPL_DLL OGRFeatureDefn
513
{
514
  protected:
515
    //! @cond Doxygen_Suppress
516
    volatile int nRefCount = 0;
517
518
    mutable std::vector<std::unique_ptr<OGRFieldDefn>> apoFieldDefn{};
519
    mutable std::vector<std::unique_ptr<OGRGeomFieldDefn>> apoGeomFieldDefn{};
520
521
    char *pszFeatureClassName = nullptr;
522
523
    bool bIgnoreStyle = false;
524
525
    friend class TemporaryUnsealer;
526
    bool m_bSealed = false;
527
    int m_nTemporaryUnsealCount = 0;
528
    //! @endcond
529
530
  public:
531
    explicit OGRFeatureDefn(const char *pszName = nullptr);
532
    virtual ~OGRFeatureDefn();
533
534
    void SetName(const char *pszName);
535
    virtual const char *GetName() const;
536
537
    virtual int GetFieldCount() const;
538
    virtual OGRFieldDefn *GetFieldDefn(int i);
539
    virtual const OGRFieldDefn *GetFieldDefn(int i) const;
540
    virtual int GetFieldIndex(const char *) const;
541
    int GetFieldIndexCaseSensitive(const char *) const;
542
543
    //! @cond Doxygen_Suppress
544
    /** Helper class to iterate over non-geometry fields.
545
     *
546
     * Note: fields should not be added or removed while iterating over them.
547
     */
548
    template <class OwnerT, class ChildT> struct CPL_DLL Fields
549
    {
550
      private:
551
        OwnerT m_poFDefn;
552
553
      public:
554
0
        inline explicit Fields(OwnerT poFDefn) : m_poFDefn(poFDefn)
555
0
        {
556
0
        }
Unexecuted instantiation: OGRFeatureDefn::Fields<OGRFeatureDefn const*, OGRFieldDefn const*>::Fields(OGRFeatureDefn const*)
Unexecuted instantiation: OGRFeatureDefn::Fields<OGRFeatureDefn*, OGRFieldDefn*>::Fields(OGRFeatureDefn*)
557
558
        struct CPL_DLL Iterator
559
        {
560
          private:
561
            OwnerT m_poFDefn;
562
            int m_nIdx;
563
564
          public:
565
            inline Iterator(OwnerT poFDefn, int nIdx)
566
0
                : m_poFDefn(poFDefn), m_nIdx(nIdx)
567
0
            {
568
0
            }
Unexecuted instantiation: OGRFeatureDefn::Fields<OGRFeatureDefn const*, OGRFieldDefn const*>::Iterator::Iterator(OGRFeatureDefn const*, int)
Unexecuted instantiation: OGRFeatureDefn::Fields<OGRFeatureDefn*, OGRFieldDefn*>::Iterator::Iterator(OGRFeatureDefn*, int)
569
570
            inline ChildT operator*() const
571
0
            {
572
0
                return m_poFDefn->GetFieldDefn(m_nIdx);
573
0
            }
Unexecuted instantiation: OGRFeatureDefn::Fields<OGRFeatureDefn const*, OGRFieldDefn const*>::Iterator::operator*() const
Unexecuted instantiation: OGRFeatureDefn::Fields<OGRFeatureDefn*, OGRFieldDefn*>::Iterator::operator*() const
574
575
            inline Iterator &operator++()
576
0
            {
577
0
                m_nIdx++;
578
0
                return *this;
579
0
            }
Unexecuted instantiation: OGRFeatureDefn::Fields<OGRFeatureDefn const*, OGRFieldDefn const*>::Iterator::operator++()
Unexecuted instantiation: OGRFeatureDefn::Fields<OGRFeatureDefn*, OGRFieldDefn*>::Iterator::operator++()
580
581
            inline bool operator!=(const Iterator &it) const
582
0
            {
583
0
                return m_nIdx != it.m_nIdx;
584
0
            }
Unexecuted instantiation: OGRFeatureDefn::Fields<OGRFeatureDefn const*, OGRFieldDefn const*>::Iterator::operator!=(OGRFeatureDefn::Fields<OGRFeatureDefn const*, OGRFieldDefn const*>::Iterator const&) const
Unexecuted instantiation: OGRFeatureDefn::Fields<OGRFeatureDefn*, OGRFieldDefn*>::Iterator::operator!=(OGRFeatureDefn::Fields<OGRFeatureDefn*, OGRFieldDefn*>::Iterator const&) const
585
        };
586
587
        inline Iterator begin()
588
0
        {
589
0
            return Iterator(m_poFDefn, 0);
590
0
        }
Unexecuted instantiation: OGRFeatureDefn::Fields<OGRFeatureDefn const*, OGRFieldDefn const*>::begin()
Unexecuted instantiation: OGRFeatureDefn::Fields<OGRFeatureDefn*, OGRFieldDefn*>::begin()
591
592
        inline Iterator end()
593
0
        {
594
0
            return Iterator(m_poFDefn, m_poFDefn->GetFieldCount());
595
0
        }
Unexecuted instantiation: OGRFeatureDefn::Fields<OGRFeatureDefn const*, OGRFieldDefn const*>::end()
Unexecuted instantiation: OGRFeatureDefn::Fields<OGRFeatureDefn*, OGRFieldDefn*>::end()
596
597
        inline size_t size() const
598
        {
599
            return static_cast<std::size_t>(m_poFDefn->GetFieldCount());
600
        }
601
602
        inline ChildT operator[](size_t i)
603
        {
604
            return m_poFDefn->GetFieldDefn(static_cast<int>(i));
605
        }
606
    };
607
608
    //! @endcond
609
610
    /** Return type of GetFields() */
611
    using NonConstFields = Fields<OGRFeatureDefn *, OGRFieldDefn *>;
612
613
    /** Return an object that can be used to iterate over non-geometry fields.
614
        \verbatim
615
        for( const auto* poFieldDefn: poFeatureDefn->GetFields() )
616
        {
617
            // do something
618
        }
619
        \endverbatim
620
621
        @since GDAL 3.7
622
     */
623
    inline NonConstFields GetFields()
624
0
    {
625
0
        return NonConstFields(this);
626
0
    }
627
628
    /** Return type of GetFields() const */
629
    using ConstFields = Fields<const OGRFeatureDefn *, const OGRFieldDefn *>;
630
631
    /** Return an object that can be used to iterate over non-geometry fields.
632
        \verbatim
633
        for( const auto* poFieldDefn: poFeatureDefn->GetFields() )
634
        {
635
            // do something
636
        }
637
        \endverbatim
638
639
        @since GDAL 3.12
640
     */
641
    inline ConstFields GetFields() const
642
0
    {
643
0
        return ConstFields(this);
644
0
    }
645
646
    //! @cond Doxygen_Suppress
647
    // That method should only be called if there's a guarantee that
648
    // GetFieldCount() has been called before
649
    int GetFieldCountUnsafe() const
650
0
    {
651
0
        return static_cast<int>(apoFieldDefn.size());
652
0
    }
653
654
    // Those methods don't check i is n range.
655
    OGRFieldDefn *GetFieldDefnUnsafe(int i)
656
0
    {
657
0
        if (apoFieldDefn.empty())
658
0
            GetFieldDefn(i);
659
0
        return apoFieldDefn[static_cast<std::size_t>(i)].get();
660
0
    }
661
662
    const OGRFieldDefn *GetFieldDefnUnsafe(int i) const
663
0
    {
664
0
        if (apoFieldDefn.empty())
665
0
            GetFieldDefn(i);
666
0
        return apoFieldDefn[static_cast<std::size_t>(i)].get();
667
0
    }
668
669
    //! @endcond
670
671
    virtual void AddFieldDefn(const OGRFieldDefn *);
672
    virtual OGRErr DeleteFieldDefn(int iField);
673
674
    /**
675
     * @brief StealFieldDefn takes ownership of the field definition at index detaching
676
     *        it from the feature definition.
677
     * This is an advanced method designed to be only used for driver implementations.
678
     * @param iField index of the field definition to detach.
679
     * @return a unique pointer to the detached field definition or nullptr if the index is out of range.
680
     * @since GDAL 3.11
681
     */
682
    virtual std::unique_ptr<OGRFieldDefn> StealFieldDefn(int iField);
683
684
    virtual void AddFieldDefn(std::unique_ptr<OGRFieldDefn> &&poFieldDefn);
685
686
    virtual OGRErr ReorderFieldDefns(const int *panMap);
687
688
    /**
689
     * @brief StealGeomFieldDefn takes ownership of the the geometry field definition at index
690
     *        detaching it from the feature definition.
691
     * This is an advanced method designed to be only used for driver implementations.
692
     * @param iField index of the geometry field definition to detach.
693
     * @return a unique pointer to the detached geometry field definition or nullptr if the index is out of range.
694
     * @since GDAL 3.11
695
     */
696
    virtual std::unique_ptr<OGRGeomFieldDefn> StealGeomFieldDefn(int iField);
697
698
    virtual int GetGeomFieldCount() const;
699
    virtual OGRGeomFieldDefn *GetGeomFieldDefn(int i);
700
    virtual const OGRGeomFieldDefn *GetGeomFieldDefn(int i) const;
701
    virtual int GetGeomFieldIndex(const char *) const;
702
703
    //! @cond Doxygen_Suppress
704
    /** Helper class to iterate over geometry fields.
705
     *
706
     * Note: fields should not be added or removed while iterating over them.
707
     */
708
    template <class OwnerT, class ChildT> struct CPL_DLL GeomFields
709
    {
710
      private:
711
        OwnerT m_poFDefn;
712
713
      public:
714
0
        inline explicit GeomFields(OwnerT poFDefn) : m_poFDefn(poFDefn)
715
0
        {
716
0
        }
Unexecuted instantiation: OGRFeatureDefn::GeomFields<OGRFeatureDefn const*, OGRGeomFieldDefn const*>::GeomFields(OGRFeatureDefn const*)
Unexecuted instantiation: OGRFeatureDefn::GeomFields<OGRFeatureDefn*, OGRGeomFieldDefn*>::GeomFields(OGRFeatureDefn*)
717
718
        struct CPL_DLL Iterator
719
        {
720
          private:
721
            OwnerT m_poFDefn;
722
            int m_nIdx;
723
724
          public:
725
            inline Iterator(OwnerT poFDefn, int nIdx)
726
0
                : m_poFDefn(poFDefn), m_nIdx(nIdx)
727
0
            {
728
0
            }
Unexecuted instantiation: OGRFeatureDefn::GeomFields<OGRFeatureDefn const*, OGRGeomFieldDefn const*>::Iterator::Iterator(OGRFeatureDefn const*, int)
Unexecuted instantiation: OGRFeatureDefn::GeomFields<OGRFeatureDefn*, OGRGeomFieldDefn*>::Iterator::Iterator(OGRFeatureDefn*, int)
729
730
            inline ChildT operator*() const
731
0
            {
732
0
                return m_poFDefn->GetGeomFieldDefn(m_nIdx);
733
0
            }
Unexecuted instantiation: OGRFeatureDefn::GeomFields<OGRFeatureDefn const*, OGRGeomFieldDefn const*>::Iterator::operator*() const
Unexecuted instantiation: OGRFeatureDefn::GeomFields<OGRFeatureDefn*, OGRGeomFieldDefn*>::Iterator::operator*() const
734
735
            inline Iterator &operator++()
736
0
            {
737
0
                m_nIdx++;
738
0
                return *this;
739
0
            }
Unexecuted instantiation: OGRFeatureDefn::GeomFields<OGRFeatureDefn const*, OGRGeomFieldDefn const*>::Iterator::operator++()
Unexecuted instantiation: OGRFeatureDefn::GeomFields<OGRFeatureDefn*, OGRGeomFieldDefn*>::Iterator::operator++()
740
741
            inline bool operator!=(const Iterator &it) const
742
0
            {
743
0
                return m_nIdx != it.m_nIdx;
744
0
            }
Unexecuted instantiation: OGRFeatureDefn::GeomFields<OGRFeatureDefn const*, OGRGeomFieldDefn const*>::Iterator::operator!=(OGRFeatureDefn::GeomFields<OGRFeatureDefn const*, OGRGeomFieldDefn const*>::Iterator const&) const
Unexecuted instantiation: OGRFeatureDefn::GeomFields<OGRFeatureDefn*, OGRGeomFieldDefn*>::Iterator::operator!=(OGRFeatureDefn::GeomFields<OGRFeatureDefn*, OGRGeomFieldDefn*>::Iterator const&) const
745
        };
746
747
        inline Iterator begin()
748
0
        {
749
0
            return Iterator(m_poFDefn, 0);
750
0
        }
Unexecuted instantiation: OGRFeatureDefn::GeomFields<OGRFeatureDefn const*, OGRGeomFieldDefn const*>::begin()
Unexecuted instantiation: OGRFeatureDefn::GeomFields<OGRFeatureDefn*, OGRGeomFieldDefn*>::begin()
751
752
        inline Iterator end()
753
0
        {
754
0
            return Iterator(m_poFDefn, m_poFDefn->GetGeomFieldCount());
755
0
        }
Unexecuted instantiation: OGRFeatureDefn::GeomFields<OGRFeatureDefn const*, OGRGeomFieldDefn const*>::end()
Unexecuted instantiation: OGRFeatureDefn::GeomFields<OGRFeatureDefn*, OGRGeomFieldDefn*>::end()
756
757
        inline size_t size() const
758
        {
759
            return static_cast<std::size_t>(m_poFDefn->GetGeomFieldCount());
760
        }
761
762
        inline ChildT operator[](size_t i) const
763
        {
764
            return m_poFDefn->GetGeomFieldDefn(static_cast<int>(i));
765
        }
766
    };
767
768
    //! @endcond
769
770
    /** Return type of GetGeomFields() */
771
    using NonConstGeomFields = GeomFields<OGRFeatureDefn *, OGRGeomFieldDefn *>;
772
773
    /** Return an object that can be used to iterate over geometry fields.
774
        \verbatim
775
        for( const auto* poGeomFieldDefn: poFeatureDefn->GetGeomFields() )
776
        {
777
            // do something
778
        }
779
        \endverbatim
780
781
        @since GDAL 3.7
782
     */
783
    inline NonConstGeomFields GetGeomFields()
784
0
    {
785
0
        return NonConstGeomFields(this);
786
0
    }
787
788
    /** Return type of GetGeomFields() const */
789
    using ConstGeomFields =
790
        GeomFields<const OGRFeatureDefn *, const OGRGeomFieldDefn *>;
791
792
    /** Return an object that can be used to iterate over geometry fields.
793
        \verbatim
794
        for( const auto* poGeomFieldDefn: poFeatureDefn->GetGeomFields() )
795
        {
796
            // do something
797
        }
798
        \endverbatim
799
800
        @since GDAL 3.12
801
     */
802
    inline ConstGeomFields GetGeomFields() const
803
0
    {
804
0
        return ConstGeomFields(this);
805
0
    }
806
807
    virtual void AddGeomFieldDefn(const OGRGeomFieldDefn *);
808
    virtual void AddGeomFieldDefn(std::unique_ptr<OGRGeomFieldDefn> &&);
809
    virtual OGRErr DeleteGeomFieldDefn(int iGeomField);
810
811
    virtual OGRwkbGeometryType GetGeomType() const;
812
    virtual void SetGeomType(OGRwkbGeometryType);
813
814
    virtual OGRFeatureDefn *Clone() const;
815
816
    int Reference()
817
0
    {
818
0
        return CPLAtomicInc(&nRefCount);
819
0
    }
820
821
    int Dereference()
822
#if defined(GDAL_COMPILATION) && !defined(DOXYGEN_XML)
823
        CPL_WARN_DEPRECATED("Use Release() instead")
824
#endif
825
0
    {
826
0
        return CPLAtomicDec(&nRefCount);
827
0
    }
828
829
    int GetReferenceCount() const
830
0
    {
831
0
        return nRefCount;
832
0
    }
833
834
    void Release();
835
836
    virtual int IsGeometryIgnored() const;
837
    virtual void SetGeometryIgnored(int bIgnore);
838
839
    virtual bool IsStyleIgnored() const
840
0
    {
841
0
        return bIgnoreStyle;
842
0
    }
843
844
    virtual void SetStyleIgnored(bool bIgnore)
845
0
    {
846
0
        bIgnoreStyle = bIgnore;
847
0
    }
848
849
    virtual int IsSame(const OGRFeatureDefn *poOtherFeatureDefn) const;
850
851
    //! @cond Doxygen_Suppress
852
    void ReserveSpaceForFields(int nFieldCountIn);
853
    //! @endcond
854
855
    std::vector<int> ComputeMapForSetFrom(const OGRFeatureDefn *poSrcFDefn,
856
                                          bool bForgiving = true) const;
857
858
    static OGRFeatureDefn *CreateFeatureDefn(const char *pszName = nullptr);
859
    static void DestroyFeatureDefn(OGRFeatureDefn *);
860
861
    /** Convert a OGRFeatureDefn* to a OGRFeatureDefnH.
862
     */
863
    static inline OGRFeatureDefnH ToHandle(OGRFeatureDefn *poFeatureDefn)
864
0
    {
865
0
        return reinterpret_cast<OGRFeatureDefnH>(poFeatureDefn);
866
0
    }
867
868
    /** Convert a OGRFeatureDefnH to a OGRFeatureDefn*.
869
     */
870
    static inline OGRFeatureDefn *FromHandle(OGRFeatureDefnH hFeatureDefn)
871
0
    {
872
0
        return reinterpret_cast<OGRFeatureDefn *>(hFeatureDefn);
873
0
    }
Unexecuted instantiation: OGRFeatureDefn::FromHandle(OGRFeatureDefnHS*)
Unexecuted instantiation: OGRFeatureDefn::FromHandle(void*)
874
875
    void Seal(bool bSealFields);
876
877
    void Unseal(bool bUnsealFields);
878
879
    /*! @cond Doxygen_Suppress */
880
    struct CPL_DLL TemporaryUnsealer
881
    {
882
      private:
883
        OGRFeatureDefn *m_poFeatureDefn = nullptr;
884
        bool m_bSealFields = false;
885
        CPL_DISALLOW_COPY_ASSIGN(TemporaryUnsealer)
886
      public:
887
        explicit TemporaryUnsealer(OGRFeatureDefn *poFeatureDefn,
888
                                   bool bSealFields);
889
890
        TemporaryUnsealer(TemporaryUnsealer &&) = default;
891
        TemporaryUnsealer &operator=(TemporaryUnsealer &&) = default;
892
893
        ~TemporaryUnsealer();
894
895
        OGRFeatureDefn *operator->()
896
0
        {
897
0
            return m_poFeatureDefn;
898
0
        }
899
    };
900
901
    /*! @endcond */
902
903
    TemporaryUnsealer GetTemporaryUnsealer(bool bSealFields = true);
904
905
  private:
906
    CPL_DISALLOW_COPY_ASSIGN(OGRFeatureDefn)
907
};
908
909
#ifdef GDAL_COMPILATION
910
/** Return an object that temporary unseals the OGRFeatureDefn
911
 *
912
 * The returned object calls Unseal() initially, and when it is destroyed
913
 * it calls Seal().
914
 * This method should be called on a OGRFeatureDefn that has been sealed
915
 * previously.
916
 * GetTemporaryUnsealer() calls may be nested, in which case only the first
917
 * one has an effect (similarly to a recursive mutex locked in a nested way
918
 * from the same thread).
919
 *
920
 * This method should only be called by driver implementations.
921
 *
922
 * Usage: whileUnsealing(poFeatureDefn)->some_method();
923
 *
924
 * @param bSealFields Whether fields and geometry fields should be unsealed and
925
 *                    resealed.
926
 *                    This is generally desirable, but in case of deferred
927
 *                    resolution of them, this parameter should be set to false.
928
 * @since GDAL 3.9
929
 */
930
inline OGRFeatureDefn::TemporaryUnsealer whileUnsealing(OGRFeatureDefn *object,
931
                                                        bool bSealFields = true)
932
0
{
933
0
    return object->GetTemporaryUnsealer(bSealFields);
934
0
}
935
#endif
936
937
/************************************************************************/
938
/*                              OGRFeature                              */
939
/************************************************************************/
940
941
/**
942
 * A simple feature, including geometry and attributes.
943
 */
944
945
class CPL_DLL OGRFeature
946
{
947
  private:
948
    GIntBig nFID;
949
    const OGRFeatureDefn *poDefn;
950
    OGRGeometry **papoGeometries;
951
    OGRField *pauFields;
952
    char *m_pszNativeData;
953
    char *m_pszNativeMediaType;
954
955
    bool SetFieldInternal(int i, const OGRField *puValue);
956
957
  protected:
958
    //! @cond Doxygen_Suppress
959
    mutable char *m_pszStyleString;
960
    mutable OGRStyleTable *m_poStyleTable;
961
    mutable char *m_pszTmpFieldValue;
962
    //! @endcond
963
964
    bool CopySelfTo(OGRFeature *poNew) const;
965
966
  public:
967
    explicit OGRFeature(const OGRFeatureDefn *);
968
    virtual ~OGRFeature();
969
970
    /** Field value. */
971
    class CPL_DLL FieldValue
972
    {
973
        friend class OGRFeature;
974
        struct Private;
975
        std::unique_ptr<Private> m_poPrivate;
976
977
        FieldValue(OGRFeature *poFeature, int iFieldIndex);
978
        FieldValue(const OGRFeature *poFeature, int iFieldIndex);
979
        FieldValue(const FieldValue &oOther) = delete;
980
        FieldValue &Assign(const FieldValue &oOther);
981
982
      public:
983
        //! @cond Doxygen_Suppress
984
        ~FieldValue();
985
986
        FieldValue &operator=(FieldValue &&oOther);
987
        //! @endcond
988
989
        /** Set a field value from another one. */
990
        FieldValue &operator=(const FieldValue &oOther);
991
        /** Set an integer value to the field. */
992
        FieldValue &operator=(int nVal);
993
        /** Set an integer value to the field. */
994
        FieldValue &operator=(GIntBig nVal);
995
        /** Set a real value to the field. */
996
        FieldValue &operator=(double dfVal);
997
        /** Set a string value to the field. */
998
        FieldValue &operator=(const char *pszVal);
999
        /** Set a string value to the field. */
1000
        FieldValue &operator=(const std::string &osVal);
1001
        /** Set an array of integer to the field. */
1002
        FieldValue &operator=(const std::vector<int> &oArray);
1003
        /** Set an array of big integer to the field. */
1004
        FieldValue &operator=(const std::vector<GIntBig> &oArray);
1005
        /** Set an array of double to the field. */
1006
        FieldValue &operator=(const std::vector<double> &oArray);
1007
        /** Set an array of strings to the field. */
1008
        FieldValue &operator=(const std::vector<std::string> &oArray);
1009
        /** Set an array of strings to the field. */
1010
        FieldValue &operator=(CSLConstList papszValues);
1011
        /** Set a null value to the field. */
1012
        void SetNull();
1013
        /** Unset the field. */
1014
        void clear();
1015
1016
        /** Unset the field. */
1017
        void Unset()
1018
0
        {
1019
0
            clear();
1020
0
        }
1021
1022
        /** Set date time value/ */
1023
        void SetDateTime(int nYear, int nMonth, int nDay, int nHour = 0,
1024
                         int nMinute = 0, float fSecond = 0.f, int nTZFlag = 0);
1025
1026
        /** Return field index. */
1027
        int GetIndex() const;
1028
        /** Return field definition. */
1029
        const OGRFieldDefn *GetDefn() const;
1030
1031
        /** Return field name. */
1032
        const char *GetName() const
1033
0
        {
1034
0
            return GetDefn()->GetNameRef();
1035
0
        }
1036
1037
        /** Return field type. */
1038
        OGRFieldType GetType() const
1039
0
        {
1040
0
            return GetDefn()->GetType();
1041
0
        }
1042
1043
        /** Return field subtype. */
1044
        OGRFieldSubType GetSubType() const
1045
0
        {
1046
0
            return GetDefn()->GetSubType();
1047
0
        }
1048
1049
        /** Return whether the field value is unset/empty. */
1050
        // cppcheck-suppress functionStatic
1051
        bool empty() const
1052
0
        {
1053
0
            return IsUnset();
1054
0
        }
1055
1056
        /** Return whether the field value is unset/empty. */
1057
        // cppcheck-suppress functionStatic
1058
        bool IsUnset() const;
1059
1060
        /** Return whether the field value is null. */
1061
        // cppcheck-suppress functionStatic
1062
        bool IsNull() const;
1063
1064
        /** Return the raw field value */
1065
        const OGRField *GetRawValue() const;
1066
1067
        /** Return the integer value.
1068
         * Only use that method if and only if GetType() == OFTInteger.
1069
         */
1070
        // cppcheck-suppress functionStatic
1071
        int GetInteger() const
1072
0
        {
1073
0
            return GetRawValue()->Integer;
1074
0
        }
1075
1076
        /** Return the 64-bit integer value.
1077
         * Only use that method if and only if GetType() == OFTInteger64.
1078
         */
1079
        // cppcheck-suppress functionStatic
1080
        GIntBig GetInteger64() const
1081
0
        {
1082
0
            return GetRawValue()->Integer64;
1083
0
        }
1084
1085
        /** Return the double value.
1086
         * Only use that method if and only if GetType() == OFTReal.
1087
         */
1088
        // cppcheck-suppress functionStatic
1089
        double GetDouble() const
1090
0
        {
1091
0
            return GetRawValue()->Real;
1092
0
        }
1093
1094
        /** Return the string value.
1095
         * Only use that method if and only if GetType() == OFTString.
1096
         */
1097
        // cppcheck-suppress functionStatic
1098
        const char *GetString() const
1099
0
        {
1100
0
            return GetRawValue()->String;
1101
0
        }
1102
1103
        /** Return the date/time/datetime value. */
1104
        bool GetDateTime(int *pnYear, int *pnMonth, int *pnDay, int *pnHour,
1105
                         int *pnMinute, float *pfSecond, int *pnTZFlag) const;
1106
1107
        /** Return the field value as integer, with potential conversion */
1108
        operator int() const
1109
0
        {
1110
0
            return GetAsInteger();
1111
0
        }
1112
1113
        /** Return the field value as 64-bit integer, with potential conversion
1114
         */
1115
        operator GIntBig() const
1116
0
        {
1117
0
            return GetAsInteger64();
1118
0
        }
1119
1120
        /** Return the field value as double, with potential conversion */
1121
        operator double() const
1122
0
        {
1123
0
            return GetAsDouble();
1124
0
        }
1125
1126
        /** Return the field value as string, with potential conversion */
1127
        operator const char *() const
1128
0
        {
1129
0
            return GetAsString();
1130
0
        }
1131
1132
        /** Return the field value as integer list, with potential conversion */
1133
        operator const std::vector<int> &() const
1134
0
        {
1135
0
            return GetAsIntegerList();
1136
0
        }
1137
1138
        /** Return the field value as 64-bit integer list, with potential
1139
         * conversion */
1140
        operator const std::vector<GIntBig> &() const
1141
0
        {
1142
0
            return GetAsInteger64List();
1143
0
        }
1144
1145
        /** Return the field value as double list, with potential conversion */
1146
        operator const std::vector<double> &() const
1147
0
        {
1148
0
            return GetAsDoubleList();
1149
0
        }
1150
1151
        /** Return the field value as string list, with potential conversion */
1152
        operator const std::vector<std::string> &() const
1153
0
        {
1154
0
            return GetAsStringList();
1155
0
        }
1156
1157
        /** Return the field value as string list, with potential conversion */
1158
        operator CSLConstList() const;
1159
1160
        /** Return the field value as integer, with potential conversion */
1161
        int GetAsInteger() const;
1162
        /** Return the field value as 64-bit integer, with potential conversion
1163
         */
1164
        GIntBig GetAsInteger64() const;
1165
        /** Return the field value as double, with potential conversion */
1166
        double GetAsDouble() const;
1167
        /** Return the field value as string, with potential conversion */
1168
        const char *GetAsString() const;
1169
        /** Return the field value as integer list, with potential conversion */
1170
        const std::vector<int> &GetAsIntegerList() const;
1171
        /** Return the field value as 64-bit integer list, with potential
1172
         * conversion */
1173
        const std::vector<GIntBig> &GetAsInteger64List() const;
1174
        /** Return the field value as double list, with potential conversion */
1175
        const std::vector<double> &GetAsDoubleList() const;
1176
        /** Return the field value as string list, with potential conversion */
1177
        const std::vector<std::string> &GetAsStringList() const;
1178
    };
1179
1180
    /** Field value iterator class. */
1181
    class CPL_DLL ConstFieldIterator
1182
    {
1183
        friend class OGRFeature;
1184
        struct Private;
1185
        std::unique_ptr<Private> m_poPrivate;
1186
1187
        ConstFieldIterator(const OGRFeature *poSelf, int nPos);
1188
1189
      public:
1190
        //! @cond Doxygen_Suppress
1191
        ConstFieldIterator(
1192
            ConstFieldIterator &&oOther) noexcept;  // declared but not defined.
1193
        // Needed for gcc 5.4 at least
1194
        ~ConstFieldIterator();
1195
        const FieldValue &operator*() const;
1196
        ConstFieldIterator &operator++();
1197
        bool operator!=(const ConstFieldIterator &it) const;
1198
        //! @endcond
1199
    };
1200
1201
    /** Return begin of field value iterator.
1202
     *
1203
     * Using this iterator for standard range-based loops is safe, but
1204
     * due to implementation limitations, you shouldn't try to access
1205
     * (dereference) more than one iterator step at a time, since you will get
1206
     * a reference to the same object (FieldValue) at each iteration step.
1207
     *
1208
     * \code{.cpp}
1209
     * for( auto&& oField: poFeature )
1210
     * {
1211
     *      std::cout << oField.GetIndex() << "," << oField.GetName()<< ": " <<
1212
     * oField.GetAsString() << std::endl;
1213
     * }
1214
     * \endcode
1215
     *
1216
     */
1217
    ConstFieldIterator begin() const;
1218
    /** Return end of field value iterator. */
1219
    ConstFieldIterator end() const;
1220
1221
    const FieldValue operator[](int iField) const;
1222
    FieldValue operator[](int iField);
1223
1224
#if defined(__clang__)
1225
#pragma clang diagnostic push
1226
#pragma clang diagnostic ignored "-Wweak-vtables"
1227
#endif
1228
1229
    /** Exception raised by operator[](const char*) when a field is not found.
1230
     */
1231
    class FieldNotFoundException final : public std::exception
1232
    {
1233
    };
1234
1235
#if defined(__clang__)
1236
#pragma clang diagnostic pop
1237
#endif
1238
1239
    const FieldValue operator[](const char *pszFieldName) const;
1240
    FieldValue operator[](const char *pszFieldName);
1241
1242
    const OGRFeatureDefn *GetDefnRef() const
1243
0
    {
1244
0
        return poDefn;
1245
0
    }
1246
1247
    //! @cond Doxygen_Suppress
1248
    void SetFDefnUnsafe(OGRFeatureDefn *poNewFDefn);
1249
    //! @endcond
1250
1251
    OGRErr SetGeometryDirectly(OGRGeometry *);
1252
    OGRErr SetGeometry(const OGRGeometry *);
1253
    OGRErr SetGeometry(std::unique_ptr<OGRGeometry>);
1254
    OGRGeometry *GetGeometryRef();
1255
    const OGRGeometry *GetGeometryRef() const;
1256
    OGRGeometry *StealGeometry() CPL_WARN_UNUSED_RESULT;
1257
1258
    int GetGeomFieldCount() const
1259
0
    {
1260
0
        return poDefn->GetGeomFieldCount();
1261
0
    }
1262
1263
    const OGRGeomFieldDefn *GetGeomFieldDefnRef(int iField) const
1264
0
    {
1265
0
        return poDefn->GetGeomFieldDefn(iField);
1266
0
    }
1267
1268
    int GetGeomFieldIndex(const char *pszName) const
1269
0
    {
1270
0
        return poDefn->GetGeomFieldIndex(pszName);
1271
0
    }
1272
1273
    OGRGeometry *GetGeomFieldRef(int iField);
1274
    const OGRGeometry *GetGeomFieldRef(int iField) const;
1275
    OGRGeometry *StealGeometry(int iField);
1276
    OGRGeometry *GetGeomFieldRef(const char *pszFName);
1277
    const OGRGeometry *GetGeomFieldRef(const char *pszFName) const;
1278
    OGRErr SetGeomFieldDirectly(int iField, OGRGeometry *);
1279
    OGRErr SetGeomField(int iField, const OGRGeometry *);
1280
    OGRErr SetGeomField(int iField, std::unique_ptr<OGRGeometry>);
1281
1282
    void Reset();
1283
1284
    OGRFeature *Clone() const CPL_WARN_UNUSED_RESULT;
1285
    virtual OGRBoolean Equal(const OGRFeature *poFeature) const;
1286
1287
    int GetFieldCount() const
1288
0
    {
1289
0
        return poDefn->GetFieldCount();
1290
0
    }
1291
1292
    const OGRFieldDefn *GetFieldDefnRef(int iField) const
1293
0
    {
1294
0
        return poDefn->GetFieldDefn(iField);
1295
0
    }
1296
1297
    int GetFieldIndex(const char *pszName) const
1298
0
    {
1299
0
        return poDefn->GetFieldIndex(pszName);
1300
0
    }
1301
1302
    int IsFieldSet(int iField) const;
1303
1304
    void UnsetField(int iField);
1305
1306
    bool IsFieldNull(int iField) const;
1307
1308
    void SetFieldNull(int iField);
1309
1310
    bool IsFieldSetAndNotNull(int iField) const;
1311
1312
    OGRField *GetRawFieldRef(int i)
1313
0
    {
1314
0
        return pauFields + i;
1315
0
    }
1316
1317
    const OGRField *GetRawFieldRef(int i) const
1318
0
    {
1319
0
        return pauFields + i;
1320
0
    }
1321
1322
    int GetFieldAsInteger(int i) const;
1323
    GIntBig GetFieldAsInteger64(int i) const;
1324
    double GetFieldAsDouble(int i) const;
1325
    const char *GetFieldAsString(int i) const;
1326
    const char *GetFieldAsISO8601DateTime(int i,
1327
                                          CSLConstList papszOptions) const;
1328
    const int *GetFieldAsIntegerList(int i, int *pnCount) const;
1329
    const GIntBig *GetFieldAsInteger64List(int i, int *pnCount) const;
1330
    const double *GetFieldAsDoubleList(int i, int *pnCount) const;
1331
    char **GetFieldAsStringList(int i) const;
1332
    GByte *GetFieldAsBinary(int i, int *pnCount) const;
1333
    int GetFieldAsDateTime(int i, int *pnYear, int *pnMonth, int *pnDay,
1334
                           int *pnHour, int *pnMinute, int *pnSecond,
1335
                           int *pnTZFlag) const;
1336
    int GetFieldAsDateTime(int i, int *pnYear, int *pnMonth, int *pnDay,
1337
                           int *pnHour, int *pnMinute, float *pfSecond,
1338
                           int *pnTZFlag) const;
1339
    char *GetFieldAsSerializedJSon(int i) const;
1340
1341
    //! @cond Doxygen_Suppress
1342
    bool IsFieldSetUnsafe(int i) const
1343
0
    {
1344
0
        return !(pauFields[i].Set.nMarker1 == OGRUnsetMarker &&
1345
0
                 pauFields[i].Set.nMarker2 == OGRUnsetMarker &&
1346
0
                 pauFields[i].Set.nMarker3 == OGRUnsetMarker);
1347
0
    }
1348
1349
    bool IsFieldNullUnsafe(int i) const
1350
0
    {
1351
0
        return (pauFields[i].Set.nMarker1 == OGRNullMarker &&
1352
0
                pauFields[i].Set.nMarker2 == OGRNullMarker &&
1353
0
                pauFields[i].Set.nMarker3 == OGRNullMarker);
1354
0
    }
1355
1356
    bool IsFieldSetAndNotNullUnsafe(int i) const
1357
0
    {
1358
0
        return IsFieldSetUnsafe(i) && !IsFieldNullUnsafe(i);
1359
0
    }
1360
1361
    // Those methods should only be called on a field that is of the type
1362
    // consistent with the value, and that is set.
1363
    int GetFieldAsIntegerUnsafe(int i) const
1364
0
    {
1365
0
        return pauFields[i].Integer;
1366
0
    }
1367
1368
    GIntBig GetFieldAsInteger64Unsafe(int i) const
1369
0
    {
1370
0
        return pauFields[i].Integer64;
1371
0
    }
1372
1373
    double GetFieldAsDoubleUnsafe(int i) const
1374
0
    {
1375
0
        return pauFields[i].Real;
1376
0
    }
1377
1378
    const char *GetFieldAsStringUnsafe(int i) const
1379
0
    {
1380
0
        return pauFields[i].String;
1381
0
    }
1382
1383
    //! @endcond
1384
1385
    int GetFieldAsInteger(const char *pszFName) const
1386
0
    {
1387
0
        return GetFieldAsInteger(GetFieldIndex(pszFName));
1388
0
    }
1389
1390
    GIntBig GetFieldAsInteger64(const char *pszFName) const
1391
0
    {
1392
0
        return GetFieldAsInteger64(GetFieldIndex(pszFName));
1393
0
    }
1394
1395
    double GetFieldAsDouble(const char *pszFName) const
1396
0
    {
1397
0
        return GetFieldAsDouble(GetFieldIndex(pszFName));
1398
0
    }
1399
1400
    const char *GetFieldAsString(const char *pszFName) const
1401
0
    {
1402
0
        return GetFieldAsString(GetFieldIndex(pszFName));
1403
0
    }
1404
1405
    const char *GetFieldAsISO8601DateTime(const char *pszFName,
1406
                                          CSLConstList papszOptions) const
1407
0
    {
1408
0
        return GetFieldAsISO8601DateTime(GetFieldIndex(pszFName), papszOptions);
1409
0
    }
1410
1411
    const int *GetFieldAsIntegerList(const char *pszFName, int *pnCount) const
1412
0
    {
1413
0
        return GetFieldAsIntegerList(GetFieldIndex(pszFName), pnCount);
1414
0
    }
1415
1416
    const GIntBig *GetFieldAsInteger64List(const char *pszFName,
1417
                                           int *pnCount) const
1418
0
    {
1419
0
        return GetFieldAsInteger64List(GetFieldIndex(pszFName), pnCount);
1420
0
    }
1421
1422
    const double *GetFieldAsDoubleList(const char *pszFName, int *pnCount) const
1423
0
    {
1424
0
        return GetFieldAsDoubleList(GetFieldIndex(pszFName), pnCount);
1425
0
    }
1426
1427
    char **GetFieldAsStringList(const char *pszFName) const
1428
0
    {
1429
0
        return GetFieldAsStringList(GetFieldIndex(pszFName));
1430
0
    }
1431
1432
    void SetField(int i, int nValue);
1433
    void SetField(int i, GIntBig nValue);
1434
    void SetField(int i, double dfValue);
1435
    void SetField(int i, const char *pszValue);
1436
#if defined(DOXYGEN_SKIP) || __cplusplus >= 201703L ||                         \
1437
    (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
1438
    void SetField(int i, std::string_view svValue);
1439
1440
    //! @cond Doxygen_Suppress
1441
    inline void SetField(int i, const std::string &osValue)
1442
0
    {
1443
0
        SetField(i, osValue.c_str());
1444
0
    }
1445
1446
    //! @endcond
1447
#endif
1448
    void SetField(int i, int nCount, const int *panValues);
1449
    void SetField(int i, int nCount, const GIntBig *panValues);
1450
    void SetField(int i, int nCount, const double *padfValues);
1451
    void SetField(int i, const char *const *papszValues);
1452
    void SetField(int i, const OGRField *puValue);
1453
    void SetField(int i, int nCount, const void *pabyBinary);
1454
    void SetField(int i, int nYear, int nMonth, int nDay, int nHour = 0,
1455
                  int nMinute = 0, float fSecond = 0.f, int nTZFlag = 0);
1456
1457
    //! @cond Doxygen_Suppress
1458
    // Those methods should only be called on a field that is of the type
1459
    // consistent with the value, and in a unset state.
1460
    void SetFieldSameTypeUnsafe(int i, int nValue)
1461
0
    {
1462
0
        pauFields[i].Integer = nValue;
1463
0
        pauFields[i].Set.nMarker2 = 0;
1464
0
        pauFields[i].Set.nMarker3 = 0;
1465
0
    }
1466
1467
    void SetFieldSameTypeUnsafe(int i, GIntBig nValue)
1468
0
    {
1469
0
        pauFields[i].Integer64 = nValue;
1470
0
    }
1471
1472
    void SetFieldSameTypeUnsafe(int i, double dfValue)
1473
0
    {
1474
0
        pauFields[i].Real = dfValue;
1475
0
    }
1476
1477
    void SetFieldSameTypeUnsafe(int i, char *pszValueTransferred)
1478
0
    {
1479
0
        pauFields[i].String = pszValueTransferred;
1480
0
    }
1481
1482
    //! @endcond
1483
1484
    void SetField(const char *pszFName, int nValue)
1485
0
    {
1486
0
        SetField(GetFieldIndex(pszFName), nValue);
1487
0
    }
1488
1489
    void SetField(const char *pszFName, GIntBig nValue)
1490
0
    {
1491
0
        SetField(GetFieldIndex(pszFName), nValue);
1492
0
    }
1493
1494
    void SetField(const char *pszFName, double dfValue)
1495
0
    {
1496
0
        SetField(GetFieldIndex(pszFName), dfValue);
1497
0
    }
1498
1499
    void SetField(const char *pszFName, const char *pszValue)
1500
0
    {
1501
0
        SetField(GetFieldIndex(pszFName), pszValue);
1502
0
    }
1503
1504
    void SetField(const char *pszFName, int nCount, const int *panValues)
1505
0
    {
1506
0
        SetField(GetFieldIndex(pszFName), nCount, panValues);
1507
0
    }
1508
1509
    void SetField(const char *pszFName, int nCount, const GIntBig *panValues)
1510
0
    {
1511
0
        SetField(GetFieldIndex(pszFName), nCount, panValues);
1512
0
    }
1513
1514
    void SetField(const char *pszFName, int nCount, const double *padfValues)
1515
0
    {
1516
0
        SetField(GetFieldIndex(pszFName), nCount, padfValues);
1517
0
    }
1518
1519
    void SetField(const char *pszFName, const char *const *papszValues)
1520
0
    {
1521
0
        SetField(GetFieldIndex(pszFName), papszValues);
1522
0
    }
1523
1524
    void SetField(const char *pszFName, const OGRField *puValue)
1525
0
    {
1526
0
        SetField(GetFieldIndex(pszFName), puValue);
1527
0
    }
1528
1529
    void SetField(const char *pszFName, int nYear, int nMonth, int nDay,
1530
                  int nHour = 0, int nMinute = 0, float fSecond = 0.f,
1531
                  int nTZFlag = 0)
1532
0
    {
1533
0
        SetField(GetFieldIndex(pszFName), nYear, nMonth, nDay, nHour, nMinute,
1534
0
                 fSecond, nTZFlag);
1535
0
    }
1536
1537
    GIntBig GetFID() const
1538
0
    {
1539
0
        return nFID;
1540
0
    }
1541
1542
    virtual OGRErr SetFID(GIntBig nFIDIn);
1543
1544
    void DumpReadable(FILE *, CSLConstList papszOptions = nullptr) const;
1545
    std::string DumpReadableAsString(CSLConstList papszOptions = nullptr) const;
1546
1547
    OGRErr SetFrom(const OGRFeature *, int bForgiving = TRUE);
1548
    OGRErr SetFrom(const OGRFeature *, const int *panMap, int bForgiving = TRUE,
1549
                   bool bUseISO8601ForDateTimeAsString = false);
1550
    OGRErr SetFieldsFrom(const OGRFeature *, const int *panMap,
1551
                         int bForgiving = TRUE,
1552
                         bool bUseISO8601ForDateTimeAsString = false);
1553
1554
    //! @cond Doxygen_Suppress
1555
    OGRErr RemapFields(const OGRFeatureDefn *poNewDefn,
1556
                       const int *panRemapSource);
1557
    void AppendField();
1558
    OGRErr RemapGeomFields(const OGRFeatureDefn *poNewDefn,
1559
                           const int *panRemapSource);
1560
    //! @endcond
1561
1562
    int Validate(int nValidateFlags, int bEmitError) const;
1563
    void FillUnsetWithDefault(int bNotNullableOnly, CSLConstList papszOptions);
1564
1565
    bool SerializeToBinary(std::vector<GByte> &abyBuffer) const;
1566
    bool DeserializeFromBinary(const GByte *pabyBuffer, size_t nSize);
1567
1568
    virtual const char *GetStyleString() const;
1569
    virtual void SetStyleString(const char *);
1570
    virtual void SetStyleStringDirectly(char *);
1571
1572
    /** Return style table.
1573
     * @return style table.
1574
     */
1575
    virtual OGRStyleTable *GetStyleTable() const
1576
0
    {
1577
0
        return m_poStyleTable;
1578
0
    } /* f.i.x.m.e: add a const qualifier for return type */
1579
1580
    virtual void SetStyleTable(OGRStyleTable *poStyleTable);
1581
    virtual void SetStyleTableDirectly(OGRStyleTable *poStyleTable);
1582
1583
    const char *GetNativeData() const
1584
0
    {
1585
0
        return m_pszNativeData;
1586
0
    }
1587
1588
    const char *GetNativeMediaType() const
1589
0
    {
1590
0
        return m_pszNativeMediaType;
1591
0
    }
1592
1593
    void SetNativeData(const char *pszNativeData);
1594
    void SetNativeMediaType(const char *pszNativeMediaType);
1595
1596
    static OGRFeature *CreateFeature(const OGRFeatureDefn *);
1597
    static void DestroyFeature(OGRFeature *);
1598
1599
    /** Convert a OGRFeature* to a OGRFeatureH.
1600
     */
1601
    static inline OGRFeatureH ToHandle(OGRFeature *poFeature)
1602
0
    {
1603
0
        return reinterpret_cast<OGRFeatureH>(poFeature);
1604
0
    }
1605
1606
    /** Convert a OGRFeatureH to a OGRFeature*.
1607
     */
1608
    static inline OGRFeature *FromHandle(OGRFeatureH hFeature)
1609
0
    {
1610
0
        return reinterpret_cast<OGRFeature *>(hFeature);
1611
0
    }
Unexecuted instantiation: OGRFeature::FromHandle(OGRFeatureHS*)
Unexecuted instantiation: OGRFeature::FromHandle(void*)
1612
1613
  private:
1614
    CPL_DISALLOW_COPY_ASSIGN(OGRFeature)
1615
};
1616
1617
//! @cond Doxygen_Suppress
1618
struct CPL_DLL OGRFeatureUniquePtrDeleter
1619
{
1620
    void operator()(OGRFeature *) const;
1621
};
1622
1623
//! @endcond
1624
1625
/** Unique pointer type for OGRFeature.
1626
 */
1627
typedef std::unique_ptr<OGRFeature, OGRFeatureUniquePtrDeleter>
1628
    OGRFeatureUniquePtr;
1629
1630
//! @cond Doxygen_Suppress
1631
/** @see OGRFeature::begin() const */
1632
inline OGRFeature::ConstFieldIterator begin(const OGRFeature *poFeature)
1633
0
{
1634
0
    return poFeature->begin();
1635
0
}
1636
1637
/** @see OGRFeature::end() const */
1638
inline OGRFeature::ConstFieldIterator end(const OGRFeature *poFeature)
1639
0
{
1640
0
    return poFeature->end();
1641
0
}
1642
1643
/** @see OGRFeature::begin() const */
1644
inline OGRFeature::ConstFieldIterator
1645
begin(const OGRFeatureUniquePtr &poFeature)
1646
0
{
1647
0
    return poFeature->begin();
1648
0
}
1649
1650
/** @see OGRFeature::end() const */
1651
inline OGRFeature::ConstFieldIterator end(const OGRFeatureUniquePtr &poFeature)
1652
0
{
1653
0
    return poFeature->end();
1654
0
}
1655
1656
//! @endcond
1657
1658
/************************************************************************/
1659
/*                            OGRFieldDomain                            */
1660
/************************************************************************/
1661
1662
/* clang-format off */
1663
/**
1664
 * Definition of a field domain.
1665
 *
1666
 * A field domain is a set of constraints that apply to one or several fields.
1667
 *
1668
 * This is a concept found in
1669
 * <a href="https://desktop.arcgis.com/en/arcmap/latest/manage-data/geodatabases/an-overview-of-attribute-domains.htm">File
1670
 * Geodatabase</a> or GeoPackage (using the <a href="http://www.geopackage.org/spec/#extension_schema">schema extension</a>)
1671
 * for example.
1672
 *
1673
 * A field domain can be:
1674
 * <ul>
1675
 * <li>OGRCodedFieldDomain: an enumerated list of (code, value) tuples.</li>
1676
 * <li>OGRRangeFieldDomain: a range constraint (min, max).</li>
1677
 * <li>OGRGlobFieldDomain: a glob expression.</li>
1678
 * </ul>
1679
 *
1680
 * @since GDAL 3.3
1681
 */
1682
/* clang-format on */
1683
1684
class CPL_DLL OGRFieldDomain
1685
{
1686
  protected:
1687
    /*! @cond Doxygen_Suppress */
1688
    std::string m_osName;
1689
    std::string m_osDescription;
1690
    OGRFieldDomainType m_eDomainType;
1691
    OGRFieldType m_eFieldType;
1692
    OGRFieldSubType m_eFieldSubType;
1693
    OGRFieldDomainSplitPolicy m_eSplitPolicy = OFDSP_DEFAULT_VALUE;
1694
    OGRFieldDomainMergePolicy m_eMergePolicy = OFDMP_DEFAULT_VALUE;
1695
1696
    OGRFieldDomain(const std::string &osName, const std::string &osDescription,
1697
                   OGRFieldDomainType eDomainType, OGRFieldType eFieldType,
1698
                   OGRFieldSubType eFieldSubType);
1699
    /*! @endcond */
1700
1701
  public:
1702
    /** Destructor.
1703
     *
1704
     * This is the same as the C function OGR_FldDomain_Destroy().
1705
     */
1706
    virtual ~OGRFieldDomain();
1707
1708
    /** Clone.
1709
     *
1710
     * Return a cloned object, or nullptr in case of error.
1711
     */
1712
    virtual OGRFieldDomain *Clone() const = 0;
1713
1714
    /** Get the name of the field domain.
1715
     *
1716
     * This is the same as the C function OGR_FldDomain_GetName().
1717
     */
1718
    const std::string &GetName() const
1719
0
    {
1720
0
        return m_osName;
1721
0
    }
1722
1723
    /** Get the description of the field domain.
1724
     * Empty string if there is none.
1725
     *
1726
     * This is the same as the C function OGR_FldDomain_GetDescription().
1727
     */
1728
    const std::string &GetDescription() const
1729
0
    {
1730
0
        return m_osDescription;
1731
0
    }
1732
1733
    /** Get the type of the field domain.
1734
     *
1735
     * This is the same as the C function OGR_FldDomain_GetDomainType().
1736
     */
1737
    OGRFieldDomainType GetDomainType() const
1738
0
    {
1739
0
        return m_eDomainType;
1740
0
    }
1741
1742
    /** Get the field type.
1743
     *
1744
     * This is the same as the C function OGR_FldDomain_GetFieldType().
1745
     */
1746
    OGRFieldType GetFieldType() const
1747
0
    {
1748
0
        return m_eFieldType;
1749
0
    }
1750
1751
    /** Get the field subtype.
1752
     *
1753
     * This is the same as the C function OGR_FldDomain_GetFieldSubType().
1754
     */
1755
    OGRFieldSubType GetFieldSubType() const
1756
0
    {
1757
0
        return m_eFieldSubType;
1758
0
    }
1759
1760
    /** Convert a OGRFieldDomain* to a OGRFieldDomainH. */
1761
    static inline OGRFieldDomainH ToHandle(OGRFieldDomain *poFieldDomain)
1762
0
    {
1763
0
        return reinterpret_cast<OGRFieldDomainH>(poFieldDomain);
1764
0
    }
1765
1766
    /** Convert a OGRFieldDomainH to a OGRFieldDomain*. */
1767
    static inline OGRFieldDomain *FromHandle(OGRFieldDomainH hFieldDomain)
1768
0
    {
1769
0
        return reinterpret_cast<OGRFieldDomain *>(hFieldDomain);
1770
0
    }
1771
1772
    /** Get the split policy.
1773
     *
1774
     * This is the same as the C function OGR_FldDomain_GetSplitPolicy().
1775
     */
1776
    OGRFieldDomainSplitPolicy GetSplitPolicy() const
1777
0
    {
1778
0
        return m_eSplitPolicy;
1779
0
    }
1780
1781
    /** Set the split policy.
1782
     *
1783
     * This is the same as the C function OGR_FldDomain_SetSplitPolicy().
1784
     */
1785
    void SetSplitPolicy(OGRFieldDomainSplitPolicy policy)
1786
0
    {
1787
0
        m_eSplitPolicy = policy;
1788
0
    }
1789
1790
    /** Get the merge policy.
1791
     *
1792
     * This is the same as the C function OGR_FldDomain_GetMergePolicy().
1793
     */
1794
    OGRFieldDomainMergePolicy GetMergePolicy() const
1795
0
    {
1796
0
        return m_eMergePolicy;
1797
0
    }
1798
1799
    /** Set the merge policy.
1800
     *
1801
     * This is the same as the C function OGR_FldDomain_SetMergePolicy().
1802
     */
1803
    void SetMergePolicy(OGRFieldDomainMergePolicy policy)
1804
0
    {
1805
0
        m_eMergePolicy = policy;
1806
0
    }
1807
};
1808
1809
/** Definition of a coded / enumerated field domain.
1810
 *
1811
 * A code field domain is a domain for which only a limited set of codes,
1812
 * associated with their expanded value, are allowed.
1813
 * The type of the code should be the one of the field domain.
1814
 */
1815
class CPL_DLL OGRCodedFieldDomain final : public OGRFieldDomain
1816
{
1817
  private:
1818
    std::vector<OGRCodedValue> m_asValues{};
1819
1820
    OGRCodedFieldDomain(const OGRCodedFieldDomain &) = delete;
1821
    OGRCodedFieldDomain &operator=(const OGRCodedFieldDomain &) = delete;
1822
1823
  public:
1824
    /** Constructor.
1825
     *
1826
     * This is the same as the C function OGR_CodedFldDomain_Create()
1827
     * (except that the C function copies the enumeration, whereas the C++
1828
     * method moves it)
1829
     *
1830
     * @param osName         Domain name.
1831
     * @param osDescription  Domain description.
1832
     * @param eFieldType     Field type. Generally numeric. Potentially
1833
     * OFTDateTime
1834
     * @param eFieldSubType  Field subtype.
1835
     * @param asValues       Enumeration as (code, value) pairs.
1836
     *                       Each code should appear only once, but it is the
1837
     *                       responsibility of the user to check it.
1838
     */
1839
    OGRCodedFieldDomain(const std::string &osName,
1840
                        const std::string &osDescription,
1841
                        OGRFieldType eFieldType, OGRFieldSubType eFieldSubType,
1842
                        std::vector<OGRCodedValue> &&asValues);
1843
1844
    ~OGRCodedFieldDomain() override;
1845
1846
    OGRCodedFieldDomain *Clone() const override;
1847
1848
    /** Get the enumeration as (code, value) pairs.
1849
     * The end of the enumeration is signaled by code == NULL.
1850
     *
1851
     * This is the same as the C function OGR_CodedFldDomain_GetEnumeration().
1852
     */
1853
    const OGRCodedValue *GetEnumeration() const
1854
0
    {
1855
0
        return m_asValues.data();
1856
0
    }
1857
};
1858
1859
/** Definition of a numeric field domain with a range of validity for values.
1860
 */
1861
class CPL_DLL OGRRangeFieldDomain final : public OGRFieldDomain
1862
{
1863
  private:
1864
    OGRField m_sMin;
1865
    OGRField m_sMax;
1866
    bool m_bMinIsInclusive;
1867
    bool m_bMaxIsInclusive;
1868
1869
    OGRRangeFieldDomain(const OGRRangeFieldDomain &) = delete;
1870
    OGRRangeFieldDomain &operator=(const OGRRangeFieldDomain &) = delete;
1871
1872
  public:
1873
    /** Constructor.
1874
     *
1875
     * This is the same as the C function OGR_RangeFldDomain_Create().
1876
     *
1877
     * @param osName          Domain name.
1878
     * @param osDescription   Domain description.
1879
     * @param eFieldType      Field type.
1880
     *                        One among OFTInteger, OFTInteger64, OFTReal or
1881
     * OFTDateTime
1882
     * @param eFieldSubType   Field subtype.
1883
     * @param sMin            Minimum value.
1884
     *                        Which member in the OGRField enum must be read
1885
     *                        depends on the field type.
1886
     *                        If no minimum is set (might not be supported by
1887
     *                        all backends), then initialize the value with
1888
     *                        OGR_RawField_SetUnset().
1889
     * @param bMinIsInclusive Whether the minimum value is included in the
1890
     * range.
1891
     * @param sMax            Minimum value.
1892
     *                        Which member in the OGRField enum must be read
1893
     *                        depends on the field type.
1894
     *                        If no maximum is set (might not be supported by
1895
     *                        all backends), then initialize the value with
1896
     *                        OGR_RawField_SetUnset().
1897
     * @param bMaxIsInclusive Whether the minimum value is included in the
1898
     * range.
1899
     */
1900
    OGRRangeFieldDomain(const std::string &osName,
1901
                        const std::string &osDescription,
1902
                        OGRFieldType eFieldType, OGRFieldSubType eFieldSubType,
1903
                        const OGRField &sMin, bool bMinIsInclusive,
1904
                        const OGRField &sMax, bool bMaxIsInclusive);
1905
1906
    OGRRangeFieldDomain *Clone() const override;
1907
1908
    /** Get the minimum value.
1909
     *
1910
     * Which member in the returned OGRField enum must be read depends on the
1911
     * field type.
1912
     *
1913
     * If no minimum value is set, the OGR_RawField_IsUnset() will return true
1914
     * when called on the result.
1915
     *
1916
     * This is the same as the C function OGR_RangeFldDomain_GetMin().
1917
     *
1918
     * @param bIsInclusiveOut set to true if the minimum is included in the
1919
     * range.
1920
     */
1921
    const OGRField &GetMin(bool &bIsInclusiveOut) const
1922
0
    {
1923
0
        bIsInclusiveOut = m_bMinIsInclusive;
1924
0
        return m_sMin;
1925
0
    }
1926
1927
    /** Get the maximum value.
1928
     *
1929
     * Which member in the returned OGRField enum must be read depends on the
1930
     * field type.
1931
     *
1932
     * If no maximum value is set, the OGR_RawField_IsUnset() will return true
1933
     * when called on the result.
1934
     *
1935
     * This is the same as the C function OGR_RangeFldDomain_GetMax().
1936
     *
1937
     * @param bIsInclusiveOut set to true if the maximum is included in the
1938
     * range.
1939
     */
1940
    const OGRField &GetMax(bool &bIsInclusiveOut) const
1941
0
    {
1942
0
        bIsInclusiveOut = m_bMaxIsInclusive;
1943
0
        return m_sMax;
1944
0
    }
1945
};
1946
1947
/** Definition of a field domain for field content validated by a glob.
1948
 *
1949
 * Globs are matching expression like "*[a-z][0-1]?"
1950
 */
1951
class CPL_DLL OGRGlobFieldDomain final : public OGRFieldDomain
1952
{
1953
  private:
1954
    std::string m_osGlob;
1955
1956
    OGRGlobFieldDomain(const OGRGlobFieldDomain &) = delete;
1957
    OGRGlobFieldDomain &operator=(const OGRGlobFieldDomain &) = delete;
1958
1959
  public:
1960
    /** Constructor.
1961
     *
1962
     * This is the same as the C function OGR_GlobFldDomain_Create().
1963
     *
1964
     * @param osName          Domain name.
1965
     * @param osDescription   Domain description.
1966
     * @param eFieldType      Field type.
1967
     * @param eFieldSubType   Field subtype.
1968
     * @param osBlob          Blob expression
1969
     */
1970
    OGRGlobFieldDomain(const std::string &osName,
1971
                       const std::string &osDescription,
1972
                       OGRFieldType eFieldType, OGRFieldSubType eFieldSubType,
1973
                       const std::string &osBlob);
1974
1975
    OGRGlobFieldDomain *Clone() const override;
1976
1977
    /** Get the glob expression.
1978
     *
1979
     * This is the same as the C function OGR_GlobFldDomain_GetGlob().
1980
     */
1981
    const std::string &GetGlob() const
1982
0
    {
1983
0
        return m_osGlob;
1984
0
    }
1985
};
1986
1987
/************************************************************************/
1988
/*                           OGRFeatureQuery                            */
1989
/************************************************************************/
1990
1991
//! @cond Doxygen_Suppress
1992
class OGRLayer;
1993
class swq_expr_node;
1994
class swq_custom_func_registrar;
1995
struct swq_evaluation_context;
1996
1997
class CPL_DLL OGRFeatureQuery
1998
{
1999
  private:
2000
    const OGRFeatureDefn *poTargetDefn;
2001
    void *pSWQExpr;
2002
    swq_evaluation_context *m_psContext = nullptr;
2003
2004
    char **FieldCollector(void *, char **);
2005
2006
    static GIntBig *EvaluateAgainstIndices(const swq_expr_node *, OGRLayer *,
2007
                                           GIntBig &nFIDCount);
2008
2009
    static int CanUseIndex(const swq_expr_node *, OGRLayer *);
2010
2011
    OGRErr Compile(const OGRLayer *, const OGRFeatureDefn *, const char *,
2012
                   int bCheck,
2013
                   swq_custom_func_registrar *poCustomFuncRegistrar);
2014
2015
    CPL_DISALLOW_COPY_ASSIGN(OGRFeatureQuery)
2016
2017
  public:
2018
    OGRFeatureQuery();
2019
    ~OGRFeatureQuery();
2020
2021
    OGRErr Compile(const OGRLayer *, const char *, int bCheck = TRUE,
2022
                   swq_custom_func_registrar *poCustomFuncRegistrar = nullptr);
2023
    OGRErr Compile(const OGRFeatureDefn *, const char *, int bCheck = TRUE,
2024
                   swq_custom_func_registrar *poCustomFuncRegistrar = nullptr);
2025
    int Evaluate(OGRFeature *);
2026
2027
    GIntBig *EvaluateAgainstIndices(OGRLayer *, OGRErr *);
2028
2029
    int CanUseIndex(OGRLayer *);
2030
2031
    char **GetUsedFields();
2032
2033
    void *GetSWQExpr()
2034
0
    {
2035
0
        return pSWQExpr;
2036
0
    }
2037
};
2038
2039
//! @endcond
2040
2041
#endif /* ndef OGR_FEATURE_H_INCLUDED */