1 /******************************************************************************
2 * $Id: ogr_feature.h eb925c89fcc7978ce21d7456480f31487bcb8ad1 2021-04-04 09:37:15 +0200 Even Rouault $
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
38 #include <exception>
39 #include <memory>
40 #include <string>
41 #include <vector>
42
43 /**
44 * \file ogr_feature.h
45 *
46 * Simple feature classes.
47 */
48
49 #ifndef DEFINE_OGRFeatureH
50 /*! @cond Doxygen_Suppress */
51 #define DEFINE_OGRFeatureH
52 /*! @endcond */
53 #ifdef DEBUG
54 typedef struct OGRFieldDefnHS *OGRFieldDefnH;
55 typedef struct OGRFeatureDefnHS *OGRFeatureDefnH;
56 typedef struct OGRFeatureHS *OGRFeatureH;
57 typedef struct OGRStyleTableHS *OGRStyleTableH;
58 #else
59 /** Opaque type for a field definition (OGRFieldDefn) */
60 typedef void *OGRFieldDefnH;
61 /** Opaque type for a feature definition (OGRFeatureDefn) */
62 typedef void *OGRFeatureDefnH;
63 /** Opaque type for a feature (OGRFeature) */
64 typedef void *OGRFeatureH;
65 /** Opaque type for a style table (OGRStyleTable) */
66 typedef void *OGRStyleTableH;
67 #endif
68 /** Opaque type for a geometry field definition (OGRGeomFieldDefn) */
69 typedef struct OGRGeomFieldDefnHS *OGRGeomFieldDefnH;
70
71 /** Opaque type for a field domain definition (OGRFieldDomain) */
72 typedef struct OGRFieldDomainHS *OGRFieldDomainH;
73 #endif /* DEFINE_OGRFeatureH */
74
75 class OGRStyleTable;
76
77 /************************************************************************/
78 /* OGRFieldDefn */
79 /************************************************************************/
80
81 /**
82 * Definition of an attribute of an OGRFeatureDefn. A field is described by :
83 * <ul>
84 * <li>a name. See SetName() / GetNameRef()</li>
85 * <li>an alternative name (optional): alternative descriptive name for the field (sometimes referred to as an "alias"). See SetAlternativeName() / GetAlternativeNameRef()</li>
86 * <li>a type: OFTString, OFTInteger, OFTReal, ... See SetType() / GetType()</li>
87 * <li>a subtype (optional): OFSTBoolean, ... See SetSubType() / GetSubType()</li>
88 * <li>a width (optional): maximal number of characters. See SetWidth() / GetWidth()</li>
89 * <li>a precision (optional): number of digits after decimal point. See SetPrecision() / GetPrecision()</li>
90 * <li>a NOT NULL constraint (optional). See SetNullable() / IsNullable()</li>
91 * <li>a UNIQUE constraint (optional). See SetUnique() / IsUnique()</li>
92 * <li>a default value (optional). See SetDefault() / GetDefault()</li>
93 * <li>a boolean to indicate whether it should be ignored when retrieving features. See SetIgnored() / IsIgnored()</li>
94 * <li>a field domain name (optional). See SetDomainName() / Get DomainName()</li>
95 * </ul>
96 */
97
98 class CPL_DLL OGRFieldDefn
99 {
100 private:
101 char *pszName;
102 char *pszAlternativeName;
103 OGRFieldType eType;
104 OGRJustification eJustify;
105 int nWidth; // Zero is variable.
106 int nPrecision;
107 char *pszDefault;
108
109 int bIgnore;
110 OGRFieldSubType eSubType;
111
112 int bNullable;
113 int bUnique;
114
115 std::string m_osDomainName{}; // field domain name. Might be empty
116
117 public:
118 OGRFieldDefn( const char *, OGRFieldType );
119 explicit OGRFieldDefn( const OGRFieldDefn * );
120 ~OGRFieldDefn();
121
122 void SetName( const char * );
GetNameRef()123 const char *GetNameRef() const { return pszName; }
124
125 void SetAlternativeName( const char * );
GetAlternativeNameRef()126 const char *GetAlternativeNameRef() const { return pszAlternativeName; }
127
GetType()128 OGRFieldType GetType() const { return eType; }
129 void SetType( OGRFieldType eTypeIn );
130 static const char *GetFieldTypeName( OGRFieldType );
131
GetSubType()132 OGRFieldSubType GetSubType() const { return eSubType; }
133 void SetSubType( OGRFieldSubType eSubTypeIn );
134 static const char *GetFieldSubTypeName( OGRFieldSubType );
135
GetJustify()136 OGRJustification GetJustify() const { return eJustify; }
SetJustify(OGRJustification eJustifyIn)137 void SetJustify( OGRJustification eJustifyIn )
138 { eJustify = eJustifyIn; }
139
GetWidth()140 int GetWidth() const { return nWidth; }
SetWidth(int nWidthIn)141 void SetWidth( int nWidthIn ) { nWidth = MAX(0,nWidthIn); }
142
GetPrecision()143 int GetPrecision() const { return nPrecision; }
SetPrecision(int nPrecisionIn)144 void SetPrecision( int nPrecisionIn )
145 { nPrecision = nPrecisionIn; }
146
147 void Set( const char *, OGRFieldType, int = 0, int = 0,
148 OGRJustification = OJUndefined );
149
150 void SetDefault( const char* );
151 const char *GetDefault() const;
152 int IsDefaultDriverSpecific() const;
153
IsIgnored()154 int IsIgnored() const { return bIgnore; }
SetIgnored(int bIgnoreIn)155 void SetIgnored( int bIgnoreIn ) { bIgnore = bIgnoreIn; }
156
IsNullable()157 int IsNullable() const { return bNullable; }
SetNullable(int bNullableIn)158 void SetNullable( int bNullableIn ) { bNullable = bNullableIn; }
159
IsUnique()160 int IsUnique() const { return bUnique; }
SetUnique(int bUniqueIn)161 void SetUnique( int bUniqueIn ) { bUnique = bUniqueIn; }
162
GetDomainName()163 const std::string& GetDomainName() const { return m_osDomainName; }
SetDomainName(const std::string & osDomainName)164 void SetDomainName(const std::string& osDomainName) { m_osDomainName = osDomainName; }
165
166 int IsSame( const OGRFieldDefn * ) const;
167
168 /** Convert a OGRFieldDefn* to a OGRFieldDefnH.
169 * @since GDAL 2.3
170 */
ToHandle(OGRFieldDefn * poFieldDefn)171 static inline OGRFieldDefnH ToHandle(OGRFieldDefn* poFieldDefn)
172 { return reinterpret_cast<OGRFieldDefnH>(poFieldDefn); }
173
174 /** Convert a OGRFieldDefnH to a OGRFieldDefn*.
175 * @since GDAL 2.3
176 */
FromHandle(OGRFieldDefnH hFieldDefn)177 static inline OGRFieldDefn* FromHandle(OGRFieldDefnH hFieldDefn)
178 { return reinterpret_cast<OGRFieldDefn*>(hFieldDefn); }
179 private:
180 CPL_DISALLOW_COPY_ASSIGN(OGRFieldDefn)
181 };
182
183 /************************************************************************/
184 /* OGRGeomFieldDefn */
185 /************************************************************************/
186
187 /**
188 * Definition of a geometry field of an OGRFeatureDefn. A geometry field is
189 * described by :
190 * <ul>
191 * <li>a name. See SetName() / GetNameRef()</li>
192 * <li>a type: wkbPoint, wkbLineString, ... See SetType() / GetType()</li>
193 * <li>a spatial reference system (optional). See SetSpatialRef() / GetSpatialRef()</li>
194 * <li>a NOT NULL constraint (optional). See SetNullable() / IsNullable()</li>
195 * <li>a boolean to indicate whether it should be ignored when retrieving features. See SetIgnored() / IsIgnored()</li>
196 * </ul>
197 *
198 * @since OGR 1.11
199 */
200
201 class CPL_DLL OGRGeomFieldDefn
202 {
203 protected:
204 //! @cond Doxygen_Suppress
205 char *pszName = nullptr;
206 OGRwkbGeometryType eGeomType = wkbUnknown; /* all values possible except wkbNone */
207 mutable OGRSpatialReference* poSRS = nullptr;
208
209 int bIgnore = false;
210 mutable int bNullable = true;
211
212 void Initialize( const char *, OGRwkbGeometryType );
213 //! @endcond
214
215 public:
216 OGRGeomFieldDefn( const char *pszNameIn,
217 OGRwkbGeometryType eGeomTypeIn );
218 explicit OGRGeomFieldDefn( const OGRGeomFieldDefn * );
219 virtual ~OGRGeomFieldDefn();
220
221 void SetName( const char * );
GetNameRef()222 const char *GetNameRef() const { return pszName; }
223
GetType()224 OGRwkbGeometryType GetType() const { return eGeomType; }
225 void SetType( OGRwkbGeometryType eTypeIn );
226
227 virtual OGRSpatialReference* GetSpatialRef() const;
228 void SetSpatialRef( OGRSpatialReference* poSRSIn );
229
IsIgnored()230 int IsIgnored() const { return bIgnore; }
SetIgnored(int bIgnoreIn)231 void SetIgnored( int bIgnoreIn ) { bIgnore = bIgnoreIn; }
232
IsNullable()233 int IsNullable() const { return bNullable; }
SetNullable(int bNullableIn)234 void SetNullable( int bNullableIn )
235 { bNullable = bNullableIn; }
236
237 int IsSame( const OGRGeomFieldDefn * ) const;
238
239 /** Convert a OGRGeomFieldDefn* to a OGRGeomFieldDefnH.
240 * @since GDAL 2.3
241 */
ToHandle(OGRGeomFieldDefn * poGeomFieldDefn)242 static inline OGRGeomFieldDefnH ToHandle(OGRGeomFieldDefn* poGeomFieldDefn)
243 { return reinterpret_cast<OGRGeomFieldDefnH>(poGeomFieldDefn); }
244
245 /** Convert a OGRGeomFieldDefnH to a OGRGeomFieldDefn*.
246 * @since GDAL 2.3
247 */
FromHandle(OGRGeomFieldDefnH hGeomFieldDefn)248 static inline OGRGeomFieldDefn* FromHandle(OGRGeomFieldDefnH hGeomFieldDefn)
249 { return reinterpret_cast<OGRGeomFieldDefn*>(hGeomFieldDefn); }
250 private:
251 CPL_DISALLOW_COPY_ASSIGN(OGRGeomFieldDefn)
252 };
253
254 /************************************************************************/
255 /* OGRFeatureDefn */
256 /************************************************************************/
257
258 /**
259 * Definition of a feature class or feature layer.
260 *
261 * This object contains schema information for a set of OGRFeatures. In
262 * table based systems, an OGRFeatureDefn is essentially a layer. In more
263 * object oriented approaches (such as SF CORBA) this can represent a class
264 * of features but doesn't necessarily relate to all of a layer, or just one
265 * layer.
266 *
267 * This object also can contain some other information such as a name and
268 * potentially other metadata.
269 *
270 * It is essentially a collection of field descriptions (OGRFieldDefn class).
271 * Starting with GDAL 1.11, in addition to attribute fields, it can also
272 * contain multiple geometry fields (OGRGeomFieldDefn class).
273 *
274 * It is reasonable for different translators to derive classes from
275 * OGRFeatureDefn with additional translator specific information.
276 */
277
278 class CPL_DLL OGRFeatureDefn
279 {
280 protected:
281 //! @cond Doxygen_Suppress
282 volatile int nRefCount;
283
284 mutable int nFieldCount;
285 mutable OGRFieldDefn **papoFieldDefn;
286
287 mutable int nGeomFieldCount;
288 mutable OGRGeomFieldDefn **papoGeomFieldDefn;
289
290 char *pszFeatureClassName;
291
292 int bIgnoreStyle;
293 //! @endcond
294
295 public:
296 explicit OGRFeatureDefn( const char * pszName = nullptr );
297 virtual ~OGRFeatureDefn();
298
299 void SetName( const char* pszName );
300 virtual const char *GetName() const;
301
302 virtual int GetFieldCount() const;
303 virtual OGRFieldDefn *GetFieldDefn( int i );
304 virtual const OGRFieldDefn *GetFieldDefn( int i ) const;
305 virtual int GetFieldIndex( const char * ) const;
306 int GetFieldIndexCaseSensitive( const char * ) const;
307
308 virtual void AddFieldDefn( OGRFieldDefn * );
309 virtual OGRErr DeleteFieldDefn( int iField );
310 virtual OGRErr ReorderFieldDefns( int* panMap );
311
312 virtual int GetGeomFieldCount() const;
313 virtual OGRGeomFieldDefn *GetGeomFieldDefn( int i );
314 virtual const OGRGeomFieldDefn *GetGeomFieldDefn( int i ) const;
315 virtual int GetGeomFieldIndex( const char * ) const;
316
317 virtual void AddGeomFieldDefn( OGRGeomFieldDefn *,
318 int bCopy = TRUE );
319 virtual OGRErr DeleteGeomFieldDefn( int iGeomField );
320
321 virtual OGRwkbGeometryType GetGeomType() const;
322 virtual void SetGeomType( OGRwkbGeometryType );
323
324 virtual OGRFeatureDefn *Clone() const;
325
Reference()326 int Reference() { return CPLAtomicInc(&nRefCount); }
Dereference()327 int Dereference() { return CPLAtomicDec(&nRefCount); }
GetReferenceCount()328 int GetReferenceCount() const { return nRefCount; }
329 void Release();
330
331 virtual int IsGeometryIgnored() const;
332 virtual void SetGeometryIgnored( int bIgnore );
IsStyleIgnored()333 virtual int IsStyleIgnored() const { return bIgnoreStyle; }
SetStyleIgnored(int bIgnore)334 virtual void SetStyleIgnored( int bIgnore )
335 { bIgnoreStyle = bIgnore; }
336
337 virtual int IsSame( const OGRFeatureDefn * poOtherFeatureDefn ) const;
338
339 //! @cond Doxygen_Suppress
340 void ReserveSpaceForFields(int nFieldCountIn);
341 //! @endcond
342
343 std::vector<int> ComputeMapForSetFrom( const OGRFeatureDefn* poSrcFDefn,
344 bool bForgiving = true ) const;
345
346 static OGRFeatureDefn *CreateFeatureDefn( const char *pszName = nullptr );
347 static void DestroyFeatureDefn( OGRFeatureDefn * );
348
349 /** Convert a OGRFeatureDefn* to a OGRFeatureDefnH.
350 * @since GDAL 2.3
351 */
ToHandle(OGRFeatureDefn * poFeatureDefn)352 static inline OGRFeatureDefnH ToHandle(OGRFeatureDefn* poFeatureDefn)
353 { return reinterpret_cast<OGRFeatureDefnH>(poFeatureDefn); }
354
355 /** Convert a OGRFeatureDefnH to a OGRFeatureDefn*.
356 * @since GDAL 2.3
357 */
FromHandle(OGRFeatureDefnH hFeatureDefn)358 static inline OGRFeatureDefn* FromHandle(OGRFeatureDefnH hFeatureDefn)
359 { return reinterpret_cast<OGRFeatureDefn*>(hFeatureDefn); }
360
361 private:
362 CPL_DISALLOW_COPY_ASSIGN(OGRFeatureDefn)
363 };
364
365 /************************************************************************/
366 /* OGRFeature */
367 /************************************************************************/
368
369 /**
370 * A simple feature, including geometry and attributes.
371 */
372
373 class CPL_DLL OGRFeature
374 {
375 private:
376
377 GIntBig nFID;
378 OGRFeatureDefn *poDefn;
379 OGRGeometry **papoGeometries;
380 OGRField *pauFields;
381 char *m_pszNativeData;
382 char *m_pszNativeMediaType;
383
384 bool SetFieldInternal( int i, OGRField * puValue );
385
386 protected:
387 //! @cond Doxygen_Suppress
388 mutable char *m_pszStyleString;
389 mutable OGRStyleTable *m_poStyleTable;
390 mutable char *m_pszTmpFieldValue;
391 //! @endcond
392
393 bool CopySelfTo( OGRFeature *poNew ) const;
394
395 public:
396 explicit OGRFeature( OGRFeatureDefn * );
397 virtual ~OGRFeature();
398
399 /** Field value. */
400 class CPL_DLL FieldValue
401 {
402 friend class OGRFeature;
403 struct Private;
404 std::unique_ptr<Private> m_poPrivate;
405
406 FieldValue(OGRFeature* poFeature, int iFieldIndex);
407 FieldValue(const OGRFeature* poFeature, int iFieldIndex);
408 FieldValue(const FieldValue& oOther) = delete;
409
410 public:
411 //! @cond Doxygen_Suppress
412 ~FieldValue();
413 //! @endcond
414
415 /** Set a field value from another one. */
416 FieldValue& operator= (const FieldValue& oOther);
417 /** Set an integer value to the field. */
418 FieldValue& operator= (int nVal);
419 /** Set an integer value to the field. */
420 FieldValue& operator= (GIntBig nVal);
421 /** Set a real value to the field. */
422 FieldValue& operator= (double dfVal);
423 /** Set a string value to the field. */
424 FieldValue& operator= (const char *pszVal);
425 /** Set a string value to the field. */
426 FieldValue& operator= (const std::string& osVal);
427 /** Set an array of integer to the field. */
428 FieldValue& operator= (const std::vector<int>& oArray);
429 /** Set an array of big integer to the field. */
430 FieldValue& operator= (const std::vector<GIntBig>& oArray);
431 /** Set an array of double to the field. */
432 FieldValue& operator= (const std::vector<double>& oArray);
433 /** Set an array of strings to the field. */
434 FieldValue& operator= (const std::vector<std::string>& oArray);
435 /** Set an array of strings to the field. */
436 FieldValue& operator= (CSLConstList papszValues);
437 /** Set a null value to the field. */
438 void SetNull();
439 /** Unset the field. */
440 void clear();
441 /** Unset the field. */
Unset()442 void Unset() { clear(); }
443 /** Set date time value/ */
444 void SetDateTime(int nYear, int nMonth, int nDay,
445 int nHour=0, int nMinute=0, float fSecond=0.f,
446 int nTZFlag = 0 );
447
448 /** Return field index. */
449 int GetIndex() const;
450 /** Return field definition. */
451 const OGRFieldDefn* GetDefn() const;
452 /** Return field name. */
GetName()453 const char* GetName() const { return GetDefn()->GetNameRef(); }
454 /** Return field type. */
GetType()455 OGRFieldType GetType() const { return GetDefn()->GetType(); }
456 /** Return field subtype. */
GetSubType()457 OGRFieldSubType GetSubType() const { return GetDefn()->GetSubType(); }
458
459 /** Return whether the field value is unset/empty. */
460 // cppcheck-suppress functionStatic
empty()461 bool empty() const { return IsUnset(); }
462
463 /** Return whether the field value is unset/empty. */
464 // cppcheck-suppress functionStatic
465 bool IsUnset() const;
466
467 /** Return whether the field value is null. */
468 // cppcheck-suppress functionStatic
469 bool IsNull() const;
470
471 /** Return the raw field value */
472 const OGRField *GetRawValue() const;
473
474 /** Return the integer value.
475 * Only use that method if and only if GetType() == OFTInteger.
476 */
477 // cppcheck-suppress functionStatic
GetInteger()478 int GetInteger() const { return GetRawValue()->Integer; }
479
480 /** Return the 64-bit integer value.
481 * Only use that method if and only if GetType() == OFTInteger64.
482 */
483 // cppcheck-suppress functionStatic
GetInteger64()484 GIntBig GetInteger64() const { return GetRawValue()->Integer64; }
485
486 /** Return the double value.
487 * Only use that method if and only if GetType() == OFTReal.
488 */
489 // cppcheck-suppress functionStatic
GetDouble()490 double GetDouble() const { return GetRawValue()->Real; }
491
492 /** Return the string value.
493 * Only use that method if and only if GetType() == OFTString.
494 */
495 // cppcheck-suppress functionStatic
GetString()496 const char* GetString() const { return GetRawValue()->String; }
497
498 /** Return the date/time/datetime value. */
499 bool GetDateTime( int *pnYear, int *pnMonth,
500 int *pnDay,
501 int *pnHour, int *pnMinute,
502 float *pfSecond,
503 int *pnTZFlag ) const;
504
505 /** Return the field value as integer, with potential conversion */
506 operator int () const { return GetAsInteger(); }
507 /** Return the field value as 64-bit integer, with potential conversion */
GIntBig()508 operator GIntBig() const { return GetAsInteger64(); }
509 /** Return the field value as double, with potential conversion */
510 operator double () const { return GetAsDouble(); }
511 /** Return the field value as string, with potential conversion */
512 operator const char*() const { return GetAsString(); }
513 /** Return the field value as integer list, with potential conversion */
514 operator const std::vector<int>& () const { return GetAsIntegerList(); }
515 /** Return the field value as 64-bit integer list, with potential conversion */
516 operator const std::vector<GIntBig>& () const { return GetAsInteger64List(); }
517 /** Return the field value as double list, with potential conversion */
518 operator const std::vector<double>& () const { return GetAsDoubleList(); }
519 /** Return the field value as string list, with potential conversion */
520 operator const std::vector<std::string>& () const { return GetAsStringList(); }
521 /** Return the field value as string list, with potential conversion */
522 operator CSLConstList () const;
523
524 /** Return the field value as integer, with potential conversion */
525 int GetAsInteger() const;
526 /** Return the field value as 64-bit integer, with potential conversion */
527 GIntBig GetAsInteger64() const;
528 /** Return the field value as double, with potential conversion */
529 double GetAsDouble() const;
530 /** Return the field value as string, with potential conversion */
531 const char* GetAsString() const;
532 /** Return the field value as integer list, with potential conversion */
533 const std::vector<int>& GetAsIntegerList() const;
534 /** Return the field value as 64-bit integer list, with potential conversion */
535 const std::vector<GIntBig>& GetAsInteger64List() const;
536 /** Return the field value as double list, with potential conversion */
537 const std::vector<double>& GetAsDoubleList() const;
538 /** Return the field value as string list, with potential conversion */
539 const std::vector<std::string>& GetAsStringList() const;
540 };
541
542 /** Field value iterator class. */
543 class CPL_DLL ConstFieldIterator
544 {
545 friend class OGRFeature;
546 struct Private;
547 std::unique_ptr<Private> m_poPrivate;
548
549 ConstFieldIterator(const OGRFeature* poSelf, int nPos);
550
551 public:
552 //! @cond Doxygen_Suppress
553 ConstFieldIterator(ConstFieldIterator&& oOther) noexcept; // declared but not defined. Needed for gcc 5.4 at least
554 ~ConstFieldIterator();
555 const FieldValue& operator*() const;
556 ConstFieldIterator& operator++();
557 bool operator!=(const ConstFieldIterator& it) const;
558 //! @endcond
559 };
560
561 /** Return begin of field value iterator.
562 *
563 * Using this iterator for standard range-based loops is safe, but
564 * due to implementation limitations, you shouldn't try to access
565 * (dereference) more than one iterator step at a time, since you will get
566 * a reference to the same object (FieldValue) at each iteration step.
567 *
568 * <pre>
569 * for( auto&& oField: poFeature )
570 * {
571 * std::cout << oField.GetIndex() << "," << oField.GetName()<< ": " << oField.GetAsString() << std::endl;
572 * }
573 * </pre>
574 *
575 * @since GDAL 2.3
576 */
577 ConstFieldIterator begin() const;
578 /** Return end of field value iterator. */
579 ConstFieldIterator end() const;
580
581 const FieldValue operator[](int iField) const;
582 FieldValue operator[](int iField);
583
584 /** Exception raised by operator[](const char*) when a field is not found. */
585 class FieldNotFoundException: public std::exception {};
586
587 const FieldValue operator[](const char* pszFieldName) const;
588 FieldValue operator[](const char* pszFieldName);
589
GetDefnRef()590 OGRFeatureDefn *GetDefnRef() { return poDefn; }
GetDefnRef()591 const OGRFeatureDefn *GetDefnRef() const { return poDefn; }
592
593 OGRErr SetGeometryDirectly( OGRGeometry * );
594 OGRErr SetGeometry( const OGRGeometry * );
595 OGRGeometry *GetGeometryRef();
596 const OGRGeometry *GetGeometryRef() const;
597 OGRGeometry *StealGeometry() CPL_WARN_UNUSED_RESULT;
598
GetGeomFieldCount()599 int GetGeomFieldCount() const
600 { return poDefn->GetGeomFieldCount(); }
GetGeomFieldDefnRef(int iField)601 OGRGeomFieldDefn *GetGeomFieldDefnRef( int iField )
602 { return poDefn->GetGeomFieldDefn(iField); }
GetGeomFieldDefnRef(int iField)603 const OGRGeomFieldDefn *GetGeomFieldDefnRef( int iField ) const
604 { return poDefn->GetGeomFieldDefn(iField); }
GetGeomFieldIndex(const char * pszName)605 int GetGeomFieldIndex( const char * pszName ) const
606 { return poDefn->GetGeomFieldIndex(pszName); }
607
608 OGRGeometry* GetGeomFieldRef( int iField );
609 const OGRGeometry* GetGeomFieldRef( int iField ) const;
610 OGRGeometry* StealGeometry( int iField );
611 OGRGeometry* GetGeomFieldRef( const char* pszFName );
612 const OGRGeometry* GetGeomFieldRef( const char* pszFName ) const;
613 OGRErr SetGeomFieldDirectly( int iField, OGRGeometry * );
614 OGRErr SetGeomField( int iField, const OGRGeometry * );
615
616 OGRFeature *Clone() const CPL_WARN_UNUSED_RESULT;
617 virtual OGRBoolean Equal( const OGRFeature * poFeature ) const;
618
GetFieldCount()619 int GetFieldCount() const
620 { return poDefn->GetFieldCount(); }
GetFieldDefnRef(int iField)621 const OGRFieldDefn *GetFieldDefnRef( int iField ) const
622 { return poDefn->GetFieldDefn(iField); }
GetFieldDefnRef(int iField)623 OGRFieldDefn *GetFieldDefnRef( int iField )
624 { return poDefn->GetFieldDefn(iField); }
GetFieldIndex(const char * pszName)625 int GetFieldIndex( const char * pszName ) const
626 { return poDefn->GetFieldIndex(pszName); }
627
628 int IsFieldSet( int iField ) const;
629
630 void UnsetField( int iField );
631
632 bool IsFieldNull( int iField ) const;
633
634 void SetFieldNull( int iField );
635
636 bool IsFieldSetAndNotNull( int iField ) const;
637
GetRawFieldRef(int i)638 OGRField *GetRawFieldRef( int i ) { return pauFields + i; }
GetRawFieldRef(int i)639 const OGRField *GetRawFieldRef( int i ) const { return pauFields + i; }
640
641 int GetFieldAsInteger( int i ) const;
642 GIntBig GetFieldAsInteger64( int i ) const;
643 double GetFieldAsDouble( int i ) const;
644 const char *GetFieldAsString( int i ) const;
645 const int *GetFieldAsIntegerList( int i, int *pnCount ) const;
646 const GIntBig *GetFieldAsInteger64List( int i, int *pnCount ) const;
647 const double *GetFieldAsDoubleList( int i, int *pnCount ) const;
648 char **GetFieldAsStringList( int i ) const;
649 GByte *GetFieldAsBinary( int i, int *pnCount ) const;
650 int GetFieldAsDateTime( int i,
651 int *pnYear, int *pnMonth,
652 int *pnDay,
653 int *pnHour, int *pnMinute,
654 int *pnSecond,
655 int *pnTZFlag ) const;
656 int GetFieldAsDateTime( int i,
657 int *pnYear, int *pnMonth,
658 int *pnDay,
659 int *pnHour, int *pnMinute,
660 float *pfSecond,
661 int *pnTZFlag ) const;
662 char *GetFieldAsSerializedJSon( int i ) const;
663
GetFieldAsInteger(const char * pszFName)664 int GetFieldAsInteger( const char *pszFName ) const
665 { return GetFieldAsInteger( GetFieldIndex(pszFName) ); }
GetFieldAsInteger64(const char * pszFName)666 GIntBig GetFieldAsInteger64( const char *pszFName ) const
667 { return GetFieldAsInteger64( GetFieldIndex(pszFName) ); }
GetFieldAsDouble(const char * pszFName)668 double GetFieldAsDouble( const char *pszFName ) const
669 { return GetFieldAsDouble( GetFieldIndex(pszFName) ); }
GetFieldAsString(const char * pszFName)670 const char *GetFieldAsString( const char *pszFName ) const
671 { return GetFieldAsString( GetFieldIndex(pszFName) ); }
GetFieldAsIntegerList(const char * pszFName,int * pnCount)672 const int *GetFieldAsIntegerList( const char *pszFName,
673 int *pnCount ) const
674 { return GetFieldAsIntegerList( GetFieldIndex(pszFName),
675 pnCount ); }
GetFieldAsInteger64List(const char * pszFName,int * pnCount)676 const GIntBig *GetFieldAsInteger64List( const char *pszFName,
677 int *pnCount ) const
678 { return GetFieldAsInteger64List( GetFieldIndex(pszFName),
679 pnCount ); }
GetFieldAsDoubleList(const char * pszFName,int * pnCount)680 const double *GetFieldAsDoubleList( const char *pszFName,
681 int *pnCount ) const
682 { return GetFieldAsDoubleList( GetFieldIndex(pszFName),
683 pnCount ); }
GetFieldAsStringList(const char * pszFName)684 char **GetFieldAsStringList( const char *pszFName ) const
685 { return GetFieldAsStringList(GetFieldIndex(pszFName)); }
686
687 void SetField( int i, int nValue );
688 void SetField( int i, GIntBig nValue );
689 void SetField( int i, double dfValue );
690 void SetField( int i, const char * pszValue );
691 void SetField( int i, int nCount, const int * panValues );
692 void SetField( int i, int nCount,
693 const GIntBig * panValues );
694 void SetField( int i, int nCount, const double * padfValues );
695 void SetField( int i, const char * const * papszValues );
696 void SetField( int i, OGRField * puValue );
697 void SetField( int i, int nCount, const void * pabyBinary );
698 void SetField( int i, int nYear, int nMonth, int nDay,
699 int nHour=0, int nMinute=0, float fSecond=0.f,
700 int nTZFlag = 0 );
701
SetField(const char * pszFName,int nValue)702 void SetField( const char *pszFName, int nValue )
703 { SetField( GetFieldIndex(pszFName), nValue ); }
SetField(const char * pszFName,GIntBig nValue)704 void SetField( const char *pszFName, GIntBig nValue )
705 { SetField( GetFieldIndex(pszFName), nValue ); }
SetField(const char * pszFName,double dfValue)706 void SetField( const char *pszFName, double dfValue )
707 { SetField( GetFieldIndex(pszFName), dfValue ); }
SetField(const char * pszFName,const char * pszValue)708 void SetField( const char *pszFName, const char * pszValue )
709 { SetField( GetFieldIndex(pszFName), pszValue ); }
SetField(const char * pszFName,int nCount,const int * panValues)710 void SetField( const char *pszFName, int nCount,
711 const int * panValues )
712 { SetField(GetFieldIndex(pszFName),nCount,panValues); }
SetField(const char * pszFName,int nCount,const GIntBig * panValues)713 void SetField( const char *pszFName, int nCount,
714 const GIntBig * panValues )
715 { SetField(GetFieldIndex(pszFName),nCount,panValues); }
SetField(const char * pszFName,int nCount,const double * padfValues)716 void SetField( const char *pszFName, int nCount,
717 const double * padfValues )
718 {SetField(GetFieldIndex(pszFName),nCount,padfValues); }
SetField(const char * pszFName,const char * const * papszValues)719 void SetField( const char *pszFName, const char * const * papszValues )
720 { SetField( GetFieldIndex(pszFName), papszValues); }
SetField(const char * pszFName,OGRField * puValue)721 void SetField( const char *pszFName, OGRField * puValue )
722 { SetField( GetFieldIndex(pszFName), puValue ); }
723 void SetField( const char *pszFName,
724 int nYear, int nMonth, int nDay,
725 int nHour=0, int nMinute=0, float fSecond=0.f,
726 int nTZFlag = 0 )
727 { SetField( GetFieldIndex(pszFName),
728 nYear, nMonth, nDay,
729 nHour, nMinute, fSecond, nTZFlag ); }
730
GetFID()731 GIntBig GetFID() const { return nFID; }
732 virtual OGRErr SetFID( GIntBig nFIDIn );
733
734 void DumpReadable( FILE *, char** papszOptions = nullptr ) const;
735
736 OGRErr SetFrom( const OGRFeature *, int = TRUE );
737 OGRErr SetFrom( const OGRFeature *, const int *, int = TRUE );
738 OGRErr SetFieldsFrom( const OGRFeature *, const int *, int = TRUE );
739
740 //! @cond Doxygen_Suppress
741 OGRErr RemapFields( OGRFeatureDefn *poNewDefn,
742 const int *panRemapSource );
743 void AppendField();
744 OGRErr RemapGeomFields( OGRFeatureDefn *poNewDefn,
745 const int *panRemapSource );
746 //! @endcond
747
748 int Validate( int nValidateFlags,
749 int bEmitError ) const;
750 void FillUnsetWithDefault( int bNotNullableOnly,
751 char** papszOptions );
752
753 virtual const char *GetStyleString() const;
754 virtual void SetStyleString( const char * );
755 virtual void SetStyleStringDirectly( char * );
756
757 /** Return style table.
758 * @return style table.
759 */
GetStyleTable()760 virtual OGRStyleTable *GetStyleTable() const { return m_poStyleTable; } /* f.i.x.m.e: add a const qualifier for return type */
761 virtual void SetStyleTable( OGRStyleTable *poStyleTable );
762 virtual void SetStyleTableDirectly( OGRStyleTable *poStyleTable );
763
GetNativeData()764 const char *GetNativeData() const { return m_pszNativeData; }
GetNativeMediaType()765 const char *GetNativeMediaType() const
766 { return m_pszNativeMediaType; }
767 void SetNativeData( const char* pszNativeData );
768 void SetNativeMediaType( const char* pszNativeMediaType );
769
770 static OGRFeature *CreateFeature( OGRFeatureDefn * );
771 static void DestroyFeature( OGRFeature * );
772
773 /** Convert a OGRFeature* to a OGRFeatureH.
774 * @since GDAL 2.3
775 */
ToHandle(OGRFeature * poFeature)776 static inline OGRFeatureH ToHandle(OGRFeature* poFeature)
777 { return reinterpret_cast<OGRFeatureH>(poFeature); }
778
779 /** Convert a OGRFeatureH to a OGRFeature*.
780 * @since GDAL 2.3
781 */
FromHandle(OGRFeatureH hFeature)782 static inline OGRFeature* FromHandle(OGRFeatureH hFeature)
783 { return reinterpret_cast<OGRFeature*>(hFeature); }
784
785 private:
786 CPL_DISALLOW_COPY_ASSIGN(OGRFeature)
787 };
788
789 //! @cond Doxygen_Suppress
790 struct CPL_DLL OGRFeatureUniquePtrDeleter
791 {
792 void operator()(OGRFeature*) const;
793 };
794 //! @endcond
795
796 /** Unique pointer type for OGRFeature.
797 * @since GDAL 2.3
798 */
799 typedef std::unique_ptr<OGRFeature, OGRFeatureUniquePtrDeleter> OGRFeatureUniquePtr;
800
801 //! @cond Doxygen_Suppress
802 /** @see OGRFeature::begin() const */
begin(const OGRFeature * poFeature)803 inline OGRFeature::ConstFieldIterator begin(const OGRFeature* poFeature) { return poFeature->begin(); }
804 /** @see OGRFeature::end() const */
end(const OGRFeature * poFeature)805 inline OGRFeature::ConstFieldIterator end(const OGRFeature* poFeature) { return poFeature->end(); }
806
807 /** @see OGRFeature::begin() const */
begin(const OGRFeatureUniquePtr & poFeature)808 inline OGRFeature::ConstFieldIterator begin(const OGRFeatureUniquePtr& poFeature) { return poFeature->begin(); }
809 /** @see OGRFeature::end() const */
end(const OGRFeatureUniquePtr & poFeature)810 inline OGRFeature::ConstFieldIterator end(const OGRFeatureUniquePtr& poFeature) { return poFeature->end(); }
811
812 //! @endcond
813
814 /************************************************************************/
815 /* OGRFieldDomain */
816 /************************************************************************/
817
818 /**
819 * Definition of a field domain.
820 *
821 * A field domain is a set of constraints that apply to one or several fields.
822 *
823 * This is a concept found in
824 * <a href="https://desktop.arcgis.com/en/arcmap/latest/manage-data/geodatabases/an-overview-of-attribute-domains.htm">File Geodatabase</a>
825 * or GeoPackage (using the
826 * <a href="http://www.geopackage.org/spec/#extension_schema">schema extension</a>)
827 * for example.
828 *
829 * A field domain can be:
830 * <ul>
831 * <li>OGRCodedFieldDomain: an enumerated list of (code, value) tuples.</li>
832 * <li>OGRRangeFieldDomain: a range constraint (min, max).</li>
833 * <li>OGRGlobFieldDomain: a glob expression.</li>
834 * </ul>
835 *
836 * @since GDAL 3.3
837 */
838 class CPL_DLL OGRFieldDomain
839 {
840 protected:
841 /*! @cond Doxygen_Suppress */
842 std::string m_osName;
843 std::string m_osDescription;
844 OGRFieldDomainType m_eDomainType;
845 OGRFieldType m_eFieldType;
846 OGRFieldSubType m_eFieldSubType;
847 OGRFieldDomainSplitPolicy m_eSplitPolicy = OFDSP_DEFAULT_VALUE;
848 OGRFieldDomainMergePolicy m_eMergePolicy = OFDMP_DEFAULT_VALUE;
849
850 OGRFieldDomain(const std::string& osName,
851 const std::string& osDescription,
852 OGRFieldDomainType eDomainType,
853 OGRFieldType eFieldType,
854 OGRFieldSubType eFieldSubType);
855 /*! @endcond */
856
857 public:
858 /** Destructor.
859 *
860 * This is the same as the C function OGR_FldDomain_Destroy().
861 */
862 virtual ~OGRFieldDomain() = 0;
863
864 /** Clone.
865 *
866 * Return a cloned object, or nullptr in case of error.
867 */
868 virtual OGRFieldDomain* Clone() const = 0;
869
870 /** Get the name of the field domain.
871 *
872 * This is the same as the C function OGR_FldDomain_GetName().
873 */
GetName()874 const std::string& GetName() const { return m_osName; }
875
876 /** Get the description of the field domain.
877 * Empty string if there is none.
878 *
879 * This is the same as the C function OGR_FldDomain_GetDescription().
880 */
GetDescription()881 const std::string& GetDescription() const { return m_osDescription; }
882
883 /** Get the type of the field domain.
884 *
885 * This is the same as the C function OGR_FldDomain_GetDomainType().
886 */
GetDomainType()887 OGRFieldDomainType GetDomainType() const { return m_eDomainType; }
888
889 /** Get the field type.
890 *
891 * This is the same as the C function OGR_FldDomain_GetFieldType().
892 */
GetFieldType()893 OGRFieldType GetFieldType() const { return m_eFieldType; }
894
895 /** Get the field subtype.
896 *
897 * This is the same as the C function OGR_FldDomain_GetFieldSubType().
898 */
GetFieldSubType()899 OGRFieldSubType GetFieldSubType() const { return m_eFieldSubType; }
900
901 /** Convert a OGRFieldDomain* to a OGRFieldDomainH. */
ToHandle(OGRFieldDomain * poFieldDomain)902 static inline OGRFieldDomainH ToHandle(OGRFieldDomain* poFieldDomain)
903 { return reinterpret_cast<OGRFieldDomainH>(poFieldDomain); }
904
905 /** Convert a OGRFieldDomainH to a OGRFieldDomain*. */
FromHandle(OGRFieldDomainH hFieldDomain)906 static inline OGRFieldDomain* FromHandle(OGRFieldDomainH hFieldDomain)
907 { return reinterpret_cast<OGRFieldDomain*>(hFieldDomain); }
908
909 /** Get the split policy.
910 *
911 * This is the same as the C function OGR_FldDomain_GetSplitPolicy().
912 */
GetSplitPolicy()913 OGRFieldDomainSplitPolicy GetSplitPolicy() const { return m_eSplitPolicy; }
914
915 /** Set the split policy.
916 *
917 * This is the same as the C function OGR_FldDomain_SetSplitPolicy().
918 */
SetSplitPolicy(OGRFieldDomainSplitPolicy policy)919 void SetSplitPolicy(OGRFieldDomainSplitPolicy policy) { m_eSplitPolicy = policy; }
920
921 /** Get the merge policy.
922 *
923 * This is the same as the C function OGR_FldDomain_GetMergePolicy().
924 */
GetMergePolicy()925 OGRFieldDomainMergePolicy GetMergePolicy() const { return m_eMergePolicy; }
926
927 /** Set the merge policy.
928 *
929 * This is the same as the C function OGR_FldDomain_SetMergePolicy().
930 */
SetMergePolicy(OGRFieldDomainMergePolicy policy)931 void SetMergePolicy(OGRFieldDomainMergePolicy policy) { m_eMergePolicy = policy; }
932 };
933
934 /** Definition of a coded / enumerated field domain.
935 *
936 * A code field domain is a domain for which only a limited set of codes,
937 * associated with their expanded value, are allowed.
938 * The type of the code should be the one of the field domain.
939 */
940 class CPL_DLL OGRCodedFieldDomain final: public OGRFieldDomain
941 {
942 private:
943 std::vector<OGRCodedValue> m_asValues{};
944
945 OGRCodedFieldDomain(const OGRCodedFieldDomain&) = delete;
946 OGRCodedFieldDomain& operator= (const OGRCodedFieldDomain&) = delete;
947
948 public:
949 /** Constructor.
950 *
951 * This is the same as the C function OGR_CodedFldDomain_Create()
952 * (except that the C function copies the enumeration, whereas the C++
953 * method moves it)
954 *
955 * @param osName Domain name.
956 * @param osDescription Domain description.
957 * @param eFieldType Field type. Generally numeric. Potentially OFTDateTime
958 * @param eFieldSubType Field subtype.
959 * @param asValues Enumeration as (code, value) pairs.
960 * Each code should appear only once, but it is the
961 * responsibility of the user to check it.
962 */
963 OGRCodedFieldDomain(const std::string& osName,
964 const std::string& osDescription,
965 OGRFieldType eFieldType,
966 OGRFieldSubType eFieldSubType,
967 std::vector<OGRCodedValue>&& asValues);
968
969 ~OGRCodedFieldDomain() override;
970
971 OGRCodedFieldDomain* Clone() const override;
972
973 /** Get the enumeration as (code, value) pairs.
974 * The end of the enumeration is signaled by code == NULL.
975 *
976 * This is the same as the C function OGR_CodedFldDomain_GetEnumeration().
977 */
GetEnumeration()978 const OGRCodedValue* GetEnumeration() const { return m_asValues.data(); }
979 };
980
981 /** Definition of a numeric field domain with a range of validity for values.
982 */
983 class CPL_DLL OGRRangeFieldDomain final: public OGRFieldDomain
984 {
985 private:
986 OGRField m_sMin;
987 OGRField m_sMax;
988 bool m_bMinIsInclusive;
989 bool m_bMaxIsInclusive;
990
991 OGRRangeFieldDomain(const OGRRangeFieldDomain&) = delete;
992 OGRRangeFieldDomain& operator= (const OGRRangeFieldDomain&) = delete;
993
994 public:
995 /** Constructor.
996 *
997 * This is the same as the C function OGR_RangeFldDomain_Create().
998 *
999 * @param osName Domain name.
1000 * @param osDescription Domain description.
1001 * @param eFieldType Field type.
1002 * One among OFTInteger, OFTInteger64, OFTReal or OFTDateTime
1003 * @param eFieldSubType Field subtype.
1004 * @param sMin Minimum value.
1005 * Which member in the OGRField enum must be read
1006 * depends on the field type.
1007 * If no minimum is set (might not be supported by
1008 * all backends), then initialize the value with
1009 * OGR_RawField_SetUnset().
1010 * @param bMinIsInclusive Whether the minimum value is included in the range.
1011 * @param sMax Minimum value.
1012 * Which member in the OGRField enum must be read
1013 * depends on the field type.
1014 * If no maximum is set (might not be supported by
1015 * all backends), then initialize the value with
1016 * OGR_RawField_SetUnset().
1017 * @param bMaxIsInclusive Whether the minimum value is included in the range.
1018 */
1019 OGRRangeFieldDomain(const std::string& osName,
1020 const std::string& osDescription,
1021 OGRFieldType eFieldType,
1022 OGRFieldSubType eFieldSubType,
1023 const OGRField& sMin,
1024 bool bMinIsInclusive,
1025 const OGRField& sMax,
1026 bool bMaxIsInclusive);
1027
Clone()1028 OGRRangeFieldDomain* Clone() const override {
1029 return new OGRRangeFieldDomain(m_osName, m_osDescription,
1030 m_eFieldType, m_eFieldSubType,
1031 m_sMin, m_bMinIsInclusive,
1032 m_sMax, m_bMaxIsInclusive);
1033 }
1034
1035 /** Get the minimum value.
1036 *
1037 * Which member in the returned OGRField enum must be read depends on the field type.
1038 *
1039 * If no minimum value is set, the OGR_RawField_IsUnset() will return true
1040 * when called on the result.
1041 *
1042 * This is the same as the C function OGR_RangeFldDomain_GetMin().
1043 *
1044 * @param bIsInclusiveOut set to true if the minimum is included in the range.
1045 */
GetMin(bool & bIsInclusiveOut)1046 const OGRField& GetMin(bool& bIsInclusiveOut) const {
1047 bIsInclusiveOut = m_bMinIsInclusive;
1048 return m_sMin;
1049 }
1050
1051 /** Get the maximum value.
1052 *
1053 * Which member in the returned OGRField enum must be read depends on the field type.
1054 *
1055 * If no maximum value is set, the OGR_RawField_IsUnset() will return true
1056 * when called on the result.
1057 *
1058 * This is the same as the C function OGR_RangeFldDomain_GetMax().
1059 *
1060 * @param bIsInclusiveOut set to true if the maximum is included in the range.
1061 */
GetMax(bool & bIsInclusiveOut)1062 const OGRField& GetMax(bool& bIsInclusiveOut) const {
1063 bIsInclusiveOut = m_bMaxIsInclusive;
1064 return m_sMax;
1065 }
1066 };
1067
1068 /** Definition of a field domain for field content validated by a glob.
1069 *
1070 * Globs are matching expression like "*[a-z][0-1]?"
1071 */
1072 class CPL_DLL OGRGlobFieldDomain final: public OGRFieldDomain
1073 {
1074 private:
1075 std::string m_osGlob;
1076
1077 OGRGlobFieldDomain(const OGRGlobFieldDomain&) = delete;
1078 OGRGlobFieldDomain& operator= (const OGRGlobFieldDomain&) = delete;
1079
1080 public:
1081 /** Constructor.
1082 *
1083 * This is the same as the C function OGR_GlobFldDomain_Create().
1084 *
1085 * @param osName Domain name.
1086 * @param osDescription Domain description.
1087 * @param eFieldType Field type.
1088 * @param eFieldSubType Field subtype.
1089 * @param osBlob Blob expression
1090 */
1091 OGRGlobFieldDomain(const std::string& osName,
1092 const std::string& osDescription,
1093 OGRFieldType eFieldType,
1094 OGRFieldSubType eFieldSubType,
1095 const std::string& osBlob);
1096
Clone()1097 OGRGlobFieldDomain* Clone() const override {
1098 return new OGRGlobFieldDomain(m_osName, m_osDescription,
1099 m_eFieldType, m_eFieldSubType,
1100 m_osGlob);
1101 }
1102
1103 /** Get the glob expression.
1104 *
1105 * This is the same as the C function OGR_GlobFldDomain_GetGlob().
1106 */
GetGlob()1107 const std::string& GetGlob() const { return m_osGlob; }
1108 };
1109
1110 /************************************************************************/
1111 /* OGRFeatureQuery */
1112 /************************************************************************/
1113
1114 //! @cond Doxygen_Suppress
1115 class OGRLayer;
1116 class swq_expr_node;
1117 class swq_custom_func_registrar;
1118
1119 class CPL_DLL OGRFeatureQuery
1120 {
1121 private:
1122 OGRFeatureDefn *poTargetDefn;
1123 void *pSWQExpr;
1124
1125 char **FieldCollector( void *, char ** );
1126
1127 GIntBig *EvaluateAgainstIndices( swq_expr_node*, OGRLayer *,
1128 GIntBig& nFIDCount );
1129
1130 int CanUseIndex( swq_expr_node*, OGRLayer * );
1131
1132 OGRErr Compile( OGRLayer *, OGRFeatureDefn*, const char *,
1133 int bCheck,
1134 swq_custom_func_registrar* poCustomFuncRegistrar );
1135
1136 CPL_DISALLOW_COPY_ASSIGN(OGRFeatureQuery)
1137
1138 public:
1139 OGRFeatureQuery();
1140 ~OGRFeatureQuery();
1141
1142 OGRErr Compile( OGRLayer *, const char *,
1143 int bCheck = TRUE,
1144 swq_custom_func_registrar*
1145 poCustomFuncRegistrar = nullptr );
1146 OGRErr Compile( OGRFeatureDefn *, const char *,
1147 int bCheck = TRUE,
1148 swq_custom_func_registrar*
1149 poCustomFuncRegistrar = nullptr );
1150 int Evaluate( OGRFeature * );
1151
1152 GIntBig *EvaluateAgainstIndices( OGRLayer *, OGRErr * );
1153
1154 int CanUseIndex( OGRLayer * );
1155
1156 char **GetUsedFields();
1157
GetSWQExpr()1158 void *GetSWQExpr() { return pSWQExpr; }
1159 };
1160 //! @endcond
1161
1162 #endif /* ndef OGR_FEATURE_H_INCLUDED */
1163