Line data Source code
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 21563855 : const char *GetNameRef() const
112 : {
113 21563855 : return pszName;
114 : }
115 :
116 : void SetAlternativeName(const char *);
117 :
118 917887 : const char *GetAlternativeNameRef() const
119 : {
120 917887 : return pszAlternativeName;
121 : }
122 :
123 37325268 : OGRFieldType GetType() const
124 : {
125 37325268 : return eType;
126 : }
127 :
128 : void SetType(OGRFieldType eTypeIn);
129 : static const char *GetFieldTypeName(OGRFieldType);
130 : static OGRFieldType GetFieldTypeByName(const char *);
131 :
132 5162518 : OGRFieldSubType GetSubType() const
133 : {
134 5162518 : return eSubType;
135 : }
136 :
137 : void SetSubType(OGRFieldSubType eSubTypeIn);
138 : static const char *GetFieldSubTypeName(OGRFieldSubType);
139 : static OGRFieldSubType GetFieldSubTypeByName(const char *);
140 :
141 759914 : OGRJustification GetJustify() const
142 : {
143 759914 : return eJustify;
144 : }
145 :
146 85769 : void SetJustify(OGRJustification eJustifyIn)
147 : {
148 85769 : eJustify = eJustifyIn;
149 85769 : }
150 :
151 5587695 : int GetWidth() const
152 : {
153 5587695 : return nWidth;
154 : }
155 :
156 : void SetWidth(int nWidthIn);
157 :
158 913892 : int GetPrecision() const
159 : {
160 913892 : return nPrecision;
161 : }
162 :
163 : void SetPrecision(int nPrecisionIn);
164 :
165 773509 : int GetTZFlag() const
166 : {
167 773509 : return m_nTZFlag;
168 : }
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 966428 : int IsIgnored() const
180 : {
181 966428 : return bIgnore;
182 : }
183 :
184 55311 : void SetIgnored(int bIgnoreIn)
185 : {
186 55311 : bIgnore = bIgnoreIn;
187 55311 : }
188 :
189 957764 : int IsNullable() const
190 : {
191 957764 : return bNullable;
192 : }
193 :
194 : void SetNullable(int bNullableIn);
195 :
196 916750 : int IsUnique() const
197 : {
198 916750 : return bUnique;
199 : }
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 5240501 : bool IsGenerated() const
210 : {
211 5240501 : return m_bGenerated;
212 : }
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 2439 : void SetGenerated(bool bGeneratedIn)
220 : {
221 2439 : m_bGenerated = bGeneratedIn;
222 2439 : }
223 :
224 : void SetUnique(int bUniqueIn);
225 :
226 62052 : const std::string &GetDomainName() const
227 : {
228 62052 : return m_osDomainName;
229 : }
230 :
231 : void SetDomainName(const std::string &osDomainName);
232 :
233 916848 : const std::string &GetComment() const
234 : {
235 916848 : return m_osComment;
236 : }
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 477453 : static inline OGRFieldDefnH ToHandle(OGRFieldDefn *poFieldDefn)
245 : {
246 477453 : return reinterpret_cast<OGRFieldDefnH>(poFieldDefn);
247 : }
248 :
249 : /** Convert a OGRFieldDefnH to a OGRFieldDefn*.
250 : */
251 560282 : static inline OGRFieldDefn *FromHandle(OGRFieldDefnH hFieldDefn)
252 : {
253 560282 : return reinterpret_cast<OGRFieldDefn *>(hFieldDefn);
254 : }
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 235 : explicit TemporaryUnsealer(OGRFieldDefn *poFieldDefn)
268 235 : : m_poFieldDefn(poFieldDefn)
269 : {
270 235 : m_poFieldDefn->Unseal();
271 235 : }
272 :
273 : TemporaryUnsealer(TemporaryUnsealer &&) = default;
274 : TemporaryUnsealer &operator=(TemporaryUnsealer &&) = default;
275 :
276 235 : ~TemporaryUnsealer()
277 235 : {
278 235 : m_poFieldDefn->Seal();
279 235 : }
280 :
281 84 : OGRFieldDefn *operator->()
282 : {
283 84 : return m_poFieldDefn;
284 : }
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 84 : inline OGRFieldDefn::TemporaryUnsealer whileUnsealing(OGRFieldDefn *object)
305 : {
306 84 : return object->GetTemporaryUnsealer();
307 : }
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 165330 : const char *GetNameRef() const
371 : {
372 165330 : return pszName;
373 : }
374 :
375 756871 : OGRwkbGeometryType GetType() const
376 : {
377 756871 : return eGeomType;
378 : }
379 :
380 : void SetType(OGRwkbGeometryType eTypeIn);
381 :
382 : virtual const OGRSpatialReference *GetSpatialRef() const;
383 : void SetSpatialRef(const OGRSpatialReference *poSRSIn);
384 :
385 194887 : int IsIgnored() const
386 : {
387 194887 : return bIgnore;
388 : }
389 :
390 10662 : void SetIgnored(int bIgnoreIn)
391 : {
392 10662 : bIgnore = bIgnoreIn;
393 10662 : }
394 :
395 13423 : int IsNullable() const
396 : {
397 13423 : return bNullable;
398 : }
399 :
400 : void SetNullable(int bNullableIn);
401 :
402 3620 : const OGRGeomCoordinatePrecision &GetCoordinatePrecision() const
403 : {
404 3620 : return m_oCoordPrecision;
405 : }
406 :
407 : void SetCoordinatePrecision(const OGRGeomCoordinatePrecision &prec);
408 :
409 : int IsSame(const OGRGeomFieldDefn *) const;
410 :
411 : /** Convert a OGRGeomFieldDefn* to a OGRGeomFieldDefnH.
412 : */
413 849 : static inline OGRGeomFieldDefnH ToHandle(OGRGeomFieldDefn *poGeomFieldDefn)
414 : {
415 849 : return reinterpret_cast<OGRGeomFieldDefnH>(poGeomFieldDefn);
416 : }
417 :
418 : /** Convert a OGRGeomFieldDefnH to a OGRGeomFieldDefn*.
419 : */
420 1184 : static inline OGRGeomFieldDefn *FromHandle(OGRGeomFieldDefnH hGeomFieldDefn)
421 : {
422 1184 : return reinterpret_cast<OGRGeomFieldDefn *>(hGeomFieldDefn);
423 : }
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 672 : explicit TemporaryUnsealer(OGRGeomFieldDefn *poFieldDefn)
437 672 : : m_poFieldDefn(poFieldDefn)
438 : {
439 672 : m_poFieldDefn->Unseal();
440 672 : }
441 :
442 : TemporaryUnsealer(TemporaryUnsealer &&) = default;
443 : TemporaryUnsealer &operator=(TemporaryUnsealer &&) = default;
444 :
445 672 : ~TemporaryUnsealer()
446 672 : {
447 672 : m_poFieldDefn->Seal();
448 672 : }
449 :
450 640 : OGRGeomFieldDefn *operator->()
451 : {
452 640 : return m_poFieldDefn;
453 : }
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 640 : whileUnsealing(OGRGeomFieldDefn *object)
475 : {
476 640 : return object->GetTemporaryUnsealer();
477 : }
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 187 : inline explicit Fields(OwnerT poFDefn) : m_poFDefn(poFDefn)
555 : {
556 187 : }
557 :
558 : struct CPL_DLL Iterator
559 : {
560 : private:
561 : OwnerT m_poFDefn;
562 : int m_nIdx;
563 :
564 : public:
565 368 : inline Iterator(OwnerT poFDefn, int nIdx)
566 368 : : m_poFDefn(poFDefn), m_nIdx(nIdx)
567 : {
568 368 : }
569 :
570 736 : inline ChildT operator*() const
571 : {
572 736 : return m_poFDefn->GetFieldDefn(m_nIdx);
573 : }
574 :
575 735 : inline Iterator &operator++()
576 : {
577 735 : m_nIdx++;
578 735 : return *this;
579 : }
580 :
581 919 : inline bool operator!=(const Iterator &it) const
582 : {
583 919 : return m_nIdx != it.m_nIdx;
584 : }
585 : };
586 :
587 184 : inline Iterator begin()
588 : {
589 184 : return Iterator(m_poFDefn, 0);
590 : }
591 :
592 184 : inline Iterator end()
593 : {
594 184 : return Iterator(m_poFDefn, m_poFDefn->GetFieldCount());
595 : }
596 :
597 1 : inline size_t size() const
598 : {
599 1 : return static_cast<std::size_t>(m_poFDefn->GetFieldCount());
600 : }
601 :
602 2 : inline ChildT operator[](size_t i)
603 : {
604 2 : 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 79 : inline NonConstFields GetFields()
624 : {
625 79 : return NonConstFields(this);
626 : }
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 108 : inline ConstFields GetFields() const
642 : {
643 108 : return ConstFields(this);
644 : }
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 4246102 : int GetFieldCountUnsafe() const
650 : {
651 4246102 : return static_cast<int>(apoFieldDefn.size());
652 : }
653 :
654 : // Those methods don't check i is n range.
655 1488972 : OGRFieldDefn *GetFieldDefnUnsafe(int i)
656 : {
657 1488972 : if (apoFieldDefn.empty())
658 0 : GetFieldDefn(i);
659 1488972 : return apoFieldDefn[static_cast<std::size_t>(i)].get();
660 : }
661 :
662 15595900 : const OGRFieldDefn *GetFieldDefnUnsafe(int i) const
663 : {
664 15595900 : if (apoFieldDefn.empty())
665 0 : GetFieldDefn(i);
666 15595900 : return apoFieldDefn[static_cast<std::size_t>(i)].get();
667 : }
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 16284 : inline explicit GeomFields(OwnerT poFDefn) : m_poFDefn(poFDefn)
715 : {
716 16284 : }
717 :
718 : struct CPL_DLL Iterator
719 : {
720 : private:
721 : OwnerT m_poFDefn;
722 : int m_nIdx;
723 :
724 : public:
725 32560 : inline Iterator(OwnerT poFDefn, int nIdx)
726 32560 : : m_poFDefn(poFDefn), m_nIdx(nIdx)
727 : {
728 32560 : }
729 :
730 16272 : inline ChildT operator*() const
731 : {
732 16272 : return m_poFDefn->GetGeomFieldDefn(m_nIdx);
733 : }
734 :
735 16268 : inline Iterator &operator++()
736 : {
737 16268 : m_nIdx++;
738 16268 : return *this;
739 : }
740 :
741 32548 : inline bool operator!=(const Iterator &it) const
742 : {
743 32548 : return m_nIdx != it.m_nIdx;
744 : }
745 : };
746 :
747 16280 : inline Iterator begin()
748 : {
749 16280 : return Iterator(m_poFDefn, 0);
750 : }
751 :
752 16280 : inline Iterator end()
753 : {
754 16280 : return Iterator(m_poFDefn, m_poFDefn->GetGeomFieldCount());
755 : }
756 :
757 1 : inline size_t size() const
758 : {
759 1 : return static_cast<std::size_t>(m_poFDefn->GetGeomFieldCount());
760 : }
761 :
762 3 : inline ChildT operator[](size_t i) const
763 : {
764 3 : 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 14 : inline NonConstGeomFields GetGeomFields()
784 : {
785 14 : return NonConstGeomFields(this);
786 : }
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 16270 : inline ConstGeomFields GetGeomFields() const
803 : {
804 16270 : return ConstGeomFields(this);
805 : }
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 2335366 : int Reference()
817 : {
818 2335366 : return CPLAtomicInc(&nRefCount);
819 : }
820 :
821 2335240 : int Dereference()
822 : {
823 2335240 : return CPLAtomicDec(&nRefCount);
824 : }
825 :
826 16 : int GetReferenceCount() const
827 : {
828 16 : return nRefCount;
829 : }
830 :
831 : void Release();
832 :
833 : virtual int IsGeometryIgnored() const;
834 : virtual void SetGeometryIgnored(int bIgnore);
835 :
836 13 : virtual bool IsStyleIgnored() const
837 : {
838 13 : return bIgnoreStyle;
839 : }
840 :
841 7755 : virtual void SetStyleIgnored(bool bIgnore)
842 : {
843 7755 : bIgnoreStyle = bIgnore;
844 7755 : }
845 :
846 : virtual int IsSame(const OGRFeatureDefn *poOtherFeatureDefn) const;
847 :
848 : //! @cond Doxygen_Suppress
849 : void ReserveSpaceForFields(int nFieldCountIn);
850 : //! @endcond
851 :
852 : std::vector<int> ComputeMapForSetFrom(const OGRFeatureDefn *poSrcFDefn,
853 : bool bForgiving = true) const;
854 :
855 : static OGRFeatureDefn *CreateFeatureDefn(const char *pszName = nullptr);
856 : static void DestroyFeatureDefn(OGRFeatureDefn *);
857 :
858 : /** Convert a OGRFeatureDefn* to a OGRFeatureDefnH.
859 : */
860 183015 : static inline OGRFeatureDefnH ToHandle(OGRFeatureDefn *poFeatureDefn)
861 : {
862 183015 : return reinterpret_cast<OGRFeatureDefnH>(poFeatureDefn);
863 : }
864 :
865 : /** Convert a OGRFeatureDefnH to a OGRFeatureDefn*.
866 : */
867 751195 : static inline OGRFeatureDefn *FromHandle(OGRFeatureDefnH hFeatureDefn)
868 : {
869 751195 : return reinterpret_cast<OGRFeatureDefn *>(hFeatureDefn);
870 : }
871 :
872 : void Seal(bool bSealFields);
873 :
874 : void Unseal(bool bUnsealFields);
875 :
876 : /*! @cond Doxygen_Suppress */
877 : struct CPL_DLL TemporaryUnsealer
878 : {
879 : private:
880 : OGRFeatureDefn *m_poFeatureDefn = nullptr;
881 : bool m_bSealFields = false;
882 : CPL_DISALLOW_COPY_ASSIGN(TemporaryUnsealer)
883 : public:
884 : explicit TemporaryUnsealer(OGRFeatureDefn *poFeatureDefn,
885 : bool bSealFields);
886 :
887 : TemporaryUnsealer(TemporaryUnsealer &&) = default;
888 : TemporaryUnsealer &operator=(TemporaryUnsealer &&) = default;
889 :
890 : ~TemporaryUnsealer();
891 :
892 28165 : OGRFeatureDefn *operator->()
893 : {
894 28165 : return m_poFeatureDefn;
895 : }
896 : };
897 :
898 : /*! @endcond */
899 :
900 : TemporaryUnsealer GetTemporaryUnsealer(bool bSealFields = true);
901 :
902 : private:
903 : CPL_DISALLOW_COPY_ASSIGN(OGRFeatureDefn)
904 : };
905 :
906 : #ifdef GDAL_COMPILATION
907 : /** Return an object that temporary unseals the OGRFeatureDefn
908 : *
909 : * The returned object calls Unseal() initially, and when it is destroyed
910 : * it calls Seal().
911 : * This method should be called on a OGRFeatureDefn that has been sealed
912 : * previously.
913 : * GetTemporaryUnsealer() calls may be nested, in which case only the first
914 : * one has an effect (similarly to a recursive mutex locked in a nested way
915 : * from the same thread).
916 : *
917 : * This method should only be called by driver implementations.
918 : *
919 : * Usage: whileUnsealing(poFeatureDefn)->some_method();
920 : *
921 : * @param bSealFields Whether fields and geometry fields should be unsealed and
922 : * resealed.
923 : * This is generally desirable, but in case of deferred
924 : * resolution of them, this parameter should be set to false.
925 : * @since GDAL 3.9
926 : */
927 28165 : inline OGRFeatureDefn::TemporaryUnsealer whileUnsealing(OGRFeatureDefn *object,
928 : bool bSealFields = true)
929 : {
930 28165 : return object->GetTemporaryUnsealer(bSealFields);
931 : }
932 : #endif
933 :
934 : /************************************************************************/
935 : /* OGRFeature */
936 : /************************************************************************/
937 :
938 : /**
939 : * A simple feature, including geometry and attributes.
940 : */
941 :
942 : class CPL_DLL OGRFeature
943 : {
944 : private:
945 : GIntBig nFID;
946 : const OGRFeatureDefn *poDefn;
947 : OGRGeometry **papoGeometries;
948 : OGRField *pauFields;
949 : char *m_pszNativeData;
950 : char *m_pszNativeMediaType;
951 :
952 : bool SetFieldInternal(int i, const OGRField *puValue);
953 :
954 : protected:
955 : //! @cond Doxygen_Suppress
956 : mutable char *m_pszStyleString;
957 : mutable OGRStyleTable *m_poStyleTable;
958 : mutable char *m_pszTmpFieldValue;
959 : //! @endcond
960 :
961 : bool CopySelfTo(OGRFeature *poNew) const;
962 :
963 : public:
964 : explicit OGRFeature(const OGRFeatureDefn *);
965 : virtual ~OGRFeature();
966 :
967 : /** Field value. */
968 51 : class CPL_DLL FieldValue
969 : {
970 : friend class OGRFeature;
971 : struct Private;
972 : std::unique_ptr<Private> m_poPrivate;
973 :
974 : FieldValue(OGRFeature *poFeature, int iFieldIndex);
975 : FieldValue(const OGRFeature *poFeature, int iFieldIndex);
976 : FieldValue(const FieldValue &oOther) = delete;
977 : FieldValue &Assign(const FieldValue &oOther);
978 :
979 : public:
980 : //! @cond Doxygen_Suppress
981 : ~FieldValue();
982 :
983 : FieldValue &operator=(FieldValue &&oOther);
984 : //! @endcond
985 :
986 : /** Set a field value from another one. */
987 : FieldValue &operator=(const FieldValue &oOther);
988 : /** Set an integer value to the field. */
989 : FieldValue &operator=(int nVal);
990 : /** Set an integer value to the field. */
991 : FieldValue &operator=(GIntBig nVal);
992 : /** Set a real value to the field. */
993 : FieldValue &operator=(double dfVal);
994 : /** Set a string value to the field. */
995 : FieldValue &operator=(const char *pszVal);
996 : /** Set a string value to the field. */
997 : FieldValue &operator=(const std::string &osVal);
998 : /** Set an array of integer to the field. */
999 : FieldValue &operator=(const std::vector<int> &oArray);
1000 : /** Set an array of big integer to the field. */
1001 : FieldValue &operator=(const std::vector<GIntBig> &oArray);
1002 : /** Set an array of double to the field. */
1003 : FieldValue &operator=(const std::vector<double> &oArray);
1004 : /** Set an array of strings to the field. */
1005 : FieldValue &operator=(const std::vector<std::string> &oArray);
1006 : /** Set an array of strings to the field. */
1007 : FieldValue &operator=(CSLConstList papszValues);
1008 : /** Set a null value to the field. */
1009 : void SetNull();
1010 : /** Unset the field. */
1011 : void clear();
1012 :
1013 : /** Unset the field. */
1014 2 : void Unset()
1015 : {
1016 2 : clear();
1017 2 : }
1018 :
1019 : /** Set date time value/ */
1020 : void SetDateTime(int nYear, int nMonth, int nDay, int nHour = 0,
1021 : int nMinute = 0, float fSecond = 0.f, int nTZFlag = 0);
1022 :
1023 : /** Return field index. */
1024 : int GetIndex() const;
1025 : /** Return field definition. */
1026 : const OGRFieldDefn *GetDefn() const;
1027 :
1028 : /** Return field name. */
1029 11 : const char *GetName() const
1030 : {
1031 11 : return GetDefn()->GetNameRef();
1032 : }
1033 :
1034 : /** Return field type. */
1035 23 : OGRFieldType GetType() const
1036 : {
1037 23 : return GetDefn()->GetType();
1038 : }
1039 :
1040 : /** Return field subtype. */
1041 11 : OGRFieldSubType GetSubType() const
1042 : {
1043 11 : return GetDefn()->GetSubType();
1044 : }
1045 :
1046 : /** Return whether the field value is unset/empty. */
1047 : // cppcheck-suppress functionStatic
1048 1 : bool empty() const
1049 : {
1050 1 : return IsUnset();
1051 : }
1052 :
1053 : /** Return whether the field value is unset/empty. */
1054 : // cppcheck-suppress functionStatic
1055 : bool IsUnset() const;
1056 :
1057 : /** Return whether the field value is null. */
1058 : // cppcheck-suppress functionStatic
1059 : bool IsNull() const;
1060 :
1061 : /** Return the raw field value */
1062 : const OGRField *GetRawValue() const;
1063 :
1064 : /** Return the integer value.
1065 : * Only use that method if and only if GetType() == OFTInteger.
1066 : */
1067 : // cppcheck-suppress functionStatic
1068 3 : int GetInteger() const
1069 : {
1070 3 : return GetRawValue()->Integer;
1071 : }
1072 :
1073 : /** Return the 64-bit integer value.
1074 : * Only use that method if and only if GetType() == OFTInteger64.
1075 : */
1076 : // cppcheck-suppress functionStatic
1077 3 : GIntBig GetInteger64() const
1078 : {
1079 3 : return GetRawValue()->Integer64;
1080 : }
1081 :
1082 : /** Return the double value.
1083 : * Only use that method if and only if GetType() == OFTReal.
1084 : */
1085 : // cppcheck-suppress functionStatic
1086 2 : double GetDouble() const
1087 : {
1088 2 : return GetRawValue()->Real;
1089 : }
1090 :
1091 : /** Return the string value.
1092 : * Only use that method if and only if GetType() == OFTString.
1093 : */
1094 : // cppcheck-suppress functionStatic
1095 6 : const char *GetString() const
1096 : {
1097 6 : return GetRawValue()->String;
1098 : }
1099 :
1100 : /** Return the date/time/datetime value. */
1101 : bool GetDateTime(int *pnYear, int *pnMonth, int *pnDay, int *pnHour,
1102 : int *pnMinute, float *pfSecond, int *pnTZFlag) const;
1103 :
1104 : /** Return the field value as integer, with potential conversion */
1105 2 : operator int() const
1106 : {
1107 2 : return GetAsInteger();
1108 : }
1109 :
1110 : /** Return the field value as 64-bit integer, with potential conversion
1111 : */
1112 1 : operator GIntBig() const
1113 : {
1114 1 : return GetAsInteger64();
1115 : }
1116 :
1117 : /** Return the field value as double, with potential conversion */
1118 1 : operator double() const
1119 : {
1120 1 : return GetAsDouble();
1121 : }
1122 :
1123 : /** Return the field value as string, with potential conversion */
1124 1 : operator const char *() const
1125 : {
1126 1 : return GetAsString();
1127 : }
1128 :
1129 : /** Return the field value as integer list, with potential conversion */
1130 1 : operator const std::vector<int> &() const
1131 : {
1132 1 : return GetAsIntegerList();
1133 : }
1134 :
1135 : /** Return the field value as 64-bit integer list, with potential
1136 : * conversion */
1137 1 : operator const std::vector<GIntBig> &() const
1138 : {
1139 1 : return GetAsInteger64List();
1140 : }
1141 :
1142 : /** Return the field value as double list, with potential conversion */
1143 1 : operator const std::vector<double> &() const
1144 : {
1145 1 : return GetAsDoubleList();
1146 : }
1147 :
1148 : /** Return the field value as string list, with potential conversion */
1149 1 : operator const std::vector<std::string> &() const
1150 : {
1151 1 : return GetAsStringList();
1152 : }
1153 :
1154 : /** Return the field value as string list, with potential conversion */
1155 : operator CSLConstList() const;
1156 :
1157 : /** Return the field value as integer, with potential conversion */
1158 : int GetAsInteger() const;
1159 : /** Return the field value as 64-bit integer, with potential conversion
1160 : */
1161 : GIntBig GetAsInteger64() const;
1162 : /** Return the field value as double, with potential conversion */
1163 : double GetAsDouble() const;
1164 : /** Return the field value as string, with potential conversion */
1165 : const char *GetAsString() const;
1166 : /** Return the field value as integer list, with potential conversion */
1167 : const std::vector<int> &GetAsIntegerList() const;
1168 : /** Return the field value as 64-bit integer list, with potential
1169 : * conversion */
1170 : const std::vector<GIntBig> &GetAsInteger64List() const;
1171 : /** Return the field value as double list, with potential conversion */
1172 : const std::vector<double> &GetAsDoubleList() const;
1173 : /** Return the field value as string list, with potential conversion */
1174 : const std::vector<std::string> &GetAsStringList() const;
1175 : };
1176 :
1177 : /** Field value iterator class. */
1178 4 : class CPL_DLL ConstFieldIterator
1179 : {
1180 : friend class OGRFeature;
1181 : struct Private;
1182 : std::unique_ptr<Private> m_poPrivate;
1183 :
1184 : ConstFieldIterator(const OGRFeature *poSelf, int nPos);
1185 :
1186 : public:
1187 : //! @cond Doxygen_Suppress
1188 : ConstFieldIterator(
1189 : ConstFieldIterator &&oOther) noexcept; // declared but not defined.
1190 : // Needed for gcc 5.4 at least
1191 : ~ConstFieldIterator();
1192 : const FieldValue &operator*() const;
1193 : ConstFieldIterator &operator++();
1194 : bool operator!=(const ConstFieldIterator &it) const;
1195 : //! @endcond
1196 : };
1197 :
1198 : /** Return begin of field value iterator.
1199 : *
1200 : * Using this iterator for standard range-based loops is safe, but
1201 : * due to implementation limitations, you shouldn't try to access
1202 : * (dereference) more than one iterator step at a time, since you will get
1203 : * a reference to the same object (FieldValue) at each iteration step.
1204 : *
1205 : * \code{.cpp}
1206 : * for( auto&& oField: poFeature )
1207 : * {
1208 : * std::cout << oField.GetIndex() << "," << oField.GetName()<< ": " <<
1209 : * oField.GetAsString() << std::endl;
1210 : * }
1211 : * \endcode
1212 : *
1213 : */
1214 : ConstFieldIterator begin() const;
1215 : /** Return end of field value iterator. */
1216 : ConstFieldIterator end() const;
1217 :
1218 : const FieldValue operator[](int iField) const;
1219 : FieldValue operator[](int iField);
1220 :
1221 : #if defined(__clang__)
1222 : #pragma clang diagnostic push
1223 : #pragma clang diagnostic ignored "-Wweak-vtables"
1224 : #endif
1225 :
1226 : /** Exception raised by operator[](const char*) when a field is not found.
1227 : */
1228 : class FieldNotFoundException final : public std::exception
1229 : {
1230 : };
1231 :
1232 : #if defined(__clang__)
1233 : #pragma clang diagnostic pop
1234 : #endif
1235 :
1236 : const FieldValue operator[](const char *pszFieldName) const;
1237 : FieldValue operator[](const char *pszFieldName);
1238 :
1239 1143538 : const OGRFeatureDefn *GetDefnRef() const
1240 : {
1241 1143538 : return poDefn;
1242 : }
1243 :
1244 : //! @cond Doxygen_Suppress
1245 : void SetFDefnUnsafe(OGRFeatureDefn *poNewFDefn);
1246 : //! @endcond
1247 :
1248 : OGRErr SetGeometryDirectly(OGRGeometry *);
1249 : OGRErr SetGeometry(const OGRGeometry *);
1250 : OGRErr SetGeometry(std::unique_ptr<OGRGeometry>);
1251 : OGRGeometry *GetGeometryRef();
1252 : const OGRGeometry *GetGeometryRef() const;
1253 : OGRGeometry *StealGeometry() CPL_WARN_UNUSED_RESULT;
1254 :
1255 7715300 : int GetGeomFieldCount() const
1256 : {
1257 7715300 : return poDefn->GetGeomFieldCount();
1258 : }
1259 :
1260 9512 : const OGRGeomFieldDefn *GetGeomFieldDefnRef(int iField) const
1261 : {
1262 9512 : return poDefn->GetGeomFieldDefn(iField);
1263 : }
1264 :
1265 9223 : int GetGeomFieldIndex(const char *pszName) const
1266 : {
1267 9223 : return poDefn->GetGeomFieldIndex(pszName);
1268 : }
1269 :
1270 : OGRGeometry *GetGeomFieldRef(int iField);
1271 : const OGRGeometry *GetGeomFieldRef(int iField) const;
1272 : OGRGeometry *StealGeometry(int iField);
1273 : OGRGeometry *GetGeomFieldRef(const char *pszFName);
1274 : const OGRGeometry *GetGeomFieldRef(const char *pszFName) const;
1275 : OGRErr SetGeomFieldDirectly(int iField, OGRGeometry *);
1276 : OGRErr SetGeomField(int iField, const OGRGeometry *);
1277 : OGRErr SetGeomField(int iField, std::unique_ptr<OGRGeometry>);
1278 :
1279 : void Reset();
1280 :
1281 : OGRFeature *Clone() const CPL_WARN_UNUSED_RESULT;
1282 : virtual OGRBoolean Equal(const OGRFeature *poFeature) const;
1283 :
1284 551217 : int GetFieldCount() const
1285 : {
1286 551217 : return poDefn->GetFieldCount();
1287 : }
1288 :
1289 627754 : const OGRFieldDefn *GetFieldDefnRef(int iField) const
1290 : {
1291 627754 : return poDefn->GetFieldDefn(iField);
1292 : }
1293 :
1294 2534044 : int GetFieldIndex(const char *pszName) const
1295 : {
1296 2534044 : return poDefn->GetFieldIndex(pszName);
1297 : }
1298 :
1299 : int IsFieldSet(int iField) const;
1300 :
1301 : void UnsetField(int iField);
1302 :
1303 : bool IsFieldNull(int iField) const;
1304 :
1305 : void SetFieldNull(int iField);
1306 :
1307 : bool IsFieldSetAndNotNull(int iField) const;
1308 :
1309 419998 : OGRField *GetRawFieldRef(int i)
1310 : {
1311 419998 : return pauFields + i;
1312 : }
1313 :
1314 605 : const OGRField *GetRawFieldRef(int i) const
1315 : {
1316 605 : return pauFields + i;
1317 : }
1318 :
1319 : int GetFieldAsInteger(int i) const;
1320 : GIntBig GetFieldAsInteger64(int i) const;
1321 : double GetFieldAsDouble(int i) const;
1322 : const char *GetFieldAsString(int i) const;
1323 : const char *GetFieldAsISO8601DateTime(int i,
1324 : CSLConstList papszOptions) const;
1325 : const int *GetFieldAsIntegerList(int i, int *pnCount) const;
1326 : const GIntBig *GetFieldAsInteger64List(int i, int *pnCount) const;
1327 : const double *GetFieldAsDoubleList(int i, int *pnCount) const;
1328 : char **GetFieldAsStringList(int i) const;
1329 : GByte *GetFieldAsBinary(int i, int *pnCount) const;
1330 : int GetFieldAsDateTime(int i, int *pnYear, int *pnMonth, int *pnDay,
1331 : int *pnHour, int *pnMinute, int *pnSecond,
1332 : int *pnTZFlag) const;
1333 : int GetFieldAsDateTime(int i, int *pnYear, int *pnMonth, int *pnDay,
1334 : int *pnHour, int *pnMinute, float *pfSecond,
1335 : int *pnTZFlag) const;
1336 : char *GetFieldAsSerializedJSon(int i) const;
1337 :
1338 : //! @cond Doxygen_Suppress
1339 30979549 : bool IsFieldSetUnsafe(int i) const
1340 : {
1341 39670667 : return !(pauFields[i].Set.nMarker1 == OGRUnsetMarker &&
1342 8691058 : pauFields[i].Set.nMarker2 == OGRUnsetMarker &&
1343 39670567 : pauFields[i].Set.nMarker3 == OGRUnsetMarker);
1344 : }
1345 :
1346 13343231 : bool IsFieldNullUnsafe(int i) const
1347 : {
1348 13405047 : return (pauFields[i].Set.nMarker1 == OGRNullMarker &&
1349 13405047 : pauFields[i].Set.nMarker2 == OGRNullMarker &&
1350 13405047 : pauFields[i].Set.nMarker3 == OGRNullMarker);
1351 : }
1352 :
1353 17458449 : bool IsFieldSetAndNotNullUnsafe(int i) const
1354 : {
1355 17458449 : return IsFieldSetUnsafe(i) && !IsFieldNullUnsafe(i);
1356 : }
1357 :
1358 : // Those methods should only be called on a field that is of the type
1359 : // consistent with the value, and that is set.
1360 51767 : int GetFieldAsIntegerUnsafe(int i) const
1361 : {
1362 51767 : return pauFields[i].Integer;
1363 : }
1364 :
1365 16330 : GIntBig GetFieldAsInteger64Unsafe(int i) const
1366 : {
1367 16330 : return pauFields[i].Integer64;
1368 : }
1369 :
1370 41820 : double GetFieldAsDoubleUnsafe(int i) const
1371 : {
1372 41820 : return pauFields[i].Real;
1373 : }
1374 :
1375 4468250 : const char *GetFieldAsStringUnsafe(int i) const
1376 : {
1377 4468250 : return pauFields[i].String;
1378 : }
1379 :
1380 : //! @endcond
1381 :
1382 10267 : int GetFieldAsInteger(const char *pszFName) const
1383 : {
1384 10267 : return GetFieldAsInteger(GetFieldIndex(pszFName));
1385 : }
1386 :
1387 6937 : GIntBig GetFieldAsInteger64(const char *pszFName) const
1388 : {
1389 6937 : return GetFieldAsInteger64(GetFieldIndex(pszFName));
1390 : }
1391 :
1392 358 : double GetFieldAsDouble(const char *pszFName) const
1393 : {
1394 358 : return GetFieldAsDouble(GetFieldIndex(pszFName));
1395 : }
1396 :
1397 28042 : const char *GetFieldAsString(const char *pszFName) const
1398 : {
1399 28042 : return GetFieldAsString(GetFieldIndex(pszFName));
1400 : }
1401 :
1402 : const char *GetFieldAsISO8601DateTime(const char *pszFName,
1403 : CSLConstList papszOptions) const
1404 : {
1405 : return GetFieldAsISO8601DateTime(GetFieldIndex(pszFName), papszOptions);
1406 : }
1407 :
1408 120 : const int *GetFieldAsIntegerList(const char *pszFName, int *pnCount) const
1409 : {
1410 120 : return GetFieldAsIntegerList(GetFieldIndex(pszFName), pnCount);
1411 : }
1412 :
1413 : const GIntBig *GetFieldAsInteger64List(const char *pszFName,
1414 : int *pnCount) const
1415 : {
1416 : return GetFieldAsInteger64List(GetFieldIndex(pszFName), pnCount);
1417 : }
1418 :
1419 21 : const double *GetFieldAsDoubleList(const char *pszFName, int *pnCount) const
1420 : {
1421 21 : return GetFieldAsDoubleList(GetFieldIndex(pszFName), pnCount);
1422 : }
1423 :
1424 491 : char **GetFieldAsStringList(const char *pszFName) const
1425 : {
1426 491 : return GetFieldAsStringList(GetFieldIndex(pszFName));
1427 : }
1428 :
1429 : void SetField(int i, int nValue);
1430 : void SetField(int i, GIntBig nValue);
1431 : void SetField(int i, double dfValue);
1432 : void SetField(int i, const char *pszValue);
1433 : #if defined(DOXYGEN_SKIP) || __cplusplus >= 201703L || \
1434 : (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
1435 : void SetField(int i, std::string_view svValue);
1436 :
1437 : //! @cond Doxygen_Suppress
1438 2251 : inline void SetField(int i, const std::string &osValue)
1439 : {
1440 2251 : SetField(i, osValue.c_str());
1441 2251 : }
1442 :
1443 : //! @endcond
1444 : #endif
1445 : void SetField(int i, int nCount, const int *panValues);
1446 : void SetField(int i, int nCount, const GIntBig *panValues);
1447 : void SetField(int i, int nCount, const double *padfValues);
1448 : void SetField(int i, const char *const *papszValues);
1449 : void SetField(int i, const OGRField *puValue);
1450 : void SetField(int i, int nCount, const void *pabyBinary);
1451 : void SetField(int i, int nYear, int nMonth, int nDay, int nHour = 0,
1452 : int nMinute = 0, float fSecond = 0.f, int nTZFlag = 0);
1453 :
1454 : //! @cond Doxygen_Suppress
1455 : // Those methods should only be called on a field that is of the type
1456 : // consistent with the value, and in a unset state.
1457 54369 : void SetFieldSameTypeUnsafe(int i, int nValue)
1458 : {
1459 54369 : pauFields[i].Integer = nValue;
1460 54369 : pauFields[i].Set.nMarker2 = 0;
1461 54369 : pauFields[i].Set.nMarker3 = 0;
1462 54369 : }
1463 :
1464 13299 : void SetFieldSameTypeUnsafe(int i, GIntBig nValue)
1465 : {
1466 13299 : pauFields[i].Integer64 = nValue;
1467 13299 : }
1468 :
1469 22519 : void SetFieldSameTypeUnsafe(int i, double dfValue)
1470 : {
1471 22519 : pauFields[i].Real = dfValue;
1472 22519 : }
1473 :
1474 1431066 : void SetFieldSameTypeUnsafe(int i, char *pszValueTransferred)
1475 : {
1476 1431066 : pauFields[i].String = pszValueTransferred;
1477 1431066 : }
1478 :
1479 : //! @endcond
1480 :
1481 883107 : void SetField(const char *pszFName, int nValue)
1482 : {
1483 883107 : SetField(GetFieldIndex(pszFName), nValue);
1484 883107 : }
1485 :
1486 1288 : void SetField(const char *pszFName, GIntBig nValue)
1487 : {
1488 1288 : SetField(GetFieldIndex(pszFName), nValue);
1489 1288 : }
1490 :
1491 4717 : void SetField(const char *pszFName, double dfValue)
1492 : {
1493 4717 : SetField(GetFieldIndex(pszFName), dfValue);
1494 4717 : }
1495 :
1496 1526182 : void SetField(const char *pszFName, const char *pszValue)
1497 : {
1498 1526182 : SetField(GetFieldIndex(pszFName), pszValue);
1499 1526182 : }
1500 :
1501 121 : void SetField(const char *pszFName, int nCount, const int *panValues)
1502 : {
1503 121 : SetField(GetFieldIndex(pszFName), nCount, panValues);
1504 121 : }
1505 :
1506 1 : void SetField(const char *pszFName, int nCount, const GIntBig *panValues)
1507 : {
1508 1 : SetField(GetFieldIndex(pszFName), nCount, panValues);
1509 1 : }
1510 :
1511 45 : void SetField(const char *pszFName, int nCount, const double *padfValues)
1512 : {
1513 45 : SetField(GetFieldIndex(pszFName), nCount, padfValues);
1514 45 : }
1515 :
1516 500 : void SetField(const char *pszFName, const char *const *papszValues)
1517 : {
1518 500 : SetField(GetFieldIndex(pszFName), papszValues);
1519 500 : }
1520 :
1521 86 : void SetField(const char *pszFName, const OGRField *puValue)
1522 : {
1523 86 : SetField(GetFieldIndex(pszFName), puValue);
1524 86 : }
1525 :
1526 3 : void SetField(const char *pszFName, int nYear, int nMonth, int nDay,
1527 : int nHour = 0, int nMinute = 0, float fSecond = 0.f,
1528 : int nTZFlag = 0)
1529 : {
1530 3 : SetField(GetFieldIndex(pszFName), nYear, nMonth, nDay, nHour, nMinute,
1531 : fSecond, nTZFlag);
1532 3 : }
1533 :
1534 3711269 : GIntBig GetFID() const
1535 : {
1536 3711269 : return nFID;
1537 : }
1538 :
1539 : virtual OGRErr SetFID(GIntBig nFIDIn);
1540 :
1541 : void DumpReadable(FILE *, CSLConstList papszOptions = nullptr) const;
1542 : std::string DumpReadableAsString(CSLConstList papszOptions = nullptr) const;
1543 :
1544 : OGRErr SetFrom(const OGRFeature *, int bForgiving = TRUE);
1545 : OGRErr SetFrom(const OGRFeature *, const int *panMap, int bForgiving = TRUE,
1546 : bool bUseISO8601ForDateTimeAsString = false);
1547 : OGRErr SetFieldsFrom(const OGRFeature *, const int *panMap,
1548 : int bForgiving = TRUE,
1549 : bool bUseISO8601ForDateTimeAsString = false);
1550 :
1551 : //! @cond Doxygen_Suppress
1552 : OGRErr RemapFields(const OGRFeatureDefn *poNewDefn,
1553 : const int *panRemapSource);
1554 : void AppendField();
1555 : OGRErr RemapGeomFields(const OGRFeatureDefn *poNewDefn,
1556 : const int *panRemapSource);
1557 : //! @endcond
1558 :
1559 : int Validate(int nValidateFlags, int bEmitError) const;
1560 : void FillUnsetWithDefault(int bNotNullableOnly, CSLConstList papszOptions);
1561 :
1562 : bool SerializeToBinary(std::vector<GByte> &abyBuffer) const;
1563 : bool DeserializeFromBinary(const GByte *pabyBuffer, size_t nSize);
1564 :
1565 : virtual const char *GetStyleString() const;
1566 : virtual void SetStyleString(const char *);
1567 : virtual void SetStyleStringDirectly(char *);
1568 :
1569 : /** Return style table.
1570 : * @return style table.
1571 : */
1572 199 : virtual OGRStyleTable *GetStyleTable() const
1573 : {
1574 199 : return m_poStyleTable;
1575 : } /* f.i.x.m.e: add a const qualifier for return type */
1576 :
1577 : virtual void SetStyleTable(OGRStyleTable *poStyleTable);
1578 : virtual void SetStyleTableDirectly(OGRStyleTable *poStyleTable);
1579 :
1580 15099 : const char *GetNativeData() const
1581 : {
1582 15099 : return m_pszNativeData;
1583 : }
1584 :
1585 18191 : const char *GetNativeMediaType() const
1586 : {
1587 18191 : return m_pszNativeMediaType;
1588 : }
1589 :
1590 : void SetNativeData(const char *pszNativeData);
1591 : void SetNativeMediaType(const char *pszNativeMediaType);
1592 :
1593 : static OGRFeature *CreateFeature(const OGRFeatureDefn *);
1594 : static void DestroyFeature(OGRFeature *);
1595 :
1596 : /** Convert a OGRFeature* to a OGRFeatureH.
1597 : */
1598 219264 : static inline OGRFeatureH ToHandle(OGRFeature *poFeature)
1599 : {
1600 219264 : return reinterpret_cast<OGRFeatureH>(poFeature);
1601 : }
1602 :
1603 : /** Convert a OGRFeatureH to a OGRFeature*.
1604 : */
1605 1795261 : static inline OGRFeature *FromHandle(OGRFeatureH hFeature)
1606 : {
1607 1795261 : return reinterpret_cast<OGRFeature *>(hFeature);
1608 : }
1609 :
1610 : private:
1611 : CPL_DISALLOW_COPY_ASSIGN(OGRFeature)
1612 : };
1613 :
1614 : //! @cond Doxygen_Suppress
1615 : struct CPL_DLL OGRFeatureUniquePtrDeleter
1616 : {
1617 : void operator()(OGRFeature *) const;
1618 : };
1619 :
1620 : //! @endcond
1621 :
1622 : /** Unique pointer type for OGRFeature.
1623 : */
1624 : typedef std::unique_ptr<OGRFeature, OGRFeatureUniquePtrDeleter>
1625 : OGRFeatureUniquePtr;
1626 :
1627 : //! @cond Doxygen_Suppress
1628 : /** @see OGRFeature::begin() const */
1629 : inline OGRFeature::ConstFieldIterator begin(const OGRFeature *poFeature)
1630 : {
1631 : return poFeature->begin();
1632 : }
1633 :
1634 : /** @see OGRFeature::end() const */
1635 : inline OGRFeature::ConstFieldIterator end(const OGRFeature *poFeature)
1636 : {
1637 : return poFeature->end();
1638 : }
1639 :
1640 : /** @see OGRFeature::begin() const */
1641 : inline OGRFeature::ConstFieldIterator
1642 : begin(const OGRFeatureUniquePtr &poFeature)
1643 : {
1644 : return poFeature->begin();
1645 : }
1646 :
1647 : /** @see OGRFeature::end() const */
1648 : inline OGRFeature::ConstFieldIterator end(const OGRFeatureUniquePtr &poFeature)
1649 : {
1650 : return poFeature->end();
1651 : }
1652 :
1653 : //! @endcond
1654 :
1655 : /************************************************************************/
1656 : /* OGRFieldDomain */
1657 : /************************************************************************/
1658 :
1659 : /* clang-format off */
1660 : /**
1661 : * Definition of a field domain.
1662 : *
1663 : * A field domain is a set of constraints that apply to one or several fields.
1664 : *
1665 : * This is a concept found in
1666 : * <a href="https://desktop.arcgis.com/en/arcmap/latest/manage-data/geodatabases/an-overview-of-attribute-domains.htm">File
1667 : * Geodatabase</a> or GeoPackage (using the <a href="http://www.geopackage.org/spec/#extension_schema">schema extension</a>)
1668 : * for example.
1669 : *
1670 : * A field domain can be:
1671 : * <ul>
1672 : * <li>OGRCodedFieldDomain: an enumerated list of (code, value) tuples.</li>
1673 : * <li>OGRRangeFieldDomain: a range constraint (min, max).</li>
1674 : * <li>OGRGlobFieldDomain: a glob expression.</li>
1675 : * </ul>
1676 : *
1677 : * @since GDAL 3.3
1678 : */
1679 : /* clang-format on */
1680 :
1681 1335 : class CPL_DLL OGRFieldDomain
1682 : {
1683 : protected:
1684 : /*! @cond Doxygen_Suppress */
1685 : std::string m_osName;
1686 : std::string m_osDescription;
1687 : OGRFieldDomainType m_eDomainType;
1688 : OGRFieldType m_eFieldType;
1689 : OGRFieldSubType m_eFieldSubType;
1690 : OGRFieldDomainSplitPolicy m_eSplitPolicy = OFDSP_DEFAULT_VALUE;
1691 : OGRFieldDomainMergePolicy m_eMergePolicy = OFDMP_DEFAULT_VALUE;
1692 :
1693 : OGRFieldDomain(const std::string &osName, const std::string &osDescription,
1694 : OGRFieldDomainType eDomainType, OGRFieldType eFieldType,
1695 : OGRFieldSubType eFieldSubType);
1696 : /*! @endcond */
1697 :
1698 : public:
1699 : /** Destructor.
1700 : *
1701 : * This is the same as the C function OGR_FldDomain_Destroy().
1702 : */
1703 : virtual ~OGRFieldDomain();
1704 :
1705 : /** Clone.
1706 : *
1707 : * Return a cloned object, or nullptr in case of error.
1708 : */
1709 : virtual OGRFieldDomain *Clone() const = 0;
1710 :
1711 : /** Get the name of the field domain.
1712 : *
1713 : * This is the same as the C function OGR_FldDomain_GetName().
1714 : */
1715 1353 : const std::string &GetName() const
1716 : {
1717 1353 : return m_osName;
1718 : }
1719 :
1720 : /** Get the description of the field domain.
1721 : * Empty string if there is none.
1722 : *
1723 : * This is the same as the C function OGR_FldDomain_GetDescription().
1724 : */
1725 109 : const std::string &GetDescription() const
1726 : {
1727 109 : return m_osDescription;
1728 : }
1729 :
1730 : /** Get the type of the field domain.
1731 : *
1732 : * This is the same as the C function OGR_FldDomain_GetDomainType().
1733 : */
1734 230 : OGRFieldDomainType GetDomainType() const
1735 : {
1736 230 : return m_eDomainType;
1737 : }
1738 :
1739 : /** Get the field type.
1740 : *
1741 : * This is the same as the C function OGR_FldDomain_GetFieldType().
1742 : */
1743 205 : OGRFieldType GetFieldType() const
1744 : {
1745 205 : return m_eFieldType;
1746 : }
1747 :
1748 : /** Get the field subtype.
1749 : *
1750 : * This is the same as the C function OGR_FldDomain_GetFieldSubType().
1751 : */
1752 101 : OGRFieldSubType GetFieldSubType() const
1753 : {
1754 101 : return m_eFieldSubType;
1755 : }
1756 :
1757 : /** Convert a OGRFieldDomain* to a OGRFieldDomainH. */
1758 223 : static inline OGRFieldDomainH ToHandle(OGRFieldDomain *poFieldDomain)
1759 : {
1760 223 : return reinterpret_cast<OGRFieldDomainH>(poFieldDomain);
1761 : }
1762 :
1763 : /** Convert a OGRFieldDomainH to a OGRFieldDomain*. */
1764 552 : static inline OGRFieldDomain *FromHandle(OGRFieldDomainH hFieldDomain)
1765 : {
1766 552 : return reinterpret_cast<OGRFieldDomain *>(hFieldDomain);
1767 : }
1768 :
1769 : /** Get the split policy.
1770 : *
1771 : * This is the same as the C function OGR_FldDomain_GetSplitPolicy().
1772 : */
1773 32 : OGRFieldDomainSplitPolicy GetSplitPolicy() const
1774 : {
1775 32 : return m_eSplitPolicy;
1776 : }
1777 :
1778 : /** Set the split policy.
1779 : *
1780 : * This is the same as the C function OGR_FldDomain_SetSplitPolicy().
1781 : */
1782 1196 : void SetSplitPolicy(OGRFieldDomainSplitPolicy policy)
1783 : {
1784 1196 : m_eSplitPolicy = policy;
1785 1196 : }
1786 :
1787 : /** Get the merge policy.
1788 : *
1789 : * This is the same as the C function OGR_FldDomain_GetMergePolicy().
1790 : */
1791 32 : OGRFieldDomainMergePolicy GetMergePolicy() const
1792 : {
1793 32 : return m_eMergePolicy;
1794 : }
1795 :
1796 : /** Set the merge policy.
1797 : *
1798 : * This is the same as the C function OGR_FldDomain_SetMergePolicy().
1799 : */
1800 1196 : void SetMergePolicy(OGRFieldDomainMergePolicy policy)
1801 : {
1802 1196 : m_eMergePolicy = policy;
1803 1196 : }
1804 : };
1805 :
1806 : /** Definition of a coded / enumerated field domain.
1807 : *
1808 : * A code field domain is a domain for which only a limited set of codes,
1809 : * associated with their expanded value, are allowed.
1810 : * The type of the code should be the one of the field domain.
1811 : */
1812 : class CPL_DLL OGRCodedFieldDomain final : public OGRFieldDomain
1813 : {
1814 : private:
1815 : std::vector<OGRCodedValue> m_asValues{};
1816 :
1817 : OGRCodedFieldDomain(const OGRCodedFieldDomain &) = delete;
1818 : OGRCodedFieldDomain &operator=(const OGRCodedFieldDomain &) = delete;
1819 :
1820 : public:
1821 : /** Constructor.
1822 : *
1823 : * This is the same as the C function OGR_CodedFldDomain_Create()
1824 : * (except that the C function copies the enumeration, whereas the C++
1825 : * method moves it)
1826 : *
1827 : * @param osName Domain name.
1828 : * @param osDescription Domain description.
1829 : * @param eFieldType Field type. Generally numeric. Potentially
1830 : * OFTDateTime
1831 : * @param eFieldSubType Field subtype.
1832 : * @param asValues Enumeration as (code, value) pairs.
1833 : * Each code should appear only once, but it is the
1834 : * responsibility of the user to check it.
1835 : */
1836 : OGRCodedFieldDomain(const std::string &osName,
1837 : const std::string &osDescription,
1838 : OGRFieldType eFieldType, OGRFieldSubType eFieldSubType,
1839 : std::vector<OGRCodedValue> &&asValues);
1840 :
1841 : ~OGRCodedFieldDomain() override;
1842 :
1843 : OGRCodedFieldDomain *Clone() const override;
1844 :
1845 : /** Get the enumeration as (code, value) pairs.
1846 : * The end of the enumeration is signaled by code == NULL.
1847 : *
1848 : * This is the same as the C function OGR_CodedFldDomain_GetEnumeration().
1849 : */
1850 172 : const OGRCodedValue *GetEnumeration() const
1851 : {
1852 172 : return m_asValues.data();
1853 : }
1854 : };
1855 :
1856 : /** Definition of a numeric field domain with a range of validity for values.
1857 : */
1858 : class CPL_DLL OGRRangeFieldDomain final : public OGRFieldDomain
1859 : {
1860 : private:
1861 : OGRField m_sMin;
1862 : OGRField m_sMax;
1863 : bool m_bMinIsInclusive;
1864 : bool m_bMaxIsInclusive;
1865 :
1866 : OGRRangeFieldDomain(const OGRRangeFieldDomain &) = delete;
1867 : OGRRangeFieldDomain &operator=(const OGRRangeFieldDomain &) = delete;
1868 :
1869 : public:
1870 : /** Constructor.
1871 : *
1872 : * This is the same as the C function OGR_RangeFldDomain_Create().
1873 : *
1874 : * @param osName Domain name.
1875 : * @param osDescription Domain description.
1876 : * @param eFieldType Field type.
1877 : * One among OFTInteger, OFTInteger64, OFTReal or
1878 : * OFTDateTime
1879 : * @param eFieldSubType Field subtype.
1880 : * @param sMin Minimum value.
1881 : * Which member in the OGRField enum must be read
1882 : * depends on the field type.
1883 : * If no minimum is set (might not be supported by
1884 : * all backends), then initialize the value with
1885 : * OGR_RawField_SetUnset().
1886 : * @param bMinIsInclusive Whether the minimum value is included in the
1887 : * range.
1888 : * @param sMax Minimum value.
1889 : * Which member in the OGRField enum must be read
1890 : * depends on the field type.
1891 : * If no maximum is set (might not be supported by
1892 : * all backends), then initialize the value with
1893 : * OGR_RawField_SetUnset().
1894 : * @param bMaxIsInclusive Whether the minimum value is included in the
1895 : * range.
1896 : */
1897 : OGRRangeFieldDomain(const std::string &osName,
1898 : const std::string &osDescription,
1899 : OGRFieldType eFieldType, OGRFieldSubType eFieldSubType,
1900 : const OGRField &sMin, bool bMinIsInclusive,
1901 : const OGRField &sMax, bool bMaxIsInclusive);
1902 :
1903 : OGRRangeFieldDomain *Clone() const override;
1904 :
1905 : /** Get the minimum value.
1906 : *
1907 : * Which member in the returned OGRField enum must be read depends on the
1908 : * field type.
1909 : *
1910 : * If no minimum value is set, the OGR_RawField_IsUnset() will return true
1911 : * when called on the result.
1912 : *
1913 : * This is the same as the C function OGR_RangeFldDomain_GetMin().
1914 : *
1915 : * @param bIsInclusiveOut set to true if the minimum is included in the
1916 : * range.
1917 : */
1918 52 : const OGRField &GetMin(bool &bIsInclusiveOut) const
1919 : {
1920 52 : bIsInclusiveOut = m_bMinIsInclusive;
1921 52 : return m_sMin;
1922 : }
1923 :
1924 : /** Get the maximum value.
1925 : *
1926 : * Which member in the returned OGRField enum must be read depends on the
1927 : * field type.
1928 : *
1929 : * If no maximum value is set, the OGR_RawField_IsUnset() will return true
1930 : * when called on the result.
1931 : *
1932 : * This is the same as the C function OGR_RangeFldDomain_GetMax().
1933 : *
1934 : * @param bIsInclusiveOut set to true if the maximum is included in the
1935 : * range.
1936 : */
1937 52 : const OGRField &GetMax(bool &bIsInclusiveOut) const
1938 : {
1939 52 : bIsInclusiveOut = m_bMaxIsInclusive;
1940 52 : return m_sMax;
1941 : }
1942 : };
1943 :
1944 : /** Definition of a field domain for field content validated by a glob.
1945 : *
1946 : * Globs are matching expression like "*[a-z][0-1]?"
1947 : */
1948 : class CPL_DLL OGRGlobFieldDomain final : public OGRFieldDomain
1949 : {
1950 : private:
1951 : std::string m_osGlob;
1952 :
1953 : OGRGlobFieldDomain(const OGRGlobFieldDomain &) = delete;
1954 : OGRGlobFieldDomain &operator=(const OGRGlobFieldDomain &) = delete;
1955 :
1956 : public:
1957 : /** Constructor.
1958 : *
1959 : * This is the same as the C function OGR_GlobFldDomain_Create().
1960 : *
1961 : * @param osName Domain name.
1962 : * @param osDescription Domain description.
1963 : * @param eFieldType Field type.
1964 : * @param eFieldSubType Field subtype.
1965 : * @param osBlob Blob expression
1966 : */
1967 : OGRGlobFieldDomain(const std::string &osName,
1968 : const std::string &osDescription,
1969 : OGRFieldType eFieldType, OGRFieldSubType eFieldSubType,
1970 : const std::string &osBlob);
1971 :
1972 : OGRGlobFieldDomain *Clone() const override;
1973 :
1974 : /** Get the glob expression.
1975 : *
1976 : * This is the same as the C function OGR_GlobFldDomain_GetGlob().
1977 : */
1978 13 : const std::string &GetGlob() const
1979 : {
1980 13 : return m_osGlob;
1981 : }
1982 : };
1983 :
1984 : /************************************************************************/
1985 : /* OGRFeatureQuery */
1986 : /************************************************************************/
1987 :
1988 : //! @cond Doxygen_Suppress
1989 : class OGRLayer;
1990 : class swq_expr_node;
1991 : class swq_custom_func_registrar;
1992 : struct swq_evaluation_context;
1993 :
1994 : class CPL_DLL OGRFeatureQuery
1995 : {
1996 : private:
1997 : const OGRFeatureDefn *poTargetDefn;
1998 : void *pSWQExpr;
1999 : swq_evaluation_context *m_psContext = nullptr;
2000 :
2001 : char **FieldCollector(void *, char **);
2002 :
2003 : static GIntBig *EvaluateAgainstIndices(const swq_expr_node *, OGRLayer *,
2004 : GIntBig &nFIDCount);
2005 :
2006 : static int CanUseIndex(const swq_expr_node *, OGRLayer *);
2007 :
2008 : OGRErr Compile(const OGRLayer *, const OGRFeatureDefn *, const char *,
2009 : int bCheck,
2010 : swq_custom_func_registrar *poCustomFuncRegistrar);
2011 :
2012 : CPL_DISALLOW_COPY_ASSIGN(OGRFeatureQuery)
2013 :
2014 : public:
2015 : OGRFeatureQuery();
2016 : ~OGRFeatureQuery();
2017 :
2018 : OGRErr Compile(const OGRLayer *, const char *, int bCheck = TRUE,
2019 : swq_custom_func_registrar *poCustomFuncRegistrar = nullptr);
2020 : OGRErr Compile(const OGRFeatureDefn *, const char *, int bCheck = TRUE,
2021 : swq_custom_func_registrar *poCustomFuncRegistrar = nullptr);
2022 : int Evaluate(OGRFeature *);
2023 :
2024 : GIntBig *EvaluateAgainstIndices(OGRLayer *, OGRErr *);
2025 :
2026 : int CanUseIndex(OGRLayer *);
2027 :
2028 : char **GetUsedFields();
2029 :
2030 3108 : void *GetSWQExpr()
2031 : {
2032 3108 : return pSWQExpr;
2033 : }
2034 : };
2035 :
2036 : //! @endcond
2037 :
2038 : #endif /* ndef OGR_FEATURE_H_INCLUDED */
|