forked from OSGeo/gdal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdalmajorobject.cpp
450 lines (366 loc) · 14.7 KB
/
gdalmajorobject.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
/******************************************************************************
*
* Project: GDAL Core
* Purpose: Base class for objects with metadata, etc.
* Author: Frank Warmerdam, [email protected]
*
******************************************************************************
* Copyright (c) 2000, Frank Warmerdam
* Copyright (c) 2009-2013, Even Rouault <even dot rouault at spatialys.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
****************************************************************************/
#include "cpl_port.h"
#include "gdal_priv.h"
#include <cstdarg>
#include <cstddef>
#include "cpl_error.h"
#include "cpl_string.h"
#include "gdal.h"
CPL_CVSID("$Id$")
/************************************************************************/
/* GDALMajorObject() */
/************************************************************************/
GDALMajorObject::GDALMajorObject() :
nFlags(GMO_VALID)
{}
/************************************************************************/
/* ~GDALMajorObject() */
/************************************************************************/
GDALMajorObject::~GDALMajorObject()
{
if( (nFlags & GMO_VALID) == 0 )
CPLDebug( "GDAL", "In ~GDALMajorObject on invalid object" );
nFlags &= ~GMO_VALID;
}
/************************************************************************/
/* GetDescription() */
/************************************************************************/
/**
* \brief Fetch object description.
*
* The semantics of the returned description are specific to the derived
* type. For GDALDatasets it is the dataset name. For GDALRasterBands
* it is actually a description (if supported) or "".
*
* This method is the same as the C function GDALGetDescription().
*
* @return non-null pointer to internal description string.
*/
const char *GDALMajorObject::GetDescription() const
{
return sDescription.c_str();
}
/************************************************************************/
/* GDALGetDescription() */
/************************************************************************/
/**
* \brief Fetch object description.
*
* @see GDALMajorObject::GetDescription()
*/
const char * CPL_STDCALL GDALGetDescription( GDALMajorObjectH hObject )
{
VALIDATE_POINTER1( hObject, "GDALGetDescription", nullptr );
return GDALMajorObject::FromHandle(hObject)->GetDescription();
}
/************************************************************************/
/* SetDescription() */
/************************************************************************/
/**
* \brief Set object description.
*
* The semantics of the description are specific to the derived
* type. For GDALDatasets it is the dataset name. For GDALRasterBands
* it is actually a description (if supported) or "".
*
* Normally application code should not set the "description" for
* GDALDatasets. It is handled internally.
*
* This method is the same as the C function GDALSetDescription().
*/
void GDALMajorObject::SetDescription( const char * pszNewDesc )
{
sDescription = pszNewDesc;
}
/************************************************************************/
/* GDALSetDescription() */
/************************************************************************/
/**
* \brief Set object description.
*
* @see GDALMajorObject::SetDescription()
*/
void CPL_STDCALL GDALSetDescription( GDALMajorObjectH hObject,
const char *pszNewDesc )
{
VALIDATE_POINTER0( hObject, "GDALSetDescription" );
GDALMajorObject::FromHandle(hObject)->SetDescription( pszNewDesc );
}
/************************************************************************/
/* GetMetadataDomainList() */
/************************************************************************/
/**
* \brief Fetch list of metadata domains.
*
* The returned string list is the list of (non-empty) metadata domains.
*
* This method does the same thing as the C function GDALGetMetadataDomainList().
*
* @return NULL or a string list. Must be freed with CSLDestroy()
*
* @since GDAL 1.11
*/
char **GDALMajorObject::GetMetadataDomainList()
{
return CSLDuplicate(oMDMD.GetDomainList());
}
/************************************************************************/
/* BuildMetadataDomainList() */
/************************************************************************/
/**
* \brief Helper function for custom implementations of GetMetadataDomainList()
*
*
* @param papszList initial list of domains. May be NULL. Will become invalid
* after function call (use return value)
* @param bCheckNonEmpty if TRUE, each candidate domain will be tested to be non
* empty
* @param ... NULL terminated variadic list of candidate domains.
*
* @return NULL or a string list. Must be freed with CSLDestroy()
*
* @since GDAL 1.11
*/
char **GDALMajorObject::BuildMetadataDomainList( char** papszList,
int bCheckNonEmpty, ... )
{
va_list args;
const char* pszDomain = nullptr;
va_start(args, bCheckNonEmpty);
while( (pszDomain = va_arg(args, const char*)) != nullptr )
{
if( CSLFindString(papszList, pszDomain) < 0 &&
(!bCheckNonEmpty || GetMetadata(pszDomain) != nullptr) )
{
papszList = CSLAddString(papszList, pszDomain);
}
}
va_end(args);
return papszList;
}
/************************************************************************/
/* GDALGetMetadataDomainList() */
/************************************************************************/
/**
* \brief Fetch list of metadata domains.
*
* @see GDALMajorObject::GetMetadataDomainList()
*
* @since GDAL 1.11
*/
char ** CPL_STDCALL
GDALGetMetadataDomainList( GDALMajorObjectH hObject )
{
VALIDATE_POINTER1( hObject, "GetMetadataDomainList", nullptr );
return GDALMajorObject::FromHandle(hObject)->GetMetadataDomainList();
}
/************************************************************************/
/* GetMetadata() */
/************************************************************************/
/**
* \brief Fetch metadata.
*
* The returned string list is owned by the object, and may change at
* any time. It is formatted as a "Name=value" list with the last pointer
* value being NULL. Use the CPL StringList functions such as
* CSLFetchNameValue() to manipulate it.
*
* Note that relatively few formats return any metadata at this time.
*
* This method does the same thing as the C function GDALGetMetadata().
*
* @param pszDomain the domain of interest. Use "" or NULL for the default
* domain.
*
* @return NULL or a string list.
*/
char **GDALMajorObject::GetMetadata( const char * pszDomain )
{
return oMDMD.GetMetadata( pszDomain );
}
/************************************************************************/
/* GDALGetMetadata() */
/************************************************************************/
/**
* \brief Fetch metadata.
*
* @see GDALMajorObject::GetMetadata()
*/
char ** CPL_STDCALL
GDALGetMetadata( GDALMajorObjectH hObject, const char * pszDomain )
{
VALIDATE_POINTER1( hObject, "GDALGetMetadata", nullptr );
return GDALMajorObject::FromHandle(hObject)->GetMetadata(pszDomain);
}
/************************************************************************/
/* SetMetadata() */
/************************************************************************/
/**
* \brief Set metadata.
*
* The C function GDALSetMetadata() does the same thing as this method.
*
* @param papszMetadataIn the metadata in name=value string list format to
* apply.
* @param pszDomain the domain of interest. Use "" or NULL for the default
* domain.
* @return CE_None on success, CE_Failure on failure and CE_Warning if the
* metadata has been accepted, but is likely not maintained persistently
* by the underlying object between sessions.
*/
CPLErr GDALMajorObject::SetMetadata( char ** papszMetadataIn,
const char * pszDomain )
{
nFlags |= GMO_MD_DIRTY;
return oMDMD.SetMetadata( papszMetadataIn, pszDomain );
}
/************************************************************************/
/* GDALSetMetadata() */
/************************************************************************/
/**
* \brief Set metadata.
*
* CAUTION: when using this function on a GDALDatasetH or GDALRasterBandH,
* depending on the format, older values of the updated information might
* still be found in the file in a "ghost" state, even if no longer accessible
* through the GDAL API. This is for example the case of the GTiff format (this is
* not a exhaustive list)
*
* @see GDALMajorObject::SetMetadata(), GDALDataset::SetMetadata(),
* GDALRasterBand::SetMetadata()
*/
CPLErr CPL_STDCALL
GDALSetMetadata( GDALMajorObjectH hObject, CSLConstList papszMD,
const char *pszDomain )
{
VALIDATE_POINTER1( hObject, "GDALSetMetadata", CE_Failure );
return GDALMajorObject::FromHandle(hObject)->
SetMetadata( const_cast<char**>(papszMD), pszDomain );
}
/************************************************************************/
/* GetMetadataItem() */
/************************************************************************/
/**
* \brief Fetch single metadata item.
*
* The C function GDALGetMetadataItem() does the same thing as this method.
*
* @param pszName the key for the metadata item to fetch.
* @param pszDomain the domain to fetch for, use NULL for the default domain.
*
* @return NULL on failure to find the key, or a pointer to an internal
* copy of the value string on success.
*/
const char *GDALMajorObject::GetMetadataItem( const char * pszName,
const char * pszDomain )
{
return oMDMD.GetMetadataItem( pszName, pszDomain );
}
/************************************************************************/
/* GDALGetMetadataItem() */
/************************************************************************/
/**
* \brief Fetch single metadata item.
*
* @see GDALMajorObject::GetMetadataItem()
*/
const char * CPL_STDCALL GDALGetMetadataItem( GDALMajorObjectH hObject,
const char *pszName,
const char *pszDomain )
{
VALIDATE_POINTER1( hObject, "GDALGetMetadataItem", nullptr );
return GDALMajorObject::FromHandle(hObject)->
GetMetadataItem( pszName, pszDomain);
}
/************************************************************************/
/* SetMetadataItem() */
/************************************************************************/
/**
* \brief Set single metadata item.
*
* The C function GDALSetMetadataItem() does the same thing as this method.
*
* @param pszName the key for the metadata item to fetch.
* @param pszValue the value to assign to the key.
* @param pszDomain the domain to set within, use NULL for the default domain.
*
* @return CE_None on success, or an error code on failure.
*/
CPLErr GDALMajorObject::SetMetadataItem( const char * pszName,
const char * pszValue,
const char * pszDomain )
{
nFlags |= GMO_MD_DIRTY;
return oMDMD.SetMetadataItem( pszName, pszValue, pszDomain );
}
/************************************************************************/
/* GDALSetMetadataItem() */
/************************************************************************/
/**
* \brief Set single metadata item.
*
* CAUTION: when using this function on a GDALDatasetH or GDALRasterBandH,
* depending on the format, older values of the updated information might
* still be found in the file in a "ghost" state, even if no longer accessible
* through the GDAL API. This is for example the case of the GTiff format (this is
* not a exhaustive list)
*
* @see GDALMajorObject::SetMetadataItem(), GDALDataset::SetMetadataItem(),
* GDALRasterBand::SetMetadataItem()
*/
CPLErr CPL_STDCALL
GDALSetMetadataItem( GDALMajorObjectH hObject,
const char *pszName, const char *pszValue,
const char *pszDomain )
{
VALIDATE_POINTER1( hObject, "GDALSetMetadataItem", CE_Failure );
return GDALMajorObject::FromHandle(hObject)->
SetMetadataItem( pszName, pszValue, pszDomain );
}
/************************************************************************/
/* GetMOFlags() */
/************************************************************************/
/** Returns the GMO_ flags.
* @return flags
*/
int GDALMajorObject::GetMOFlags() const
{
return nFlags;
}
/************************************************************************/
/* SetMOFlags() */
/************************************************************************/
/** Assign GMO_flags.
* @param nNewFlags new flags.
*/
void GDALMajorObject::SetMOFlags( int nNewFlags )
{
nFlags = nNewFlags;
}