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