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