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