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