Line data Source code
1 : /******************************************************************************
2 : *
3 : * Project: OpenGIS Simple Features Reference Implementation
4 : * Purpose: The OGRFieldDefn class implementation.
5 : * Author: Frank Warmerdam, warmerda@home.com
6 : *
7 : ******************************************************************************
8 : * Copyright (c) 1999, Les Technologies SoftMap Inc.
9 : * Copyright (c) 2009-2013, Even Rouault <even dot rouault at spatialys.com>
10 : *
11 : * Permission is hereby granted, free of charge, to any person obtaining a
12 : * copy of this software and associated documentation files (the "Software"),
13 : * to deal in the Software without restriction, including without limitation
14 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 : * and/or sell copies of the Software, and to permit persons to whom the
16 : * Software is furnished to do so, subject to the following conditions:
17 : *
18 : * The above copyright notice and this permission notice shall be included
19 : * in all copies or substantial portions of the Software.
20 : *
21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 : * DEALINGS IN THE SOFTWARE.
28 : ****************************************************************************/
29 :
30 : #include "cpl_port.h"
31 : #include "ogr_feature.h"
32 :
33 : #include <cstring>
34 :
35 : #include "ogr_api.h"
36 : #include "ogr_core.h"
37 : #include "ogr_p.h"
38 : #include "ograpispy.h"
39 : #include "cpl_conv.h"
40 : #include "cpl_error.h"
41 : #include "cpl_string.h"
42 :
43 : /************************************************************************/
44 : /* OGRFieldDefn() */
45 : /************************************************************************/
46 :
47 : /**
48 : * \brief Constructor.
49 : *
50 : * By default, fields have no width, precision, are nullable and not ignored.
51 : *
52 : * @param pszNameIn the name of the new field.
53 : * @param eTypeIn the type of the new field.
54 : */
55 :
56 595664 : OGRFieldDefn::OGRFieldDefn(const char *pszNameIn, OGRFieldType eTypeIn)
57 595664 : : pszName(CPLStrdup(pszNameIn)), pszAlternativeName(CPLStrdup("")),
58 : eType(eTypeIn), eJustify(OJUndefined),
59 : // Should nWidth & nPrecision be defined in some particular way for
60 : // numbers?
61 : nWidth(0), nPrecision(0), pszDefault(nullptr), bIgnore(FALSE),
62 595664 : eSubType(OFSTNone), bNullable(TRUE), bUnique(FALSE)
63 : {
64 595664 : }
65 :
66 : /************************************************************************/
67 : /* OGRFieldDefn() */
68 : /************************************************************************/
69 :
70 : /**
71 : * \brief Constructor.
72 : *
73 : * Create by cloning an existing field definition.
74 : *
75 : * @param poPrototype the field definition to clone.
76 : */
77 :
78 698384 : OGRFieldDefn::OGRFieldDefn(const OGRFieldDefn *poPrototype)
79 698384 : : pszName(CPLStrdup(poPrototype->GetNameRef())),
80 698384 : pszAlternativeName(CPLStrdup(poPrototype->GetAlternativeNameRef())),
81 1396770 : eType(poPrototype->GetType()), eJustify(poPrototype->GetJustify()),
82 1396770 : nWidth(poPrototype->GetWidth()), nPrecision(poPrototype->GetPrecision()),
83 : pszDefault(nullptr),
84 : bIgnore(FALSE), // TODO(schwehr): Can we use IsIgnored()?
85 1396770 : eSubType(poPrototype->GetSubType()), bNullable(poPrototype->IsNullable()),
86 698384 : bUnique(poPrototype->IsUnique()),
87 698384 : m_osDomainName(poPrototype->m_osDomainName),
88 698384 : m_osComment(poPrototype->GetComment()),
89 1396770 : m_nTZFlag(poPrototype->GetTZFlag())
90 : {
91 698384 : SetDefault(poPrototype->GetDefault());
92 698384 : }
93 :
94 : /************************************************************************/
95 : /* OGR_Fld_Create() */
96 : /************************************************************************/
97 : /**
98 : * \brief Create a new field definition.
99 : *
100 : * By default, fields have no width, precision, are nullable and not ignored.
101 : *
102 : * This function is the same as the CPP method OGRFieldDefn::OGRFieldDefn().
103 : *
104 : * @param pszName the name of the new field definition.
105 : * @param eType the type of the new field definition.
106 : * @return handle to the new field definition.
107 : */
108 :
109 75803 : OGRFieldDefnH OGR_Fld_Create(const char *pszName, OGRFieldType eType)
110 :
111 : {
112 75803 : return OGRFieldDefn::ToHandle(new OGRFieldDefn(pszName, eType));
113 : }
114 :
115 : /************************************************************************/
116 : /* ~OGRFieldDefn() */
117 : /************************************************************************/
118 :
119 1293990 : OGRFieldDefn::~OGRFieldDefn()
120 :
121 : {
122 1293990 : CPLFree(pszName);
123 1293990 : CPLFree(pszAlternativeName);
124 1293990 : CPLFree(pszDefault);
125 1293990 : }
126 :
127 : /************************************************************************/
128 : /* OGR_Fld_Destroy() */
129 : /************************************************************************/
130 : /**
131 : * \brief Destroy a field definition.
132 : *
133 : * @param hDefn handle to the field definition to destroy.
134 : */
135 :
136 75786 : void OGR_Fld_Destroy(OGRFieldDefnH hDefn)
137 :
138 : {
139 75786 : delete OGRFieldDefn::FromHandle(hDefn);
140 75786 : }
141 :
142 : /************************************************************************/
143 : /* SetName() */
144 : /************************************************************************/
145 :
146 : /**
147 : * \brief Reset the name of this field.
148 : *
149 : * This method is the same as the C function OGR_Fld_SetName().
150 : *
151 : * Note that once a OGRFieldDefn has been added to a layer definition with
152 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
153 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
154 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
155 : * OGRFieldDefn, for drivers that support AlterFieldDefn.
156 : *
157 : * @param pszNameIn the new name to apply.
158 : */
159 :
160 109268 : void OGRFieldDefn::SetName(const char *pszNameIn)
161 :
162 : {
163 109268 : if (m_bSealed)
164 : {
165 5 : CPLError(CE_Failure, CPLE_AppDefined,
166 : "OGRFieldDefn::SetName() not allowed on a sealed object");
167 5 : return;
168 : }
169 109263 : if (pszName != pszNameIn)
170 : {
171 109257 : CPLFree(pszName);
172 109257 : pszName = CPLStrdup(pszNameIn);
173 : }
174 : }
175 :
176 : /************************************************************************/
177 : /* OGR_Fld_SetName() */
178 : /************************************************************************/
179 : /**
180 : * \brief Reset the name of this field.
181 : *
182 : * This function is the same as the CPP method OGRFieldDefn::SetName().
183 : *
184 : * Note that once a OGRFieldDefn has been added to a layer definition with
185 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
186 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
187 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
188 : * OGRFieldDefn, for drivers that support AlterFieldDefn.
189 : *
190 : * @param hDefn handle to the field definition to apply the new name to.
191 : * @param pszName the new name to apply.
192 : */
193 :
194 2 : void OGR_Fld_SetName(OGRFieldDefnH hDefn, const char *pszName)
195 :
196 : {
197 2 : OGRFieldDefn::FromHandle(hDefn)->SetName(pszName);
198 2 : }
199 :
200 : /************************************************************************/
201 : /* GetNameRef() */
202 : /************************************************************************/
203 :
204 : /**
205 : * \fn const char *OGRFieldDefn::GetNameRef();
206 : *
207 : * \brief Fetch name of this field.
208 : *
209 : * This method is the same as the C function OGR_Fld_GetNameRef().
210 : *
211 : * @return pointer to an internal name string that should not be freed or
212 : * modified.
213 : */
214 :
215 : /************************************************************************/
216 : /* OGR_Fld_GetNameRef() */
217 : /************************************************************************/
218 : /**
219 : * \brief Fetch name of this field.
220 : *
221 : * This function is the same as the CPP method OGRFieldDefn::GetNameRef().
222 : *
223 : * @param hDefn handle to the field definition.
224 : * @return the name of the field definition.
225 : *
226 : */
227 :
228 201691 : const char *OGR_Fld_GetNameRef(OGRFieldDefnH hDefn)
229 :
230 : {
231 :
232 : #ifdef OGRAPISPY_ENABLED
233 201691 : if (bOGRAPISpyEnabled)
234 2 : OGRAPISpy_Fld_GetXXXX(hDefn, "GetNameRef");
235 : #endif
236 :
237 201691 : return OGRFieldDefn::FromHandle(hDefn)->GetNameRef();
238 : }
239 :
240 : /************************************************************************/
241 : /* SetAlternativeName() */
242 : /************************************************************************/
243 :
244 : /**
245 : * \brief Reset the alternative name (or "alias") for this field.
246 : *
247 : * The alternative name is an optional attribute for a field which can provide
248 : * a more user-friendly, descriptive name of a field which is not subject to
249 : * the usual naming constraints defined by the data provider.
250 : *
251 : * This is a metadata style attribute only: the alternative name cannot
252 : * be used in place of the actual field name during SQL queries or other
253 : * field name dependent API calls.
254 : *
255 : * This method is the same as the C function OGR_Fld_SetAlternativeName().
256 : *
257 : * Note that once a OGRFieldDefn has been added to a layer definition with
258 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
259 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
260 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
261 : * OGRFieldDefn, for drivers that support AlterFieldDefn.
262 : *
263 : * @param pszAlternativeNameIn the new alternative name to apply.
264 : *
265 : * @since GDAL 3.2
266 : */
267 :
268 71113 : void OGRFieldDefn::SetAlternativeName(const char *pszAlternativeNameIn)
269 :
270 : {
271 71113 : if (m_bSealed)
272 : {
273 1 : CPLError(CE_Failure, CPLE_AppDefined,
274 : "OGRFieldDefn::SetAlternativeName() not allowed on a sealed "
275 : "object");
276 1 : return;
277 : }
278 71112 : if (pszAlternativeName != pszAlternativeNameIn)
279 : {
280 71112 : CPLFree(pszAlternativeName);
281 71112 : pszAlternativeName = CPLStrdup(pszAlternativeNameIn);
282 : }
283 : }
284 :
285 : /************************************************************************/
286 : /* OGR_Fld_SetAlternativeName() */
287 : /************************************************************************/
288 : /**
289 : * \brief Reset the alternative name (or "alias") for this field.
290 : *
291 : * The alternative name is an optional attribute for a field which can provide
292 : * a more user-friendly, descriptive name of a field which is not subject to
293 : * the usual naming constraints defined by the data provider.
294 : *
295 : * This is a metadata style attribute only: the alternative name cannot
296 : * be used in place of the actual field name during SQL queries or other
297 : * field name dependent API calls.
298 : *
299 : * This function is the same as the CPP method
300 : * OGRFieldDefn::SetAlternativeName().
301 : *
302 : * Note that once a OGRFieldDefn has been added to a layer definition with
303 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
304 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
305 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
306 : * OGRFieldDefn, for drivers that support AlterFieldDefn.
307 : *
308 : * @param hDefn handle to the field definition to apply the new alternative name
309 : * to.
310 : * @param pszAlternativeName the new alternative name to apply.
311 : *
312 : * @since GDAL 3.2
313 : */
314 :
315 19 : void OGR_Fld_SetAlternativeName(OGRFieldDefnH hDefn,
316 : const char *pszAlternativeName)
317 :
318 : {
319 19 : OGRFieldDefn::FromHandle(hDefn)->SetAlternativeName(pszAlternativeName);
320 19 : }
321 :
322 : /************************************************************************/
323 : /* GetAlternativeNameRef() */
324 : /************************************************************************/
325 :
326 : /**
327 : * \fn const char *OGRFieldDefn::GetAlternativeNameRef();
328 : *
329 : * \brief Fetch the alternative name (or "alias") for this field.
330 : *
331 : * The alternative name is an optional attribute for a field which can provide
332 : * a more user-friendly, descriptive name of a field which is not subject to
333 : * the usual naming constraints defined by the data provider.
334 : *
335 : * This is a metadata style attribute only: the alternative name cannot
336 : * be used in place of the actual field name during SQL queries or other
337 : * field name dependent API calls.
338 : *
339 : * This method is the same as the C function OGR_Fld_GetAlternativeNameRef().
340 : *
341 : * @return pointer to an internal alternative name string that should not be
342 : * freed or modified.
343 : *
344 : * @since GDAL 3.2
345 : */
346 :
347 : /************************************************************************/
348 : /* OGR_Fld_GetAlternativeNameRef() */
349 : /************************************************************************/
350 : /**
351 : * \brief Fetch the alternative name (or "alias") for this field.
352 : *
353 : * The alternative name is an optional attribute for a field which can provide
354 : * a more user-friendly, descriptive name of a field which is not subject to
355 : * the usual naming constraints defined by the data provider.
356 : *
357 : * This is a metadata style attribute only: the alternative name cannot
358 : * be used in place of the actual field name during SQL queries or other
359 : * field name dependent API calls.
360 : *
361 : * This function is the same as the CPP method
362 : * OGRFieldDefn::GetAlternativeNameRef().
363 : *
364 : * @param hDefn handle to the field definition.
365 : * @return the alternative name of the field definition.
366 : *
367 : * @since GDAL 3.2
368 : */
369 :
370 59 : const char *OGR_Fld_GetAlternativeNameRef(OGRFieldDefnH hDefn)
371 :
372 : {
373 :
374 : #ifdef OGRAPISPY_ENABLED
375 59 : if (bOGRAPISpyEnabled)
376 0 : OGRAPISpy_Fld_GetXXXX(hDefn, "GetAlternativeNameRef");
377 : #endif
378 :
379 59 : return OGRFieldDefn::FromHandle(hDefn)->GetAlternativeNameRef();
380 : }
381 :
382 : /************************************************************************/
383 : /* GetType() */
384 : /************************************************************************/
385 :
386 : /**
387 : * \fn OGRFieldType OGRFieldDefn::GetType() const;
388 : *
389 : * \brief Fetch type of this field.
390 : *
391 : * This method is the same as the C function OGR_Fld_GetType().
392 : *
393 : * @return field type.
394 : */
395 :
396 : /************************************************************************/
397 : /* OGR_Fld_GetType() */
398 : /************************************************************************/
399 : /**
400 : * \brief Fetch type of this field.
401 : *
402 : * This function is the same as the CPP method OGRFieldDefn::GetType().
403 : *
404 : * @param hDefn handle to the field definition to get type from.
405 : * @return field type.
406 : */
407 :
408 104897 : OGRFieldType OGR_Fld_GetType(OGRFieldDefnH hDefn)
409 :
410 : {
411 :
412 : #ifdef OGRAPISPY_ENABLED
413 104897 : if (bOGRAPISpyEnabled)
414 2 : OGRAPISpy_Fld_GetXXXX(hDefn, "GetType");
415 : #endif
416 :
417 104897 : return OGRFieldDefn::FromHandle(hDefn)->GetType();
418 : }
419 :
420 : /************************************************************************/
421 : /* SetType() */
422 : /************************************************************************/
423 :
424 : /**
425 : * \brief Set the type of this field.
426 : * This should never be done to an OGRFieldDefn
427 : * that is already part of an OGRFeatureDefn.
428 : *
429 : * This method is the same as the C function OGR_Fld_SetType().
430 : *
431 : * Note that once a OGRFieldDefn has been added to a layer definition with
432 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
433 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
434 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
435 : * OGRFieldDefn, for drivers that support AlterFieldDefn.
436 : *
437 : * @param eTypeIn the new field type.
438 : */
439 :
440 255679 : void OGRFieldDefn::SetType(OGRFieldType eTypeIn)
441 : {
442 255679 : if (m_bSealed)
443 : {
444 1 : CPLError(CE_Failure, CPLE_AppDefined,
445 : "OGRFieldDefn::SetType() not allowed on a sealed object");
446 1 : return;
447 : }
448 255678 : if (!OGR_AreTypeSubTypeCompatible(eTypeIn, eSubType))
449 : {
450 0 : CPLError(CE_Warning, CPLE_AppDefined,
451 : "Type and subtype of field definition are not compatible. "
452 : "Resetting to OFSTNone");
453 0 : eSubType = OFSTNone;
454 : }
455 255678 : eType = eTypeIn;
456 : }
457 :
458 : /************************************************************************/
459 : /* OGR_Fld_SetType() */
460 : /************************************************************************/
461 : /**
462 : * \brief Set the type of this field.
463 : * This should never be done to an OGRFieldDefn
464 : * that is already part of an OGRFeatureDefn.
465 : *
466 : * This function is the same as the CPP method OGRFieldDefn::SetType().
467 : *
468 : * Note that once a OGRFieldDefn has been added to a layer definition with
469 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
470 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
471 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
472 : * OGRFieldDefn, for drivers that support AlterFieldDefn.
473 : *
474 : * @param hDefn handle to the field definition to set type to.
475 : * @param eType the new field type.
476 : */
477 :
478 0 : void OGR_Fld_SetType(OGRFieldDefnH hDefn, OGRFieldType eType)
479 :
480 : {
481 0 : OGRFieldDefn::FromHandle(hDefn)->SetType(eType);
482 0 : }
483 :
484 : /************************************************************************/
485 : /* GetSubType() */
486 : /************************************************************************/
487 :
488 : /**
489 : * \fn OGRFieldSubType OGRFieldDefn::GetSubType() const;
490 : *
491 : * \brief Fetch subtype of this field.
492 : *
493 : * This method is the same as the C function OGR_Fld_GetSubType().
494 : *
495 : * @return field subtype.
496 : * @since GDAL 2.0
497 : */
498 :
499 : /************************************************************************/
500 : /* OGR_Fld_GetSubType() */
501 : /************************************************************************/
502 : /**
503 : * \brief Fetch subtype of this field.
504 : *
505 : * This function is the same as the CPP method OGRFieldDefn::GetSubType().
506 : *
507 : * @param hDefn handle to the field definition to get subtype from.
508 : * @return field subtype.
509 : * @since GDAL 2.0
510 : */
511 :
512 88251 : OGRFieldSubType OGR_Fld_GetSubType(OGRFieldDefnH hDefn)
513 :
514 : {
515 :
516 : #ifdef OGRAPISPY_ENABLED
517 88251 : if (bOGRAPISpyEnabled)
518 2 : OGRAPISpy_Fld_GetXXXX(hDefn, "GetSubType");
519 : #endif
520 :
521 88251 : return OGRFieldDefn::FromHandle(hDefn)->GetSubType();
522 : }
523 :
524 : /************************************************************************/
525 : /* SetSubType() */
526 : /************************************************************************/
527 :
528 : /**
529 : * \brief Set the subtype of this field.
530 : * This should never be done to an OGRFieldDefn
531 : * that is already part of an OGRFeatureDefn.
532 : *
533 : * This method is the same as the C function OGR_Fld_SetSubType().
534 : *
535 : * Note that once a OGRFieldDefn has been added to a layer definition with
536 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
537 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
538 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
539 : * OGRFieldDefn, for drivers that support AlterFieldDefn.
540 : *
541 : * @param eSubTypeIn the new field subtype.
542 : * @since GDAL 2.0
543 : */
544 292268 : void OGRFieldDefn::SetSubType(OGRFieldSubType eSubTypeIn)
545 : {
546 292268 : if (m_bSealed)
547 : {
548 1 : CPLError(CE_Failure, CPLE_AppDefined,
549 : "OGRFieldDefn::SetSubType() not allowed on a sealed object");
550 1 : return;
551 : }
552 292267 : if (!OGR_AreTypeSubTypeCompatible(eType, eSubTypeIn))
553 : {
554 3 : CPLError(CE_Warning, CPLE_AppDefined,
555 : "Type and subtype of field definition are not compatible. "
556 : "Resetting to OFSTNone");
557 3 : eSubType = OFSTNone;
558 : }
559 : else
560 : {
561 292264 : eSubType = eSubTypeIn;
562 : }
563 : }
564 :
565 : /************************************************************************/
566 : /* OGR_Fld_SetSubType() */
567 : /************************************************************************/
568 : /**
569 : * \brief Set the subtype of this field.
570 : * This should never be done to an OGRFieldDefn
571 : * that is already part of an OGRFeatureDefn.
572 : *
573 : * This function is the same as the CPP method OGRFieldDefn::SetSubType().
574 : *
575 : * Note that once a OGRFieldDefn has been added to a layer definition with
576 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
577 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
578 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
579 : * OGRFieldDefn, for drivers that support AlterFieldDefn.
580 : *
581 : * @param hDefn handle to the field definition to set type to.
582 : * @param eSubType the new field subtype.
583 : * @since GDAL 2.0
584 : */
585 :
586 550 : void OGR_Fld_SetSubType(OGRFieldDefnH hDefn, OGRFieldSubType eSubType)
587 :
588 : {
589 550 : OGRFieldDefn::FromHandle(hDefn)->SetSubType(eSubType);
590 550 : }
591 :
592 : /************************************************************************/
593 : /* SetDefault() */
594 : /************************************************************************/
595 :
596 : /**
597 : * \brief Set default field value.
598 : *
599 : * The default field value is taken into account by drivers (generally those
600 : * with a SQL interface) that support it at field creation time. OGR will
601 : * generally not automatically set the default field value to null fields by
602 : * itself when calling OGRFeature::CreateFeature() / OGRFeature::SetFeature(),
603 : * but will let the low-level layers to do the job. So retrieving the feature
604 : * from the layer is recommended.
605 : *
606 : * The accepted values are NULL, a numeric value, a literal value enclosed
607 : * between single quote characters (and inner single quote characters escaped by
608 : * repetition of the single quote character),
609 : * CURRENT_TIMESTAMP, CURRENT_TIME, CURRENT_DATE or
610 : * a driver specific expression (that might be ignored by other drivers).
611 : * For a datetime literal value, format should be 'YYYY/MM/DD HH:MM:SS[.sss]'
612 : * (considered as UTC time).
613 : *
614 : * Drivers that support writing DEFAULT clauses will advertise the
615 : * GDAL_DCAP_DEFAULT_FIELDS driver metadata item.
616 : *
617 : * This function is the same as the C function OGR_Fld_SetDefault().
618 : *
619 : * Note that once a OGRFieldDefn has been added to a layer definition with
620 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
621 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
622 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
623 : * OGRFieldDefn, for drivers that support AlterFieldDefn.
624 : *
625 : * @param pszDefaultIn new default field value or NULL pointer.
626 : *
627 : * @since GDAL 2.0
628 : */
629 :
630 699700 : void OGRFieldDefn::SetDefault(const char *pszDefaultIn)
631 :
632 : {
633 699700 : if (m_bSealed)
634 : {
635 1 : CPLError(CE_Failure, CPLE_AppDefined,
636 : "OGRFieldDefn::SetDefault() not allowed on a sealed object");
637 1 : return;
638 : }
639 699699 : CPLFree(pszDefault);
640 699699 : pszDefault = nullptr;
641 :
642 699699 : if (pszDefaultIn && pszDefaultIn[0] == '\'' &&
643 1664 : pszDefaultIn[strlen(pszDefaultIn) - 1] == '\'')
644 : {
645 1663 : const char *pszPtr = pszDefaultIn + 1; // Used after for.
646 16078 : for (; *pszPtr != '\0'; pszPtr++)
647 : {
648 16077 : if (*pszPtr == '\'')
649 : {
650 1714 : if (pszPtr[1] == '\0')
651 1661 : break;
652 53 : if (pszPtr[1] != '\'')
653 : {
654 1 : CPLError(CE_Failure, CPLE_AppDefined,
655 : "Incorrectly quoted string literal");
656 1 : return;
657 : }
658 52 : pszPtr++;
659 : }
660 : }
661 1662 : if (*pszPtr == '\0')
662 : {
663 1 : CPLError(CE_Failure, CPLE_AppDefined,
664 : "Incorrectly quoted string literal");
665 1 : return;
666 : }
667 : }
668 :
669 699697 : pszDefault = pszDefaultIn ? CPLStrdup(pszDefaultIn) : nullptr;
670 : }
671 :
672 : /************************************************************************/
673 : /* OGR_Fld_SetDefault() */
674 : /************************************************************************/
675 :
676 : /**
677 : * \brief Set default field value.
678 : *
679 : * The default field value is taken into account by drivers (generally those
680 : * with a SQL interface) that support it at field creation time. OGR will
681 : * generally not automatically set the default field value to null fields by
682 : * itself when calling OGRFeature::CreateFeature() / OGRFeature::SetFeature(),
683 : * but will let the low-level layers to do the job. So retrieving the feature
684 : * from the layer is recommended.
685 : *
686 : * The accepted values are NULL, a numeric value, a literal value enclosed
687 : * between single quote characters (and inner single quote characters escaped by
688 : * repetition of the single quote character),
689 : * CURRENT_TIMESTAMP, CURRENT_TIME, CURRENT_DATE or
690 : * a driver specific expression (that might be ignored by other drivers).
691 : * For a datetime literal value, format should be 'YYYY/MM/DD HH:MM:SS[.sss]'
692 : * (considered as UTC time).
693 : *
694 : * Drivers that support writing DEFAULT clauses will advertise the
695 : * GDAL_DCAP_DEFAULT_FIELDS driver metadata item.
696 : *
697 : * This function is the same as the C++ method OGRFieldDefn::SetDefault().
698 : *
699 : * Note that once a OGRFieldDefn has been added to a layer definition with
700 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
701 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
702 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
703 : * OGRFieldDefn, for drivers that support AlterFieldDefn.
704 : *
705 : * @param hDefn handle to the field definition.
706 : * @param pszDefault new default field value or NULL pointer.
707 : *
708 : * @since GDAL 2.0
709 : */
710 :
711 154 : void CPL_DLL OGR_Fld_SetDefault(OGRFieldDefnH hDefn, const char *pszDefault)
712 : {
713 154 : OGRFieldDefn::FromHandle(hDefn)->SetDefault(pszDefault);
714 154 : }
715 :
716 : /************************************************************************/
717 : /* GetDefault() */
718 : /************************************************************************/
719 :
720 : /**
721 : * \brief Get default field value.
722 : *
723 : * This function is the same as the C function OGR_Fld_GetDefault().
724 : *
725 : * @return default field value or NULL.
726 : * @since GDAL 2.0
727 : */
728 :
729 729760 : const char *OGRFieldDefn::GetDefault() const
730 :
731 : {
732 729760 : return pszDefault;
733 : }
734 :
735 : /************************************************************************/
736 : /* OGR_Fld_GetDefault() */
737 : /************************************************************************/
738 :
739 : /**
740 : * \brief Get default field value.
741 : *
742 : * This function is the same as the C++ method OGRFieldDefn::GetDefault().
743 : *
744 : * @param hDefn handle to the field definition.
745 : * @return default field value or NULL.
746 : * @since GDAL 2.0
747 : */
748 :
749 141 : const char *OGR_Fld_GetDefault(OGRFieldDefnH hDefn)
750 : {
751 141 : return OGRFieldDefn::FromHandle(hDefn)->GetDefault();
752 : }
753 :
754 : /************************************************************************/
755 : /* IsDefaultDriverSpecific() */
756 : /************************************************************************/
757 :
758 : /**
759 : * \brief Returns whether the default value is driver specific.
760 : *
761 : * Driver specific default values are those that are *not* NULL, a
762 : * numeric value, a literal value enclosed between single quote
763 : * characters, CURRENT_TIMESTAMP, CURRENT_TIME, CURRENT_DATE or
764 : * datetime literal value.
765 : *
766 : * This method is the same as the C function
767 : * OGR_Fld_IsDefaultDriverSpecific().
768 : *
769 : * @return TRUE if the default value is driver specific.
770 : * @since GDAL 2.0
771 : */
772 :
773 216 : int OGRFieldDefn::IsDefaultDriverSpecific() const
774 : {
775 216 : if (pszDefault == nullptr)
776 1 : return FALSE;
777 :
778 215 : if (EQUAL(pszDefault, "NULL") || EQUAL(pszDefault, "CURRENT_TIMESTAMP") ||
779 195 : EQUAL(pszDefault, "CURRENT_TIME") || EQUAL(pszDefault, "CURRENT_DATE"))
780 31 : return FALSE;
781 :
782 184 : if (pszDefault[0] == '\'' && pszDefault[strlen(pszDefault) - 1] == '\'')
783 80 : return FALSE;
784 :
785 104 : char *pszEnd = nullptr;
786 104 : CPLStrtod(pszDefault, &pszEnd);
787 104 : if (*pszEnd == '\0')
788 73 : return FALSE;
789 :
790 31 : return TRUE;
791 : }
792 :
793 : /************************************************************************/
794 : /* OGR_Fld_IsDefaultDriverSpecific() */
795 : /************************************************************************/
796 :
797 : /**
798 : * \brief Returns whether the default value is driver specific.
799 : *
800 : * Driver specific default values are those that are *not* NULL, a
801 : * numeric value, a literal value enclosed between single quote
802 : * characters, CURRENT_TIMESTAMP, CURRENT_TIME, CURRENT_DATE or
803 : * datetime literal value.
804 : *
805 : * This function is the same as the C++ method
806 : * OGRFieldDefn::IsDefaultDriverSpecific().
807 : *
808 : * @param hDefn handle to the field definition
809 : * @return TRUE if the default value is driver specific.
810 : * @since GDAL 2.0
811 : */
812 :
813 3 : int OGR_Fld_IsDefaultDriverSpecific(OGRFieldDefnH hDefn)
814 : {
815 3 : return OGRFieldDefn::FromHandle(hDefn)->IsDefaultDriverSpecific();
816 : }
817 :
818 : /************************************************************************/
819 : /* GetFieldTypeName() */
820 : /************************************************************************/
821 :
822 : /**
823 : * \brief Fetch human readable name for a field type.
824 : *
825 : * This static method is the same as the C function OGR_GetFieldTypeName().
826 : *
827 : * @param eType the field type to get name for.
828 : *
829 : * @return pointer to an internal static name string. It should not be
830 : * modified or freed.
831 : */
832 :
833 15849 : const char *OGRFieldDefn::GetFieldTypeName(OGRFieldType eType)
834 :
835 : {
836 15849 : switch (eType)
837 : {
838 3106 : case OFTInteger:
839 3106 : return "Integer";
840 :
841 974 : case OFTInteger64:
842 974 : return "Integer64";
843 :
844 1492 : case OFTReal:
845 1492 : return "Real";
846 :
847 5735 : case OFTString:
848 5735 : return "String";
849 :
850 1178 : case OFTIntegerList:
851 1178 : return "IntegerList";
852 :
853 225 : case OFTInteger64List:
854 225 : return "Integer64List";
855 :
856 862 : case OFTRealList:
857 862 : return "RealList";
858 :
859 443 : case OFTStringList:
860 443 : return "StringList";
861 :
862 332 : case OFTBinary:
863 332 : return "Binary";
864 :
865 322 : case OFTDate:
866 322 : return "Date";
867 :
868 261 : case OFTTime:
869 261 : return "Time";
870 :
871 469 : case OFTDateTime:
872 469 : return "DateTime";
873 :
874 450 : case OFTWideString:
875 : case OFTWideStringList:
876 450 : break;
877 : }
878 :
879 450 : return "(unknown)";
880 : }
881 :
882 : /************************************************************************/
883 : /* OGR_GetFieldTypeName() */
884 : /************************************************************************/
885 : /**
886 : * \brief Fetch human readable name for a field type.
887 : *
888 : * This function is the same as the CPP method
889 : * OGRFieldDefn::GetFieldTypeName().
890 : *
891 : * @param eType the field type to get name for.
892 : * @return the name.
893 : */
894 :
895 2196 : const char *OGR_GetFieldTypeName(OGRFieldType eType)
896 :
897 : {
898 2196 : return OGRFieldDefn::GetFieldTypeName(eType);
899 : }
900 :
901 : /************************************************************************/
902 : /* GetFieldSubTypeName() */
903 : /************************************************************************/
904 :
905 : /**
906 : * \brief Fetch human readable name for a field subtype.
907 : *
908 : * This static method is the same as the C function OGR_GetFieldSubTypeName().
909 : *
910 : * @param eSubType the field subtype to get name for.
911 : *
912 : * @return pointer to an internal static name string. It should not be
913 : * modified or freed.
914 : *
915 : * @since GDAL 2.0
916 : */
917 :
918 3862 : const char *OGRFieldDefn::GetFieldSubTypeName(OGRFieldSubType eSubType)
919 :
920 : {
921 3862 : switch (eSubType)
922 : {
923 1148 : case OFSTNone:
924 1148 : break;
925 :
926 678 : case OFSTBoolean:
927 678 : return "Boolean";
928 :
929 1008 : case OFSTInt16:
930 1008 : return "Int16";
931 :
932 321 : case OFSTFloat32:
933 321 : return "Float32";
934 :
935 706 : case OFSTJSON:
936 706 : return "JSON";
937 :
938 1 : case OFSTUUID:
939 1 : return "UUID";
940 : }
941 1148 : return "None";
942 : }
943 :
944 : /************************************************************************/
945 : /* OGR_GetFieldSubTypeName() */
946 : /************************************************************************/
947 : /**
948 : * \brief Fetch human readable name for a field subtype.
949 : *
950 : * This function is the same as the CPP method
951 : * OGRFieldDefn::GetFieldSubTypeName().
952 : *
953 : * @param eSubType the field subtype to get name for.
954 : * @return the name.
955 : *
956 : * @since GDAL 2.0
957 : */
958 :
959 2282 : const char *OGR_GetFieldSubTypeName(OGRFieldSubType eSubType)
960 :
961 : {
962 2282 : return OGRFieldDefn::GetFieldSubTypeName(eSubType);
963 : }
964 :
965 : /************************************************************************/
966 : /* OGR_IsValidTypeAndSubType() */
967 : /************************************************************************/
968 : /**
969 : * \brief Return if type and subtype are compatible
970 : *
971 : * @param eType the field type.
972 : * @param eSubType the field subtype.
973 : * @return TRUE if type and subtype are compatible
974 : *
975 : * @since GDAL 2.0
976 : */
977 :
978 547951 : int OGR_AreTypeSubTypeCompatible(OGRFieldType eType, OGRFieldSubType eSubType)
979 : {
980 547951 : if (eSubType == OFSTNone)
981 534987 : return TRUE;
982 12964 : if (eSubType == OFSTBoolean || eSubType == OFSTInt16)
983 5710 : return eType == OFTInteger || eType == OFTIntegerList;
984 7254 : if (eSubType == OFSTFloat32)
985 2564 : return eType == OFTReal || eType == OFTRealList;
986 4690 : if (eSubType == OFSTJSON)
987 4685 : return eType == OFTString;
988 5 : if (eSubType == OFSTUUID)
989 5 : return eType == OFTString;
990 0 : return FALSE;
991 : }
992 :
993 : /************************************************************************/
994 : /* GetJustify() */
995 : /************************************************************************/
996 :
997 : /**
998 : * \fn OGRJustification OGRFieldDefn::GetJustify() const;
999 : *
1000 : * \brief Get the justification for this field.
1001 : *
1002 : * Note: no driver is know to use the concept of field justification.
1003 : *
1004 : * This method is the same as the C function OGR_Fld_GetJustify().
1005 : *
1006 : * @return the justification.
1007 : */
1008 :
1009 : /************************************************************************/
1010 : /* OGR_Fld_GetJustify() */
1011 : /************************************************************************/
1012 : /**
1013 : * \brief Get the justification for this field.
1014 : *
1015 : * This function is the same as the CPP method OGRFieldDefn::GetJustify().
1016 : *
1017 : * Note: no driver is know to use the concept of field justification.
1018 : *
1019 : * @param hDefn handle to the field definition to get justification from.
1020 : * @return the justification.
1021 : */
1022 :
1023 0 : OGRJustification OGR_Fld_GetJustify(OGRFieldDefnH hDefn)
1024 :
1025 : {
1026 0 : return OGRFieldDefn::FromHandle(hDefn)->GetJustify();
1027 : }
1028 :
1029 : /************************************************************************/
1030 : /* SetJustify() */
1031 : /************************************************************************/
1032 :
1033 : /**
1034 : * \fn void OGRFieldDefn::SetJustify( OGRJustification eJustify );
1035 : *
1036 : * \brief Set the justification for this field.
1037 : *
1038 : * Note: no driver is know to use the concept of field justification.
1039 : *
1040 : * This method is the same as the C function OGR_Fld_SetJustify().
1041 : *
1042 : * @param eJustify the new justification.
1043 : */
1044 :
1045 : /************************************************************************/
1046 : /* OGR_Fld_SetJustify() */
1047 : /************************************************************************/
1048 : /**
1049 : * \brief Set the justification for this field.
1050 : *
1051 : * Note: no driver is know to use the concept of field justification.
1052 : *
1053 : * This function is the same as the CPP method OGRFieldDefn::SetJustify().
1054 : *
1055 : * @param hDefn handle to the field definition to set justification to.
1056 : * @param eJustify the new justification.
1057 : */
1058 :
1059 0 : void OGR_Fld_SetJustify(OGRFieldDefnH hDefn, OGRJustification eJustify)
1060 :
1061 : {
1062 0 : OGRFieldDefn::FromHandle(hDefn)->SetJustify(eJustify);
1063 0 : }
1064 :
1065 : /************************************************************************/
1066 : /* GetWidth() */
1067 : /************************************************************************/
1068 :
1069 : /**
1070 : * \fn int OGRFieldDefn::GetWidth() const;
1071 : *
1072 : * \brief Get the formatting width for this field.
1073 : *
1074 : * This method is the same as the C function OGR_Fld_GetWidth().
1075 : *
1076 : * @return the width, zero means no specified width.
1077 : */
1078 :
1079 : /************************************************************************/
1080 : /* OGR_Fld_GetWidth() */
1081 : /************************************************************************/
1082 : /**
1083 : * \brief Get the formatting width for this field.
1084 : *
1085 : * This function is the same as the CPP method OGRFieldDefn::GetWidth().
1086 : *
1087 : * @param hDefn handle to the field definition to get width from.
1088 : * @return the width, zero means no specified width.
1089 : */
1090 :
1091 2580 : int OGR_Fld_GetWidth(OGRFieldDefnH hDefn)
1092 :
1093 : {
1094 2580 : return OGRFieldDefn::FromHandle(hDefn)->GetWidth();
1095 : }
1096 :
1097 : /************************************************************************/
1098 : /* SetWidth() */
1099 : /************************************************************************/
1100 :
1101 : /**
1102 : * \brief Set the formatting width for this field in characters.
1103 : *
1104 : * This method is the same as the C function OGR_Fld_SetWidth().
1105 : *
1106 : * Note that once a OGRFieldDefn has been added to a layer definition with
1107 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
1108 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
1109 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
1110 : * OGRFieldDefn, for drivers that support AlterFieldDefn.
1111 : *
1112 : * @param nWidthIn the new width.
1113 : */
1114 375414 : void OGRFieldDefn::SetWidth(int nWidthIn)
1115 : {
1116 375414 : if (m_bSealed)
1117 : {
1118 1 : CPLError(CE_Failure, CPLE_AppDefined,
1119 : "OGRFieldDefn::SetWidth() not allowed on a sealed object");
1120 1 : return;
1121 : }
1122 375413 : nWidth = MAX(0, nWidthIn);
1123 : }
1124 :
1125 : /************************************************************************/
1126 : /* OGR_Fld_SetWidth() */
1127 : /************************************************************************/
1128 : /**
1129 : * \brief Set the formatting width for this field in characters.
1130 : *
1131 : * This function is the same as the CPP method OGRFieldDefn::SetWidth().
1132 : *
1133 : * Note that once a OGRFieldDefn has been added to a layer definition with
1134 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
1135 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
1136 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
1137 : * OGRFieldDefn, for drivers that support AlterFieldDefn.
1138 : *
1139 : * @param hDefn handle to the field definition to set width to.
1140 : * @param nNewWidth the new width.
1141 : */
1142 :
1143 323 : void OGR_Fld_SetWidth(OGRFieldDefnH hDefn, int nNewWidth)
1144 :
1145 : {
1146 323 : OGRFieldDefn::FromHandle(hDefn)->SetWidth(nNewWidth);
1147 323 : }
1148 :
1149 : /************************************************************************/
1150 : /* GetPrecision() */
1151 : /************************************************************************/
1152 :
1153 : /**
1154 : * \fn int OGRFieldDefn::GetPrecision() const;
1155 : *
1156 : * \brief Get the formatting precision for this field.
1157 : * This should normally be
1158 : * zero for fields of types other than OFTReal.
1159 : *
1160 : * This method is the same as the C function OGR_Fld_GetPrecision().
1161 : *
1162 : * @return the precision.
1163 : */
1164 :
1165 : /************************************************************************/
1166 : /* OGR_Fld_GetPrecision() */
1167 : /************************************************************************/
1168 : /**
1169 : * \brief Get the formatting precision for this field.
1170 : * This should normally be
1171 : * zero for fields of types other than OFTReal.
1172 : *
1173 : * This function is the same as the CPP method OGRFieldDefn::GetPrecision().
1174 : *
1175 : * @param hDefn handle to the field definition to get precision from.
1176 : * @return the precision.
1177 : */
1178 :
1179 1464 : int OGR_Fld_GetPrecision(OGRFieldDefnH hDefn)
1180 :
1181 : {
1182 1464 : return OGRFieldDefn::FromHandle(hDefn)->GetPrecision();
1183 : }
1184 :
1185 : /************************************************************************/
1186 : /* SetPrecision() */
1187 : /************************************************************************/
1188 :
1189 : /**
1190 : * \brief Set the formatting precision for this field in characters.
1191 : *
1192 : * This should normally be zero for fields of types other than OFTReal.
1193 : *
1194 : * This method is the same as the C function OGR_Fld_SetPrecision().
1195 : *
1196 : * Note that once a OGRFieldDefn has been added to a layer definition with
1197 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
1198 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
1199 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
1200 : * OGRFieldDefn, for drivers that support AlterFieldDefn.
1201 : *
1202 : * @param nPrecisionIn the new precision.
1203 : */
1204 181722 : void OGRFieldDefn::SetPrecision(int nPrecisionIn)
1205 : {
1206 181722 : if (m_bSealed)
1207 : {
1208 1 : CPLError(CE_Failure, CPLE_AppDefined,
1209 : "OGRFieldDefn::SetPrecision() not allowed on a sealed object");
1210 1 : return;
1211 : }
1212 181721 : nPrecision = nPrecisionIn;
1213 : }
1214 :
1215 : /************************************************************************/
1216 : /* OGR_Fld_SetPrecision() */
1217 : /************************************************************************/
1218 : /**
1219 : * \brief Set the formatting precision for this field in characters.
1220 : *
1221 : * This should normally be zero for fields of types other than OFTReal.
1222 : *
1223 : * This function is the same as the CPP method OGRFieldDefn::SetPrecision().
1224 : *
1225 : * Note that once a OGRFieldDefn has been added to a layer definition with
1226 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
1227 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
1228 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
1229 : * OGRFieldDefn, for drivers that support AlterFieldDefn.
1230 : *
1231 : * @param hDefn handle to the field definition to set precision to.
1232 : * @param nPrecision the new precision.
1233 : */
1234 :
1235 25 : void OGR_Fld_SetPrecision(OGRFieldDefnH hDefn, int nPrecision)
1236 :
1237 : {
1238 25 : OGRFieldDefn::FromHandle(hDefn)->SetPrecision(nPrecision);
1239 25 : }
1240 :
1241 : /************************************************************************/
1242 : /* GetTZFlag() */
1243 : /************************************************************************/
1244 :
1245 : /**
1246 : * \fn int OGRFieldDefn::GetTZFlag() const;
1247 : *
1248 : * \brief Get the time zone flag.
1249 : *
1250 : * Only applies to OFTTime, OFTDate and OFTDateTime fields.
1251 : *
1252 : * Cf OGR_TZFLAG_UNKNOWN, OGR_TZFLAG_LOCALTIME, OGR_TZFLAG_MIXED_TZ and
1253 : * OGR_TZFLAG_UTC
1254 : *
1255 : * This method is the same as the C function OGR_Fld_GetTZFlag().
1256 : *
1257 : * @return the time zone flag.
1258 : * @since GDAL 3.8
1259 : */
1260 :
1261 : /************************************************************************/
1262 : /* OGR_Fld_GetTZFlag() */
1263 : /************************************************************************/
1264 : /**
1265 : * \brief Get the time zone flag.
1266 : *
1267 : * Only applies to OFTTime, OFTDate and OFTDateTime fields.
1268 : *
1269 : * Cf OGR_TZFLAG_UNKNOWN, OGR_TZFLAG_LOCALTIME, OGR_TZFLAG_MIXED_TZ and
1270 : * OGR_TZFLAG_UTC
1271 : *
1272 : * @param hDefn handle to the field definition .
1273 : * @return the time zone flag.
1274 : * @since GDAL 3.8
1275 : */
1276 :
1277 0 : int OGR_Fld_GetTZFlag(OGRFieldDefnH hDefn)
1278 :
1279 : {
1280 0 : return OGRFieldDefn::FromHandle(hDefn)->GetTZFlag();
1281 : }
1282 :
1283 : /************************************************************************/
1284 : /* SetTZFlag() */
1285 : /************************************************************************/
1286 :
1287 : /**
1288 : * \brief Set the time zone flag.
1289 : *
1290 : * Only applies to OFTTime, OFTDate and OFTDateTime fields.
1291 : *
1292 : * Cf OGR_TZFLAG_UNKNOWN, OGR_TZFLAG_LOCALTIME, OGR_TZFLAG_MIXED_TZ and
1293 : * OGR_TZFLAG_UTC
1294 : *
1295 : * This method is the same as the C function OGR_Fld_SetTZFlag().
1296 : *
1297 : * Note that once a OGRFieldDefn has been added to a layer definition with
1298 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
1299 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
1300 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
1301 : * OGRFieldDefn, for drivers that support AlterFieldDefn.
1302 : *
1303 : * @param nTZFlag the new time zone flag.
1304 : * @since GDAL 3.8
1305 : */
1306 1735 : void OGRFieldDefn::SetTZFlag(int nTZFlag)
1307 : {
1308 1735 : if (m_bSealed)
1309 : {
1310 1 : CPLError(CE_Failure, CPLE_AppDefined,
1311 : "OGRFieldDefn::SetTZFlag() not allowed on a sealed object");
1312 1 : return;
1313 : }
1314 1734 : m_nTZFlag = nTZFlag;
1315 : }
1316 :
1317 : /************************************************************************/
1318 : /* OGR_Fld_SetTZFlag() */
1319 : /************************************************************************/
1320 : /**
1321 : * \brief Set the formatting precision for this field in characters.
1322 : *
1323 : * Set the time zone flag.
1324 : *
1325 : * Only applies to OFTTime, OFTDate and OFTDateTime fields.
1326 : *
1327 : * Cf OGR_TZFLAG_UNKNOWN, OGR_TZFLAG_LOCALTIME, OGR_TZFLAG_MIXED_TZ and
1328 : * OGR_TZFLAG_UTC
1329 : *
1330 : * Note that once a OGRFieldDefn has been added to a layer definition with
1331 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
1332 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
1333 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
1334 : * OGRFieldDefn, for drivers that support AlterFieldDefn.
1335 : *
1336 : * @param hDefn handle to the field definition to set precision to.
1337 : * @param nTZFlag the new time zone flag.
1338 : * @since GDAL 3.8
1339 : */
1340 :
1341 6 : void OGR_Fld_SetTZFlag(OGRFieldDefnH hDefn, int nTZFlag)
1342 :
1343 : {
1344 6 : OGRFieldDefn::FromHandle(hDefn)->SetTZFlag(nTZFlag);
1345 6 : }
1346 :
1347 : /************************************************************************/
1348 : /* Set() */
1349 : /************************************************************************/
1350 :
1351 : /**
1352 : * \brief Set defining parameters for a field in one call.
1353 : *
1354 : * This method is the same as the C function OGR_Fld_Set().
1355 : *
1356 : * Note that once a OGRFieldDefn has been added to a layer definition with
1357 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
1358 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
1359 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
1360 : * OGRFieldDefn, for drivers that support AlterFieldDefn.
1361 : *
1362 : * @param pszNameIn the new name to assign.
1363 : * @param eTypeIn the new type (one of the OFT values like OFTInteger).
1364 : * @param nWidthIn the preferred formatting width. Defaults to zero indicating
1365 : * undefined.
1366 : * @param nPrecisionIn number of decimals places for formatting, defaults to
1367 : * zero indicating undefined.
1368 : * @param eJustifyIn the formatting justification (OJLeft or OJRight), defaults
1369 : * to OJUndefined.
1370 : */
1371 :
1372 85769 : void OGRFieldDefn::Set(const char *pszNameIn, OGRFieldType eTypeIn,
1373 : int nWidthIn, int nPrecisionIn,
1374 : OGRJustification eJustifyIn)
1375 : {
1376 85769 : if (m_bSealed)
1377 : {
1378 0 : CPLError(CE_Failure, CPLE_AppDefined,
1379 : "OGRFieldDefn::Set() not allowed on a sealed object");
1380 0 : return;
1381 : }
1382 85769 : SetName(pszNameIn);
1383 85769 : SetType(eTypeIn);
1384 85769 : SetWidth(nWidthIn);
1385 85769 : SetPrecision(nPrecisionIn);
1386 85769 : SetJustify(eJustifyIn);
1387 : }
1388 :
1389 : /************************************************************************/
1390 : /* OGR_Fld_Set() */
1391 : /************************************************************************/
1392 : /**
1393 : * \brief Set defining parameters for a field in one call.
1394 : *
1395 : * This function is the same as the CPP method OGRFieldDefn::Set().
1396 : *
1397 : * Note that once a OGRFieldDefn has been added to a layer definition with
1398 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
1399 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
1400 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
1401 : * OGRFieldDefn, for drivers that support AlterFieldDefn.
1402 : *
1403 : * @param hDefn handle to the field definition to set to.
1404 : * @param pszNameIn the new name to assign.
1405 : * @param eTypeIn the new type (one of the OFT values like OFTInteger).
1406 : * @param nWidthIn the preferred formatting width. Defaults to zero indicating
1407 : * undefined.
1408 : * @param nPrecisionIn number of decimals places for formatting, defaults to
1409 : * zero indicating undefined.
1410 : * @param eJustifyIn the formatting justification (OJLeft or OJRight), defaults
1411 : * to OJUndefined.
1412 : */
1413 :
1414 0 : void OGR_Fld_Set(OGRFieldDefnH hDefn, const char *pszNameIn,
1415 : OGRFieldType eTypeIn, int nWidthIn, int nPrecisionIn,
1416 : OGRJustification eJustifyIn)
1417 :
1418 : {
1419 0 : OGRFieldDefn::FromHandle(hDefn)->Set(pszNameIn, eTypeIn, nWidthIn,
1420 : nPrecisionIn, eJustifyIn);
1421 0 : }
1422 :
1423 : /************************************************************************/
1424 : /* IsIgnored() */
1425 : /************************************************************************/
1426 :
1427 : /**
1428 : * \fn int OGRFieldDefn::IsIgnored() const;
1429 : *
1430 : * \brief Return whether this field should be omitted when fetching features
1431 : *
1432 : * This method is the same as the C function OGR_Fld_IsIgnored().
1433 : *
1434 : * @return ignore state
1435 : */
1436 :
1437 : /************************************************************************/
1438 : /* OGR_Fld_IsIgnored() */
1439 : /************************************************************************/
1440 :
1441 : /**
1442 : * \brief Return whether this field should be omitted when fetching features
1443 : *
1444 : * This method is the same as the C++ method OGRFieldDefn::IsIgnored().
1445 : *
1446 : * @param hDefn handle to the field definition
1447 : * @return ignore state
1448 : */
1449 :
1450 6 : int OGR_Fld_IsIgnored(OGRFieldDefnH hDefn)
1451 : {
1452 6 : return OGRFieldDefn::FromHandle(hDefn)->IsIgnored();
1453 : }
1454 :
1455 : /************************************************************************/
1456 : /* SetIgnored() */
1457 : /************************************************************************/
1458 :
1459 : /**
1460 : * \fn void OGRFieldDefn::SetIgnored( int ignore );
1461 : *
1462 : * \brief Set whether this field should be omitted when fetching features
1463 : *
1464 : * This method is the same as the C function OGR_Fld_SetIgnored().
1465 : *
1466 : * This method should not be called on a object returned with
1467 : * OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead, the
1468 : * OGRLayer::SetIgnoredFields() method should be called.
1469 : *
1470 : * @param ignore ignore state
1471 : */
1472 :
1473 : /************************************************************************/
1474 : /* OGR_Fld_SetIgnored() */
1475 : /************************************************************************/
1476 :
1477 : /**
1478 : * \brief Set whether this field should be omitted when fetching features
1479 : *
1480 : * This method is the same as the C++ method OGRFieldDefn::SetIgnored().
1481 : *
1482 : * This method should not be called on a object returned with
1483 : * OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead, the
1484 : * OGRLayer::SetIgnoredFields() method should be called.
1485 : *
1486 : * @param hDefn handle to the field definition
1487 : * @param ignore ignore state
1488 : */
1489 :
1490 0 : void OGR_Fld_SetIgnored(OGRFieldDefnH hDefn, int ignore)
1491 : {
1492 0 : OGRFieldDefn::FromHandle(hDefn)->SetIgnored(ignore);
1493 0 : }
1494 :
1495 : /************************************************************************/
1496 : /* IsSame() */
1497 : /************************************************************************/
1498 :
1499 : /**
1500 : * \brief Test if the field definition is identical to the other one.
1501 : *
1502 : * @param poOtherFieldDefn the other field definition to compare to.
1503 : * @return TRUE if the field definition is identical to the other one.
1504 : */
1505 :
1506 612 : int OGRFieldDefn::IsSame(const OGRFieldDefn *poOtherFieldDefn) const
1507 : {
1508 1223 : return strcmp(pszName, poOtherFieldDefn->pszName) == 0 &&
1509 611 : strcmp(pszAlternativeName, poOtherFieldDefn->pszAlternativeName) ==
1510 610 : 0 &&
1511 610 : eType == poOtherFieldDefn->eType &&
1512 610 : eSubType == poOtherFieldDefn->eSubType &&
1513 610 : nWidth == poOtherFieldDefn->nWidth &&
1514 609 : nPrecision == poOtherFieldDefn->nPrecision &&
1515 1218 : bNullable == poOtherFieldDefn->bNullable &&
1516 1832 : m_osComment == poOtherFieldDefn->m_osComment &&
1517 1220 : m_nTZFlag == poOtherFieldDefn->m_nTZFlag;
1518 : }
1519 :
1520 : /************************************************************************/
1521 : /* IsNullable() */
1522 : /************************************************************************/
1523 :
1524 : /**
1525 : * \fn int OGRFieldDefn::IsNullable() const
1526 : *
1527 : * \brief Return whether this field can receive null values.
1528 : *
1529 : * By default, fields are nullable.
1530 : *
1531 : * Even if this method returns FALSE (i.e not-nullable field), it doesn't mean
1532 : * that OGRFeature::IsFieldSet() will necessary return TRUE, as fields can be
1533 : * temporary unset and null/not-null validation is usually done when
1534 : * OGRLayer::CreateFeature()/SetFeature() is called.
1535 : *
1536 : * This method is the same as the C function OGR_Fld_IsNullable().
1537 : *
1538 : * @return TRUE if the field is authorized to be null.
1539 : * @since GDAL 2.0
1540 : */
1541 :
1542 : /************************************************************************/
1543 : /* OGR_Fld_IsNullable() */
1544 : /************************************************************************/
1545 :
1546 : /**
1547 : * \brief Return whether this field can receive null values.
1548 : *
1549 : * By default, fields are nullable.
1550 : *
1551 : * Even if this method returns FALSE (i.e not-nullable field), it doesn't mean
1552 : * that OGRFeature::IsFieldSet() will necessary return TRUE, as fields can be
1553 : * temporary unset and null/not-null validation is usually done when
1554 : * OGRLayer::CreateFeature()/SetFeature() is called.
1555 : *
1556 : * This method is the same as the C++ method OGRFieldDefn::IsNullable().
1557 : *
1558 : * @param hDefn handle to the field definition
1559 : * @return TRUE if the field is authorized to be null.
1560 : * @since GDAL 2.0
1561 : */
1562 :
1563 80 : int OGR_Fld_IsNullable(OGRFieldDefnH hDefn)
1564 : {
1565 80 : return OGRFieldDefn::FromHandle(hDefn)->IsNullable();
1566 : }
1567 :
1568 : /************************************************************************/
1569 : /* SetNullable() */
1570 : /************************************************************************/
1571 :
1572 : /**
1573 : * \fn void OGRFieldDefn::SetNullable( int bNullableIn );
1574 : *
1575 : * \brief Set whether this field can receive null values.
1576 : *
1577 : * By default, fields are nullable, so this method is generally called with
1578 : * FALSE to set a not-null constraint.
1579 : *
1580 : * Drivers that support writing not-null constraint will advertise the
1581 : * GDAL_DCAP_NOTNULL_FIELDS driver metadata item.
1582 : *
1583 : * This method is the same as the C function OGR_Fld_SetNullable().
1584 : *
1585 : * Note that once a OGRFieldDefn has been added to a layer definition with
1586 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
1587 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
1588 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
1589 : * OGRFieldDefn, for drivers that support AlterFieldDefn().
1590 : *
1591 : * @param bNullableIn FALSE if the field must have a not-null constraint.
1592 : * @since GDAL 2.0
1593 : */
1594 165580 : void OGRFieldDefn::SetNullable(int bNullableIn)
1595 : {
1596 165580 : if (m_bSealed)
1597 : {
1598 1 : CPLError(CE_Failure, CPLE_AppDefined,
1599 : "OGRFieldDefn::SetNullable() not allowed on a sealed object");
1600 1 : return;
1601 : }
1602 165579 : bNullable = bNullableIn;
1603 : }
1604 :
1605 : /************************************************************************/
1606 : /* OGR_Fld_SetNullable() */
1607 : /************************************************************************/
1608 :
1609 : /**
1610 : * \brief Set whether this field can receive null values.
1611 : *
1612 : * By default, fields are nullable, so this method is generally called with
1613 : * FALSE to set a not-null constraint.
1614 : *
1615 : * Drivers that support writing not-null constraint will advertise the
1616 : * GDAL_DCAP_NOTNULL_FIELDS driver metadata item.
1617 : *
1618 : * This method is the same as the C++ method OGRFieldDefn::SetNullable().
1619 : *
1620 : * Note that once a OGRFieldDefn has been added to a layer definition with
1621 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
1622 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
1623 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
1624 : * OGRFieldDefn, for drivers that support AlterFieldDefn().
1625 : *
1626 : * @param hDefn handle to the field definition
1627 : * @param bNullableIn FALSE if the field must have a not-null constraint.
1628 : * @since GDAL 2.0
1629 : */
1630 :
1631 190 : void OGR_Fld_SetNullable(OGRFieldDefnH hDefn, int bNullableIn)
1632 : {
1633 190 : OGRFieldDefn::FromHandle(hDefn)->SetNullable(bNullableIn);
1634 190 : }
1635 :
1636 : /************************************************************************/
1637 : /* IsUnique() */
1638 : /************************************************************************/
1639 :
1640 : /**
1641 : * \fn int OGRFieldDefn::IsUnique() const
1642 : *
1643 : * \brief Return whether this field has a unique constraint.
1644 : *
1645 : * By default, fields have no unique constraint.
1646 : *
1647 : * This method is the same as the C function OGR_Fld_IsUnique().
1648 : *
1649 : * @return TRUE if the field has a unique constraint.
1650 : * @since GDAL 3.2
1651 : */
1652 :
1653 : /************************************************************************/
1654 : /* OGR_Fld_IsUnique() */
1655 : /************************************************************************/
1656 :
1657 : /**
1658 : * \brief Return whether this field has a unique constraint.
1659 : *
1660 : * By default, fields have no unique constraint.
1661 : *
1662 : * This method is the same as the C++ method OGRFieldDefn::IsUnique().
1663 : *
1664 : * @param hDefn handle to the field definition
1665 : * @return TRUE if the field has a unique constraint.
1666 : * @since GDAL 3.2
1667 : */
1668 :
1669 78 : int OGR_Fld_IsUnique(OGRFieldDefnH hDefn)
1670 : {
1671 78 : return OGRFieldDefn::FromHandle(hDefn)->IsUnique();
1672 : }
1673 :
1674 : /********************************************************* ***************/
1675 : /* SetUnique() */
1676 : /************************************************************************/
1677 :
1678 : /**
1679 : * \brief Set whether this field has a unique constraint.
1680 : *
1681 : * By default, fields have no unique constraint, so this method is generally
1682 : * called with TRUE to set a unique constraint.
1683 : *
1684 : * Drivers that support writing unique constraint will advertise the
1685 : * GDAL_DCAP_UNIQUE_FIELDS driver metadata item.
1686 : *
1687 : * This method is the same as the C function OGR_Fld_SetUnique().
1688 : *
1689 : * Note that once a OGRFieldDefn has been added to a layer definition with
1690 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
1691 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
1692 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
1693 : * OGRFieldDefn, for drivers that support AlterFieldDefn().
1694 : *
1695 : * @param bUniqueIn TRUE if the field must have a unique constraint.
1696 : * @since GDAL 3.2
1697 : */
1698 67878 : void OGRFieldDefn::SetUnique(int bUniqueIn)
1699 : {
1700 67878 : if (m_bSealed)
1701 : {
1702 1 : CPLError(CE_Failure, CPLE_AppDefined,
1703 : "OGRFieldDefn::SetUnique() not allowed on a sealed object");
1704 1 : return;
1705 : }
1706 67877 : bUnique = bUniqueIn;
1707 : }
1708 :
1709 : /************************************************************************/
1710 : /* OGR_Fld_SetUnique() */
1711 : /************************************************************************/
1712 :
1713 : /**
1714 : * \brief Set whether this field has a unique constraint.
1715 : *
1716 : * By default, fields have no unique constraint, so this method is generally
1717 : *called with TRUE to set a unique constraint.
1718 : *
1719 : * Drivers that support writing unique constraint will advertise the
1720 : * GDAL_DCAP_UNIQUE_FIELDS driver metadata item.
1721 : *field can receive null values.
1722 : *
1723 : * This method is the same as the C++ method OGRFieldDefn::SetUnique().
1724 : *
1725 : * Note that once a OGRFieldDefn has been added to a layer definition with
1726 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
1727 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
1728 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
1729 : * OGRFieldDefn, for drivers that support AlterFieldDefn().
1730 : *
1731 : * @param hDefn handle to the field definition
1732 : * @param bUniqueIn TRUE if the field must have a unique constraint.
1733 : * @since GDAL 3.2
1734 : */
1735 :
1736 28 : void OGR_Fld_SetUnique(OGRFieldDefnH hDefn, int bUniqueIn)
1737 : {
1738 28 : OGRFieldDefn::FromHandle(hDefn)->SetUnique(bUniqueIn);
1739 28 : }
1740 :
1741 : /************************************************************************/
1742 : /* GetDomainName() */
1743 : /************************************************************************/
1744 :
1745 : /**
1746 : * \fn const std::string& OGRFieldDefn::GetDomainName() const
1747 : *
1748 : * \brief Return the name of the field domain for this field.
1749 : *
1750 : * By default, none (empty string) is returned.
1751 : *
1752 : * Field domains (OGRFieldDomain class) are attached at the GDALDataset level
1753 : * and should be retrieved with GDALDataset::GetFieldDomain().
1754 : *
1755 : * This method is the same as the C function OGR_Fld_GetDomainName().
1756 : *
1757 : * @return the field domain name, or an empty string if there is none.
1758 : * @since GDAL 3.3
1759 : */
1760 :
1761 : /************************************************************************/
1762 : /* OGR_Fld_GetDomainName() */
1763 : /************************************************************************/
1764 :
1765 : /**
1766 : * \brief Return the name of the field domain for this field.
1767 : *
1768 : * By default, none (empty string) is returned.
1769 : *
1770 : * Field domains (OGRFieldDomain class) are attached at the GDALDataset level
1771 : * and should be retrieved with GDALDatasetGetFieldDomain().
1772 : *
1773 : * This method is the same as the C++ method OGRFieldDefn::GetDomainName().
1774 : *
1775 : * @param hDefn handle to the field definition
1776 : * @return the field domain name, or an empty string if there is none.
1777 : * @since GDAL 3.3
1778 : */
1779 :
1780 34 : const char *OGR_Fld_GetDomainName(OGRFieldDefnH hDefn)
1781 : {
1782 34 : return OGRFieldDefn::FromHandle(hDefn)->GetDomainName().c_str();
1783 : }
1784 :
1785 : /************************************************************************/
1786 : /* SetDomainName() */
1787 : /************************************************************************/
1788 :
1789 : /**
1790 : * \brief Set the name of the field domain for this field.
1791 : *
1792 : * Field domains (OGRFieldDomain) are attached at the GDALDataset level.
1793 : *
1794 : * This method is the same as the C function OGR_Fld_SetDomainName().
1795 : *
1796 : * Note that once a OGRFieldDefn has been added to a layer definition with
1797 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
1798 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
1799 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
1800 : * OGRFieldDefn, for drivers that support AlterFieldDefn().
1801 : *
1802 : * @param osDomainName Field domain name.
1803 : * @since GDAL 3.3
1804 : */
1805 12812 : void OGRFieldDefn::SetDomainName(const std::string &osDomainName)
1806 : {
1807 12812 : if (m_bSealed)
1808 : {
1809 1 : CPLError(
1810 : CE_Failure, CPLE_AppDefined,
1811 : "OGRFieldDefn::SetDomainName() not allowed on a sealed object");
1812 1 : return;
1813 : }
1814 12811 : m_osDomainName = osDomainName;
1815 : }
1816 :
1817 : /************************************************************************/
1818 : /* OGR_Fld_SetDomainName() */
1819 : /************************************************************************/
1820 :
1821 : /**
1822 : * \brief Set the name of the field domain for this field.
1823 : *
1824 : * Field domains (OGRFieldDomain) are attached at the GDALDataset level.
1825 : *
1826 : * This method is the same as the C++ method OGRFieldDefn::SetDomainName().
1827 : *
1828 : * Note that once a OGRFieldDefn has been added to a layer definition with
1829 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
1830 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
1831 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
1832 : * OGRFieldDefn, for drivers that support AlterFieldDefn().
1833 : *
1834 : * @param hDefn handle to the field definition
1835 : * @param pszFieldName Field domain name.
1836 : * @since GDAL 3.3
1837 : */
1838 :
1839 21 : void OGR_Fld_SetDomainName(OGRFieldDefnH hDefn, const char *pszFieldName)
1840 : {
1841 21 : OGRFieldDefn::FromHandle(hDefn)->SetDomainName(pszFieldName ? pszFieldName
1842 : : "");
1843 21 : }
1844 :
1845 : /************************************************************************/
1846 : /* GetComment() */
1847 : /************************************************************************/
1848 :
1849 : /**
1850 : * \fn const std::string& OGRFieldDefn::GetComment() const
1851 : *
1852 : * \brief Return the (optional) comment for this field.
1853 : *
1854 : * By default, none (empty string) is returned.
1855 : *
1856 : * This method is the same as the C function OGR_Fld_GetComment().
1857 : *
1858 : * @return the field comment, or an empty string if there is none.
1859 : * @since GDAL 3.7
1860 : */
1861 :
1862 : /************************************************************************/
1863 : /* OGR_Fld_GetComment() */
1864 : /************************************************************************/
1865 :
1866 : /**
1867 : * \brief Return the (optional) comment for this field.
1868 : *
1869 : * By default, none (empty string) is returned.
1870 : *
1871 : * This method is the same as the C++ method OGRFieldDefn::GetComment().
1872 : *
1873 : * @param hDefn handle to the field definition
1874 : * @return the comment, or an empty string if there is none.
1875 : * @since GDAL 3.7
1876 : */
1877 :
1878 58 : const char *OGR_Fld_GetComment(OGRFieldDefnH hDefn)
1879 : {
1880 58 : return OGRFieldDefn::FromHandle(hDefn)->GetComment().c_str();
1881 : }
1882 :
1883 : /************************************************************************/
1884 : /* SetComment() */
1885 : /************************************************************************/
1886 :
1887 : /**
1888 : * \brief Set the comment for this field.
1889 : *
1890 : * This method is the same as the C function OGR_Fld_SetComment().
1891 : *
1892 : * Note that once a OGRFieldDefn has been added to a layer definition with
1893 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
1894 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
1895 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
1896 : * OGRFieldDefn, for drivers that support AlterFieldDefn().
1897 : *
1898 : * @param osComment Field comment.
1899 : * @since GDAL 3.7
1900 : */
1901 2682 : void OGRFieldDefn::SetComment(const std::string &osComment)
1902 : {
1903 2682 : if (m_bSealed)
1904 : {
1905 1 : CPLError(CE_Failure, CPLE_AppDefined,
1906 : "OGRFieldDefn::SetComment() not allowed on a sealed object");
1907 1 : return;
1908 : }
1909 2681 : m_osComment = osComment;
1910 : }
1911 :
1912 : /************************************************************************/
1913 : /* OGR_Fld_SetComment() */
1914 : /************************************************************************/
1915 :
1916 : /**
1917 : * \brief Set the comment for this field.
1918 : *
1919 : * This method is the same as the C++ method OGRFieldDefn::SetComment().
1920 : *
1921 : * Note that once a OGRFieldDefn has been added to a layer definition with
1922 : * OGRLayer::AddFieldDefn(), its setter methods should not be called on the
1923 : * object returned with OGRLayer::GetLayerDefn()->GetFieldDefn(). Instead,
1924 : * OGRLayer::AlterFieldDefn() should be called on a new instance of
1925 : * OGRFieldDefn, for drivers that support AlterFieldDefn().
1926 : *
1927 : * @param hDefn handle to the field definition
1928 : * @param pszComment Field comment.
1929 : * @since GDAL 3.7
1930 : */
1931 :
1932 31 : void OGR_Fld_SetComment(OGRFieldDefnH hDefn, const char *pszComment)
1933 : {
1934 31 : OGRFieldDefn::FromHandle(hDefn)->SetComment(pszComment ? pszComment : "");
1935 31 : }
1936 :
1937 : /************************************************************************/
1938 : /* OGRUpdateFieldType() */
1939 : /************************************************************************/
1940 :
1941 : /**
1942 : * \brief Update the type of a field definition by "merging" its existing type
1943 : * with a new type.
1944 : *
1945 : * The update is done such as broadening the type. For example a OFTInteger
1946 : * updated with OFTInteger64 will be promoted to OFTInteger64.
1947 : *
1948 : * @param poFDefn the field definition whose type must be updated.
1949 : * @param eNewType the new field type to merge into the existing type.
1950 : * @param eNewSubType the new field subtype to merge into the existing subtype.
1951 : * @since GDAL 2.1
1952 : */
1953 :
1954 32 : void OGRUpdateFieldType(OGRFieldDefn *poFDefn, OGRFieldType eNewType,
1955 : OGRFieldSubType eNewSubType)
1956 : {
1957 32 : OGRFieldType eType = poFDefn->GetType();
1958 32 : if (eType == OFTInteger)
1959 : {
1960 2 : if (eNewType == OFTInteger && poFDefn->GetSubType() == OFSTBoolean &&
1961 : eNewSubType != OFSTBoolean)
1962 : {
1963 0 : poFDefn->SetSubType(OFSTNone);
1964 : }
1965 2 : else if (eNewType == OFTInteger64 || eNewType == OFTReal)
1966 : {
1967 0 : poFDefn->SetSubType(OFSTNone);
1968 0 : poFDefn->SetType(eNewType);
1969 : }
1970 2 : else if (eNewType == OFTIntegerList || eNewType == OFTInteger64List ||
1971 2 : eNewType == OFTRealList || eNewType == OFTStringList)
1972 : {
1973 0 : if (eNewType != OFTIntegerList || eNewSubType != OFSTBoolean)
1974 0 : poFDefn->SetSubType(OFSTNone);
1975 0 : poFDefn->SetType(eNewType);
1976 : }
1977 2 : else if (eNewType != OFTInteger)
1978 : {
1979 0 : poFDefn->SetSubType(OFSTNone);
1980 0 : poFDefn->SetType(OFTString);
1981 : }
1982 : }
1983 30 : else if (eType == OFTInteger64)
1984 : {
1985 1 : if (eNewType == OFTReal)
1986 : {
1987 0 : poFDefn->SetSubType(OFSTNone);
1988 0 : poFDefn->SetType(eNewType);
1989 : }
1990 1 : else if (eNewType == OFTIntegerList)
1991 : {
1992 0 : poFDefn->SetSubType(OFSTNone);
1993 0 : poFDefn->SetType(OFTInteger64List);
1994 : }
1995 1 : else if (eNewType == OFTInteger64List || eNewType == OFTRealList ||
1996 : eNewType == OFTStringList)
1997 : {
1998 0 : poFDefn->SetSubType(OFSTNone);
1999 0 : poFDefn->SetType(eNewType);
2000 : }
2001 1 : else if (eNewType != OFTInteger && eNewType != OFTInteger64)
2002 : {
2003 0 : poFDefn->SetSubType(OFSTNone);
2004 0 : poFDefn->SetType(OFTString);
2005 : }
2006 : }
2007 29 : else if (eType == OFTReal)
2008 : {
2009 2 : if (eNewType == OFTIntegerList || eNewType == OFTInteger64List ||
2010 : eNewType == OFTRealList)
2011 : {
2012 0 : poFDefn->SetType(OFTRealList);
2013 : }
2014 2 : else if (eNewType == OFTStringList)
2015 : {
2016 0 : poFDefn->SetType(OFTStringList);
2017 : }
2018 2 : else if (eNewType != OFTInteger && eNewType != OFTInteger64 &&
2019 : eNewType != OFTReal)
2020 : {
2021 0 : poFDefn->SetSubType(OFSTNone);
2022 0 : poFDefn->SetType(OFTString);
2023 : }
2024 : }
2025 27 : else if (eType == OFTIntegerList)
2026 : {
2027 1 : if (eNewType == OFTIntegerList &&
2028 2 : poFDefn->GetSubType() == OFSTBoolean && eNewSubType != OFSTBoolean)
2029 : {
2030 0 : poFDefn->SetSubType(OFSTNone);
2031 : }
2032 1 : else if (eNewType == OFTInteger64 || eNewType == OFTInteger64List)
2033 : {
2034 0 : poFDefn->SetSubType(OFSTNone);
2035 0 : poFDefn->SetType(OFTInteger64List);
2036 : }
2037 1 : else if (eNewType == OFTReal || eNewType == OFTRealList)
2038 : {
2039 0 : poFDefn->SetSubType(OFSTNone);
2040 0 : poFDefn->SetType(OFTRealList);
2041 : }
2042 1 : else if (eNewType != OFTInteger && eNewType != OFTIntegerList)
2043 : {
2044 0 : poFDefn->SetSubType(OFSTNone);
2045 0 : poFDefn->SetType(OFTStringList);
2046 : }
2047 : }
2048 26 : else if (eType == OFTInteger64List)
2049 : {
2050 1 : if (eNewType == OFTReal || eNewType == OFTRealList)
2051 0 : poFDefn->SetType(OFTRealList);
2052 1 : else if (eNewType != OFTInteger && eNewType != OFTInteger64 &&
2053 1 : eNewType != OFTIntegerList && eNewType != OFTInteger64List)
2054 : {
2055 0 : poFDefn->SetSubType(OFSTNone);
2056 0 : poFDefn->SetType(OFTStringList);
2057 : }
2058 : }
2059 25 : else if (eType == OFTRealList)
2060 : {
2061 1 : if (eNewType != OFTInteger && eNewType != OFTInteger64 &&
2062 1 : eNewType != OFTReal && eNewType != OFTIntegerList &&
2063 1 : eNewType != OFTInteger64List && eNewType != OFTRealList)
2064 : {
2065 0 : poFDefn->SetSubType(OFSTNone);
2066 0 : poFDefn->SetType(OFTStringList);
2067 : }
2068 : }
2069 24 : else if (eType == OFTDateTime)
2070 : {
2071 1 : if (eNewType != OFTDateTime && eNewType != OFTDate)
2072 : {
2073 0 : poFDefn->SetType(OFTString);
2074 : }
2075 : }
2076 23 : else if (eType == OFTDate || eType == OFTTime)
2077 : {
2078 2 : if (eNewType == OFTDateTime)
2079 0 : poFDefn->SetType(OFTDateTime);
2080 2 : else if (eNewType != eType)
2081 0 : poFDefn->SetType(OFTString);
2082 : }
2083 21 : else if (eType == OFTString && eNewType == OFTStringList)
2084 : {
2085 0 : poFDefn->SetType(OFTStringList);
2086 : }
2087 32 : }
2088 :
2089 : /************************************************************************/
2090 : /* OGRFieldDefn::Seal() */
2091 : /************************************************************************/
2092 :
2093 : /** Seal a OGRFieldDefn.
2094 : *
2095 : * A sealed OGRFieldDefn can not be modified while it is sealed.
2096 : *
2097 : * This method should only be called by driver implementations.
2098 : *
2099 : * @since GDAL 3.9
2100 : */
2101 2709940 : void OGRFieldDefn::Seal()
2102 : {
2103 2709940 : m_bSealed = true;
2104 2709940 : }
2105 :
2106 : /************************************************************************/
2107 : /* OGRFieldDefn::Unseal() */
2108 : /************************************************************************/
2109 :
2110 : /** Unseal a OGRFieldDefn.
2111 : *
2112 : * Undo OGRFieldDefn::Seal()
2113 : *
2114 : * Using GetTemporaryUnsealer() is recommended for most use cases.
2115 : *
2116 : * This method should only be called by driver implementations.
2117 : *
2118 : * @since GDAL 3.9
2119 : */
2120 2676050 : void OGRFieldDefn::Unseal()
2121 : {
2122 2676050 : m_bSealed = false;
2123 2676050 : }
2124 :
2125 : /************************************************************************/
2126 : /* OGRFieldDefn::GetTemporaryUnsealer() */
2127 : /************************************************************************/
2128 :
2129 : /** Return an object that temporary unseals the OGRFieldDefn
2130 : *
2131 : * The returned object calls Unseal() initially, and when it is destroyed
2132 : * it calls Seal().
2133 : *
2134 : * This method should only be called by driver implementations.
2135 : *
2136 : * It is also possible to use the helper method whileUnsealing(). Example:
2137 : * whileUnsealing(poFieldDefn)->some_method()
2138 : *
2139 : * @since GDAL 3.9
2140 : */
2141 149 : OGRFieldDefn::TemporaryUnsealer OGRFieldDefn::GetTemporaryUnsealer()
2142 : {
2143 149 : return TemporaryUnsealer(this);
2144 : }
2145 :
2146 : /************************************************************************/
2147 : /* OGRFieldDomain() */
2148 : /************************************************************************/
2149 :
2150 : /*! @cond Doxygen_Suppress */
2151 1280 : OGRFieldDomain::OGRFieldDomain(const std::string &osName,
2152 : const std::string &osDescription,
2153 : OGRFieldDomainType eDomainType,
2154 : OGRFieldType eFieldType,
2155 1280 : OGRFieldSubType eFieldSubType)
2156 : : m_osName(osName), m_osDescription(osDescription),
2157 : m_eDomainType(eDomainType), m_eFieldType(eFieldType),
2158 1280 : m_eFieldSubType(eFieldSubType)
2159 : {
2160 1280 : }
2161 :
2162 : /*! @endcond */
2163 :
2164 : /************************************************************************/
2165 : /* ~OGRFieldDomain() */
2166 : /************************************************************************/
2167 :
2168 : OGRFieldDomain::~OGRFieldDomain() = default;
2169 :
2170 : /************************************************************************/
2171 : /* ~OGRFieldDomain() */
2172 : /************************************************************************/
2173 :
2174 : /** Destroy a field domain.
2175 : *
2176 : * This is the same as the C++ method OGRFieldDomain::~OGRFieldDomain()
2177 : *
2178 : * @param hFieldDomain the field domain.
2179 : * @since GDAL 3.3
2180 : */
2181 44 : void OGR_FldDomain_Destroy(OGRFieldDomainH hFieldDomain)
2182 : {
2183 44 : delete OGRFieldDomain::FromHandle(hFieldDomain);
2184 44 : }
2185 :
2186 : /************************************************************************/
2187 : /* OGRCodedFieldDomain() */
2188 : /************************************************************************/
2189 :
2190 1185 : OGRCodedFieldDomain::OGRCodedFieldDomain(const std::string &osName,
2191 : const std::string &osDescription,
2192 : OGRFieldType eFieldType,
2193 : OGRFieldSubType eFieldSubType,
2194 1185 : std::vector<OGRCodedValue> &&asValues)
2195 : : OGRFieldDomain(osName, osDescription, OFDT_CODED, eFieldType,
2196 : eFieldSubType),
2197 1185 : m_asValues(std::move(asValues))
2198 : {
2199 : // Guard
2200 1185 : if (m_asValues.empty() || m_asValues.back().pszCode != nullptr)
2201 : {
2202 : OGRCodedValue cv;
2203 1125 : cv.pszCode = nullptr;
2204 1125 : cv.pszValue = nullptr;
2205 1125 : m_asValues.emplace_back(cv);
2206 : }
2207 1185 : }
2208 :
2209 : /************************************************************************/
2210 : /* OGR_CodedFldDomain_Create() */
2211 : /************************************************************************/
2212 :
2213 : /** Creates a new coded field domain.
2214 : *
2215 : * This is the same as the C++ method OGRCodedFieldDomain::OGRCodedFieldDomain()
2216 : * (except that the C function copies the enumeration, whereas the C++
2217 : * method moves it)
2218 : *
2219 : * @param pszName Domain name. Should not be NULL.
2220 : * @param pszDescription Domain description (can be NULL)
2221 : * @param eFieldType Field type. Generally numeric. Potentially OFTDateTime
2222 : * @param eFieldSubType Field subtype.
2223 : * @param enumeration Enumeration as (code, value) pairs. Should not be
2224 : * NULL. The end of the enumeration is marked by a code
2225 : * set to NULL. The enumeration will be copied.
2226 : * Each code should appear only once, but it is the
2227 : * responsibility of the user to check it.
2228 : * @return a new handle that should be freed with OGR_FldDomain_Destroy(),
2229 : * or NULL in case of error.
2230 : * @since GDAL 3.3
2231 : */
2232 59 : OGRFieldDomainH OGR_CodedFldDomain_Create(const char *pszName,
2233 : const char *pszDescription,
2234 : OGRFieldType eFieldType,
2235 : OGRFieldSubType eFieldSubType,
2236 : const OGRCodedValue *enumeration)
2237 : {
2238 59 : VALIDATE_POINTER1(pszName, __func__, nullptr);
2239 59 : VALIDATE_POINTER1(enumeration, __func__, nullptr);
2240 59 : size_t count = 0;
2241 199 : for (int i = 0; enumeration[i].pszCode != nullptr; ++i)
2242 : {
2243 140 : ++count;
2244 : }
2245 118 : std::vector<OGRCodedValue> asValues;
2246 : try
2247 : {
2248 59 : asValues.reserve(count + 1);
2249 : }
2250 0 : catch (const std::exception &e)
2251 : {
2252 0 : CPLError(CE_Failure, CPLE_OutOfMemory, "%s", e.what());
2253 0 : return nullptr;
2254 : }
2255 59 : bool error = false;
2256 199 : for (int i = 0; enumeration[i].pszCode != nullptr; ++i)
2257 : {
2258 : OGRCodedValue cv;
2259 140 : cv.pszCode = VSI_STRDUP_VERBOSE(enumeration[i].pszCode);
2260 140 : if (cv.pszCode == nullptr)
2261 : {
2262 0 : error = true;
2263 0 : break;
2264 : }
2265 140 : if (enumeration[i].pszValue)
2266 : {
2267 116 : cv.pszValue = VSI_STRDUP_VERBOSE(enumeration[i].pszValue);
2268 116 : if (cv.pszValue == nullptr)
2269 : {
2270 0 : VSIFree(cv.pszCode);
2271 0 : error = true;
2272 0 : break;
2273 : }
2274 : }
2275 : else
2276 : {
2277 24 : cv.pszValue = nullptr;
2278 : }
2279 140 : asValues.emplace_back(cv);
2280 : }
2281 59 : if (error)
2282 : {
2283 0 : for (auto &cv : asValues)
2284 : {
2285 0 : VSIFree(cv.pszCode);
2286 0 : VSIFree(cv.pszValue);
2287 : }
2288 0 : return nullptr;
2289 : }
2290 : // Add guard
2291 : {
2292 : OGRCodedValue cv;
2293 59 : cv.pszCode = nullptr;
2294 59 : cv.pszValue = nullptr;
2295 59 : asValues.emplace_back(cv);
2296 : }
2297 177 : return OGRFieldDomain::ToHandle(new OGRCodedFieldDomain(
2298 : pszName, pszDescription ? pszDescription : "", eFieldType,
2299 118 : eFieldSubType, std::move(asValues)));
2300 : }
2301 :
2302 : /************************************************************************/
2303 : /* OGRCodedFieldDomain::Clone() */
2304 : /************************************************************************/
2305 :
2306 38 : OGRCodedFieldDomain *OGRCodedFieldDomain::Clone() const
2307 : {
2308 76 : auto poDomain = cpl::down_cast<OGRCodedFieldDomain *>(
2309 : OGRFieldDomain::FromHandle(OGR_CodedFldDomain_Create(
2310 38 : m_osName.c_str(), m_osDescription.c_str(), m_eFieldType,
2311 38 : m_eFieldSubType, m_asValues.data())));
2312 38 : poDomain->SetMergePolicy(m_eMergePolicy);
2313 38 : poDomain->SetSplitPolicy(m_eSplitPolicy);
2314 38 : return poDomain;
2315 : }
2316 :
2317 : /************************************************************************/
2318 : /* ~OGRCodedFieldDomain() */
2319 : /************************************************************************/
2320 :
2321 2367 : OGRCodedFieldDomain::~OGRCodedFieldDomain()
2322 : {
2323 19650 : for (auto &cv : m_asValues)
2324 : {
2325 18466 : CPLFree(cv.pszCode);
2326 18466 : CPLFree(cv.pszValue);
2327 : }
2328 2367 : }
2329 :
2330 : /************************************************************************/
2331 : /* OGRRangeFieldDomain() */
2332 : /************************************************************************/
2333 :
2334 61 : OGRRangeFieldDomain::OGRRangeFieldDomain(
2335 : const std::string &osName, const std::string &osDescription,
2336 : OGRFieldType eFieldType, OGRFieldSubType eFieldSubType,
2337 : const OGRField &sMin, bool bMinIsInclusive, const OGRField &sMax,
2338 61 : bool bMaxIsInclusive)
2339 : : OGRFieldDomain(osName, osDescription, OFDT_RANGE, eFieldType,
2340 : eFieldSubType),
2341 : m_sMin(sMin), m_sMax(sMax), m_bMinIsInclusive(bMinIsInclusive),
2342 61 : m_bMaxIsInclusive(bMaxIsInclusive)
2343 : {
2344 61 : CPLAssert(eFieldType == OFTInteger || eFieldType == OFTInteger64 ||
2345 : eFieldType == OFTReal || eFieldType == OFTDateTime);
2346 61 : }
2347 :
2348 : /************************************************************************/
2349 : /* OGR_RangeFldDomain_Create() */
2350 : /************************************************************************/
2351 :
2352 12 : static OGRField GetUnsetField()
2353 : {
2354 : OGRField sUnset;
2355 12 : OGR_RawField_SetUnset(&sUnset);
2356 12 : return sUnset;
2357 : }
2358 :
2359 : /** Creates a new range field domain.
2360 : *
2361 : * This is the same as the C++ method
2362 : * OGRRangeFieldDomain::OGRRangeFieldDomain().
2363 : *
2364 : * @param pszName Domain name. Should not be NULL.
2365 : * @param pszDescription Domain description (can be NULL)
2366 : * @param eFieldType Field type. Among OFTInteger, OFTInteger64, OFTReal
2367 : * and OFTDateTime.
2368 : * @param eFieldSubType Field subtype.
2369 : * @param psMin Minimum value (can be NULL). The member in the union
2370 : * that is read is consistent with eFieldType
2371 : * @param bMinIsInclusive Whether the minimum value is included in the range.
2372 : * @param psMax Maximum value (can be NULL). The member in the union
2373 : * that is read is consistent with eFieldType
2374 : * @param bMaxIsInclusive Whether the maximum value is included in the range.
2375 : * @return a new handle that should be freed with OGR_FldDomain_Destroy()
2376 : * @since GDAL 3.3
2377 : */
2378 12 : OGRFieldDomainH OGR_RangeFldDomain_Create(
2379 : const char *pszName, const char *pszDescription, OGRFieldType eFieldType,
2380 : OGRFieldSubType eFieldSubType, const OGRField *psMin, bool bMinIsInclusive,
2381 : const OGRField *psMax, bool bMaxIsInclusive)
2382 : {
2383 12 : VALIDATE_POINTER1(pszName, __func__, nullptr);
2384 12 : if (eFieldType != OFTInteger && eFieldType != OFTInteger64 &&
2385 2 : eFieldType != OFTReal && eFieldType != OFTDateTime)
2386 : {
2387 0 : CPLError(CE_Failure, CPLE_NotSupported, "Unsupported field type");
2388 0 : return nullptr;
2389 : }
2390 12 : const OGRField unsetField = GetUnsetField();
2391 36 : return OGRFieldDomain::ToHandle(new OGRRangeFieldDomain(
2392 : pszName, pszDescription ? pszDescription : "", eFieldType,
2393 : eFieldSubType, psMin ? *psMin : unsetField, bMinIsInclusive,
2394 24 : psMax ? *psMax : unsetField, bMaxIsInclusive));
2395 : }
2396 :
2397 : /************************************************************************/
2398 : /* OGRGlobFieldDomain() */
2399 : /************************************************************************/
2400 :
2401 34 : OGRGlobFieldDomain::OGRGlobFieldDomain(const std::string &osName,
2402 : const std::string &osDescription,
2403 : OGRFieldType eFieldType,
2404 : OGRFieldSubType eFieldSubType,
2405 34 : const std::string &osGlob)
2406 : : OGRFieldDomain(osName, osDescription, OFDT_GLOB, eFieldType,
2407 : eFieldSubType),
2408 34 : m_osGlob(osGlob)
2409 : {
2410 34 : }
2411 :
2412 : /************************************************************************/
2413 : /* OGR_GlobFldDomain_Create() */
2414 : /************************************************************************/
2415 :
2416 : /** Creates a new glob field domain.
2417 : *
2418 : * This is the same as the C++ method OGRGlobFieldDomain::OGRGlobFieldDomain()
2419 : *
2420 : * @param pszName Domain name. Should not be NULL.
2421 : * @param pszDescription Domain description (can be NULL)
2422 : * @param eFieldType Field type.
2423 : * @param eFieldSubType Field subtype.
2424 : * @param pszGlob Glob expression. Should not be NULL.
2425 : * @return a new handle that should be freed with OGR_FldDomain_Destroy()
2426 : * @since GDAL 3.3
2427 : */
2428 14 : OGRFieldDomainH OGR_GlobFldDomain_Create(const char *pszName,
2429 : const char *pszDescription,
2430 : OGRFieldType eFieldType,
2431 : OGRFieldSubType eFieldSubType,
2432 : const char *pszGlob)
2433 : {
2434 14 : VALIDATE_POINTER1(pszName, __func__, nullptr);
2435 14 : VALIDATE_POINTER1(pszGlob, __func__, nullptr);
2436 42 : return OGRFieldDomain::ToHandle(
2437 : new OGRGlobFieldDomain(pszName, pszDescription ? pszDescription : "",
2438 28 : eFieldType, eFieldSubType, pszGlob));
2439 : }
2440 :
2441 : /************************************************************************/
2442 : /* OGR_FldDomain_GetName() */
2443 : /************************************************************************/
2444 :
2445 : /** Get the name of the field domain.
2446 : *
2447 : * This is the same as the C++ method OGRFieldDomain::GetName()
2448 : *
2449 : * @param hFieldDomain Field domain handle.
2450 : * @return the field domain name.
2451 : * @since GDAL 3.3
2452 : */
2453 57 : const char *OGR_FldDomain_GetName(OGRFieldDomainH hFieldDomain)
2454 : {
2455 57 : return OGRFieldDomain::FromHandle(hFieldDomain)->GetName().c_str();
2456 : }
2457 :
2458 : /************************************************************************/
2459 : /* OGR_FldDomain_GetDescription() */
2460 : /************************************************************************/
2461 :
2462 : /** Get the description of the field domain.
2463 : *
2464 : * This is the same as the C++ method OGRFieldDomain::GetDescription()
2465 : *
2466 : * @param hFieldDomain Field domain handle.
2467 : * @return the field domain description (might be empty string).
2468 : * @since GDAL 3.3
2469 : */
2470 61 : const char *OGR_FldDomain_GetDescription(OGRFieldDomainH hFieldDomain)
2471 : {
2472 61 : return OGRFieldDomain::FromHandle(hFieldDomain)->GetDescription().c_str();
2473 : }
2474 :
2475 : /************************************************************************/
2476 : /* OGR_FldDomain_GetDomainType() */
2477 : /************************************************************************/
2478 :
2479 : /** Get the type of the field domain.
2480 : *
2481 : * This is the same as the C++ method OGRFieldDomain::GetDomainType()
2482 : *
2483 : * @param hFieldDomain Field domain handle.
2484 : * @return the type of the field domain.
2485 : * @since GDAL 3.3
2486 : */
2487 54 : OGRFieldDomainType OGR_FldDomain_GetDomainType(OGRFieldDomainH hFieldDomain)
2488 : {
2489 54 : return OGRFieldDomain::FromHandle(hFieldDomain)->GetDomainType();
2490 : }
2491 :
2492 : /************************************************************************/
2493 : /* OGR_FldDomain_GetFieldType() */
2494 : /************************************************************************/
2495 :
2496 : /** Get the field type of the field domain.
2497 : *
2498 : * This is the same as the C++ method OGRFieldDomain::GetFieldType()
2499 : *
2500 : * @param hFieldDomain Field domain handle.
2501 : * @return the field type of the field domain.
2502 : * @since GDAL 3.3
2503 : */
2504 84 : OGRFieldType OGR_FldDomain_GetFieldType(OGRFieldDomainH hFieldDomain)
2505 : {
2506 84 : return OGRFieldDomain::FromHandle(hFieldDomain)->GetFieldType();
2507 : }
2508 :
2509 : /************************************************************************/
2510 : /* OGR_FldDomain_GetFieldSubType() */
2511 : /************************************************************************/
2512 :
2513 : /** Get the field subtype of the field domain.
2514 : *
2515 : * This is the same as OGRFieldDomain::GetFieldSubType()
2516 : *
2517 : * @param hFieldDomain Field domain handle.
2518 : * @return the field subtype of the field domain.
2519 : * @since GDAL 3.3
2520 : */
2521 40 : OGRFieldSubType OGR_FldDomain_GetFieldSubType(OGRFieldDomainH hFieldDomain)
2522 : {
2523 40 : return OGRFieldDomain::FromHandle(hFieldDomain)->GetFieldSubType();
2524 : }
2525 :
2526 : /************************************************************************/
2527 : /* OGR_FldDomain_GetSplitPolicy() */
2528 : /************************************************************************/
2529 :
2530 : /** Get the split policy of the field domain.
2531 : *
2532 : * This is the same as the C++ method OGRFieldDomain::GetSplitPolicy()
2533 : *
2534 : * @param hFieldDomain Field domain handle.
2535 : * @return the split policy of the field domain.
2536 : * @since GDAL 3.3
2537 : */
2538 :
2539 : OGRFieldDomainSplitPolicy
2540 2 : OGR_FldDomain_GetSplitPolicy(OGRFieldDomainH hFieldDomain)
2541 : {
2542 2 : return OGRFieldDomain::FromHandle(hFieldDomain)->GetSplitPolicy();
2543 : }
2544 :
2545 : /************************************************************************/
2546 : /* OGR_FldDomain_SetSplitPolicy() */
2547 : /************************************************************************/
2548 :
2549 : /** Set the split policy of the field domain.
2550 : *
2551 : * This is the same as the C++ method OGRFieldDomain::SetSplitPolicy()
2552 : *
2553 : * @param hFieldDomain Field domain handle.
2554 : * @param policy the split policy of the field domain.
2555 : * @since GDAL 3.3
2556 : */
2557 :
2558 1 : void OGR_FldDomain_SetSplitPolicy(OGRFieldDomainH hFieldDomain,
2559 : OGRFieldDomainSplitPolicy policy)
2560 : {
2561 1 : OGRFieldDomain::FromHandle(hFieldDomain)->SetSplitPolicy(policy);
2562 1 : }
2563 :
2564 : /************************************************************************/
2565 : /* OGR_FldDomain_GetMergePolicy() */
2566 : /************************************************************************/
2567 :
2568 : /** Get the merge policy of the field domain.
2569 : *
2570 : * This is the same as the C++ method OGRFieldDomain::GetMergePolicy()
2571 : *
2572 : * @param hFieldDomain Field domain handle.
2573 : * @return the merge policy of the field domain.
2574 : * @since GDAL 3.3
2575 : */
2576 :
2577 : OGRFieldDomainMergePolicy
2578 2 : OGR_FldDomain_GetMergePolicy(OGRFieldDomainH hFieldDomain)
2579 : {
2580 2 : return OGRFieldDomain::FromHandle(hFieldDomain)->GetMergePolicy();
2581 : }
2582 :
2583 : /************************************************************************/
2584 : /* OGR_FldDomain_SetMergePolicy() */
2585 : /************************************************************************/
2586 :
2587 : /** Set the merge policy of the field domain.
2588 : *
2589 : * This is the same as the C++ method OGRFieldDomain::SetMergePolicy()
2590 : *
2591 : * @param hFieldDomain Field domain handle.
2592 : * @param policy the merge policy of the field domain.
2593 : * @since GDAL 3.3
2594 : */
2595 :
2596 1 : void OGR_FldDomain_SetMergePolicy(OGRFieldDomainH hFieldDomain,
2597 : OGRFieldDomainMergePolicy policy)
2598 : {
2599 1 : OGRFieldDomain::FromHandle(hFieldDomain)->SetMergePolicy(policy);
2600 1 : }
2601 :
2602 : /************************************************************************/
2603 : /* OGR_CodedFldDomain_GetEnumeration() */
2604 : /************************************************************************/
2605 :
2606 : /** Get the enumeration as (code, value) pairs.
2607 : *
2608 : * The end of the enumeration is signaled by code == NULL
2609 : *
2610 : * This is the same as the C++ method OGRCodedFieldDomain::GetEnumeration()
2611 : *
2612 : * @param hFieldDomain Field domain handle.
2613 : * @return the (code, value) pairs, or nullptr in case of error.
2614 : * @since GDAL 3.3
2615 : */
2616 : const OGRCodedValue *
2617 39 : OGR_CodedFldDomain_GetEnumeration(OGRFieldDomainH hFieldDomain)
2618 : {
2619 : // The user should normally only call us with the right object type, but
2620 : // it doesn't hurt to check.
2621 39 : auto poFieldDomain = dynamic_cast<const OGRCodedFieldDomain *>(
2622 78 : OGRFieldDomain::FromHandle(hFieldDomain));
2623 39 : if (!poFieldDomain)
2624 : {
2625 1 : CPLError(
2626 : CE_Failure, CPLE_AppDefined,
2627 : "This function should be called with a coded field domain object");
2628 1 : return nullptr;
2629 : }
2630 38 : return poFieldDomain->GetEnumeration();
2631 : }
2632 :
2633 : /************************************************************************/
2634 : /* OGR_RangeFldDomain_GetMin() */
2635 : /************************************************************************/
2636 :
2637 : /** Get the minimum value.
2638 : *
2639 : * Which member in the returned OGRField enum must be read depends on the field
2640 : * type.
2641 : *
2642 : * If no minimum value is set, the OGR_RawField_IsUnset() will return true when
2643 : * called on the result.
2644 : *
2645 : * This is the same as the C++ method OGRRangeFieldDomain::GetMin()
2646 : *
2647 : * @param hFieldDomain Field domain handle.
2648 : * @param pbIsInclusiveOut set to true if the minimum is included in the range.
2649 : * @return the minimum value.
2650 : * @since GDAL 3.3
2651 : */
2652 21 : const OGRField *OGR_RangeFldDomain_GetMin(OGRFieldDomainH hFieldDomain,
2653 : bool *pbIsInclusiveOut)
2654 : {
2655 : // The user should normally only call us with the right object type, but
2656 : // it doesn't hurt to check.
2657 21 : auto poFieldDomain = dynamic_cast<const OGRRangeFieldDomain *>(
2658 42 : OGRFieldDomain::FromHandle(hFieldDomain));
2659 21 : if (!poFieldDomain)
2660 : {
2661 0 : CPLError(
2662 : CE_Failure, CPLE_AppDefined,
2663 : "This function should be called with a range field domain object");
2664 0 : static const OGRField dummyField = GetUnsetField();
2665 0 : return &dummyField;
2666 : }
2667 21 : bool bIsInclusive = false;
2668 21 : const auto &ret = poFieldDomain->GetMin(bIsInclusive);
2669 21 : if (pbIsInclusiveOut)
2670 7 : *pbIsInclusiveOut = bIsInclusive;
2671 21 : return &ret;
2672 : }
2673 :
2674 : /************************************************************************/
2675 : /* OGR_RangeFldDomain_GetMax() */
2676 : /************************************************************************/
2677 :
2678 : /** Get the maximum value.
2679 : *
2680 : * Which member in the returned OGRField enum must be read depends on the field
2681 : * type.
2682 : *
2683 : * If no maximum value is set, the OGR_RawField_IsUnset() will return true when
2684 : * called on the result.
2685 : *
2686 : * This is the same as the C++ method OGRRangeFieldDomain::GetMax()
2687 : *
2688 : * @param hFieldDomain Field domain handle.
2689 : * @param pbIsInclusiveOut set to true if the maximum is included in the range.
2690 : * @return the maximum value.
2691 : * @since GDAL 3.3
2692 : */
2693 21 : const OGRField *OGR_RangeFldDomain_GetMax(OGRFieldDomainH hFieldDomain,
2694 : bool *pbIsInclusiveOut)
2695 : {
2696 : // The user should normally only call us with the right object type, but
2697 : // it doesn't hurt to check.
2698 21 : auto poFieldDomain = dynamic_cast<const OGRRangeFieldDomain *>(
2699 42 : OGRFieldDomain::FromHandle(hFieldDomain));
2700 21 : if (!poFieldDomain)
2701 : {
2702 0 : CPLError(
2703 : CE_Failure, CPLE_AppDefined,
2704 : "This function should be called with a range field domain object");
2705 0 : static const OGRField dummyField = GetUnsetField();
2706 0 : return &dummyField;
2707 : }
2708 21 : bool bIsInclusive = false;
2709 21 : const auto &ret = poFieldDomain->GetMax(bIsInclusive);
2710 21 : if (pbIsInclusiveOut)
2711 7 : *pbIsInclusiveOut = bIsInclusive;
2712 21 : return &ret;
2713 : }
2714 :
2715 : /************************************************************************/
2716 : /* OGR_GlobFldDomain_GetGlob() */
2717 : /************************************************************************/
2718 :
2719 : /** Get the glob expression.
2720 : *
2721 : * This is the same as the C++ method OGRGlobFieldDomain::GetGlob()
2722 : *
2723 : * @param hFieldDomain Field domain handle.
2724 : * @return the glob expression, or nullptr in case of error
2725 : * @since GDAL 3.3
2726 : */
2727 9 : const char *OGR_GlobFldDomain_GetGlob(OGRFieldDomainH hFieldDomain)
2728 : {
2729 : // The user should normally only call us with the right object type, but
2730 : // it doesn't hurt to check.
2731 9 : auto poFieldDomain = dynamic_cast<const OGRGlobFieldDomain *>(
2732 18 : OGRFieldDomain::FromHandle(hFieldDomain));
2733 9 : if (!poFieldDomain)
2734 : {
2735 1 : CPLError(
2736 : CE_Failure, CPLE_AppDefined,
2737 : "This function should be called with a glob field domain object");
2738 1 : return nullptr;
2739 : }
2740 8 : return poFieldDomain->GetGlob().c_str();
2741 : }
|