root/tags/gdal_1_3_2/gcore/gdalmajorobject.cpp

Revision 8608, 11.5 kB (checked in by fwarmerdam, 3 years ago)

moved GDALMultiDomainMetadata into GDALMajorObject

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /******************************************************************************
2  * $Id$
3  *
4  * Project:  GDAL Core
5  * Purpose:  Base class for objects with metadata, etc.
6  * Author:   Frank Warmerdam, warmerdam@pobox.com
7  *
8  ******************************************************************************
9  * Copyright (c) 2000, Frank Warmerdam
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  ******************************************************************************
29  *
30  * $Log$
31  * Revision 1.11  2005/10/13 01:19:57  fwarmerdam
32  * moved GDALMultiDomainMetadata into GDALMajorObject
33  *
34  * Revision 1.10  2005/09/23 20:52:21  fwarmerdam
35  * added the GMO flags on GDALMajorObject
36  *
37  * Revision 1.9  2005/07/25 19:52:43  ssoule
38  * Changed GDALMajorObject's char *pszDescription to std::string sDescription.
39  *
40  * Revision 1.8  2005/04/04 15:24:48  fwarmerdam
41  * Most C entry points now CPL_STDCALL
42  *
43  * Revision 1.7  2003/07/26 01:36:28  warmerda
44  * Implement support for forwarding non-default domains to the SetMetadata()
45  * method in SetMetadataItem().
46  *
47  * Revision 1.6  2003/04/30 17:13:48  warmerda
48  * added docs for many C functions
49  *
50  * Revision 1.5  2002/09/11 14:17:38  warmerda
51  * added C GDALSetDescription()
52  *
53  * Revision 1.4  2001/09/25 15:56:37  warmerda
54  * implemented rest of C entry points for metadata, document C++ methods
55  *
56  * Revision 1.3  2001/07/18 04:04:30  warmerda
57  * added CPL_CVSID
58  *
59  * Revision 1.2  2000/06/26 15:26:21  warmerda
60  * added GDALGetDescription
61  *
62  * Revision 1.1  2000/04/20 20:52:03  warmerda
63  * New
64  *
65  */
66
67 #include "gdal_priv.h"
68 #include "cpl_string.h"
69
70 CPL_CVSID("$Id$");
71
72 /************************************************************************/
73 /*                          GDALMajorObject()                           */
74 /************************************************************************/
75
76 GDALMajorObject::GDALMajorObject()
77
78 {
79     nFlags = GMO_VALID;
80 }
81
82 /************************************************************************/
83 /*                          ~GDALMajorObject()                          */
84 /************************************************************************/
85
86 GDALMajorObject::~GDALMajorObject()
87
88 {
89     if( (nFlags & GMO_VALID) == 0 )
90         CPLDebug( "GDAL", "In ~GDALMajorObject on invalid object" );
91
92     nFlags &= ~GMO_VALID;
93 }
94
95 /************************************************************************/
96 /*                           GetDescription()                           */
97 /************************************************************************/
98
99 /**
100  * Fetch object description.
101  *
102  * The semantics of the returned description are specific to the derived
103  * type.  For GDALDatasets it is the dataset name.  For GDALRasterBands
104  * it is actually a description (if supported) or "".
105  *
106  * This method is the same as the C function GDALGetDescription().
107  *
108  * @return pointer to internal description string.
109  */
110
111 const char *GDALMajorObject::GetDescription() const
112
113 {
114     return sDescription.c_str();
115 }
116
117 /************************************************************************/
118 /*                         GDALGetDescription()                         */
119 /************************************************************************/
120
121 /**
122  * @see GDALMajorObject::GetDescription()
123  */
124
125 const char * CPL_STDCALL GDALGetDescription( GDALMajorObjectH hObject )
126
127 {
128     return ((GDALMajorObject *) hObject)->GetDescription();
129 }
130
131 /************************************************************************/
132 /*                           SetDescription()                           */
133 /************************************************************************/
134
135 /**
136  * Set object description.
137  *
138  * The semantics of the description are specific to the derived
139  * type.  For GDALDatasets it is the dataset name.  For GDALRasterBands
140  * it is actually a description (if supported) or "".
141  *
142  * Normally application code should not set the "description" for
143  * GDALDatasets.  It is handled internally. 
144  *
145  * This method is the same as the C function GDALSetDescription().
146  */
147
148 void GDALMajorObject::SetDescription( const char * pszNewDesc )
149
150 {
151     sDescription = pszNewDesc;
152 }
153
154 /************************************************************************/
155 /*                         GDALSetDescription()                         */
156 /************************************************************************/
157
158 /**
159  * @see GDALMajorObject::SetDescription()
160  */
161
162 void CPL_STDCALL GDALSetDescription( GDALMajorObjectH hObject, const char *pszNewDesc )
163
164 {
165     ((GDALMajorObject *) hObject)->SetDescription( pszNewDesc );
166 }
167
168 /************************************************************************/
169 /*                            GetMetadata()                             */
170 /************************************************************************/
171
172 /**
173  * Fetch metadata.
174  *
175  * The returned string list is owned by the object, and may change at
176  * any time.  It is formated as a "Name=value" list with the last pointer
177  * value being NULL.  Use the the CPL StringList functions such as
178  * CSLFetchNameValue() to manipulate it.
179  *
180  * Note that relatively few formats return any metadata at this time.
181  *
182  * This method does the same thing as the C function GDALGetMetadata().
183  *
184  * @param pszDomain the domain of interest.  Use "" or NULL for the default
185  * domain.
186  *
187  * @return NULL or a string list.
188  */
189
190 char **GDALMajorObject::GetMetadata( const char * pszDomain )
191
192 {
193     return oMDMD.GetMetadata( pszDomain );
194 }
195
196 /************************************************************************/
197 /*                          GDALGetMetadata()                           */
198 /************************************************************************/
199
200 /**
201  * @see GDALMajorObject::GetMetadata()
202  */
203
204 char ** CPL_STDCALL
205 GDALGetMetadata( GDALMajorObjectH hObject, const char * pszDomain )
206
207 {
208     return ((GDALMajorObject *) hObject)->GetMetadata(pszDomain);
209 }
210
211 /************************************************************************/
212 /*                            SetMetadata()                             */
213 /************************************************************************/
214
215 /**
216  * Set metadata.
217  *
218  * The C function GDALSetMetadata() does the same thing as this method.
219  *
220  * @param papszMetadata the metadata in name=value string list format to
221  * apply. 
222  * @param pszDomain the domain of interest.  Use "" or NULL for the default
223  * domain.
224  * @return CE_None on success, CE_Failure on failure and CE_Warning if the
225  * metadata has been accepted, but is likely not maintained persistently
226  * by the underlying object between sessions.
227  */
228
229 CPLErr GDALMajorObject::SetMetadata( char ** papszMetadataIn,
230                                      const char * pszDomain )
231
232 {
233     nFlags |= GMO_MD_DIRTY;
234     return oMDMD.SetMetadata( papszMetadataIn, pszDomain );
235 }
236
237 /************************************************************************/
238 /*                          GDALSetMetadata()                           */
239 /************************************************************************/
240
241 /**
242  * @see GDALMajorObject::SetMetadata()
243  */
244
245 CPLErr CPL_STDCALL
246 GDALSetMetadata( GDALMajorObjectH hObject, char **papszMD,
247                  const char *pszDomain )
248
249 {
250     return ((GDALMajorObject *) hObject)->SetMetadata( papszMD, pszDomain );
251 }
252
253
254 /************************************************************************/
255 /*                          GetMetadataItem()                           */
256 /************************************************************************/
257
258 /**
259  * Fetch single metadata item.
260  *
261  * The C function GDALGetMetadataItem() does the same thing as this method.
262  *
263  * @param pszName the key for the metadata item to fetch.
264  * @param pszDomain the domain to fetch for, use NULL for the default domain.
265  *
266  * @return NULL on failure to find the key, or a pointer to an internal
267  * copy of the value string on success.
268  */
269
270 const char *GDALMajorObject::GetMetadataItem( const char * pszName,
271                                               const char * pszDomain )
272
273 {
274     return oMDMD.GetMetadataItem( pszName, pszDomain );
275 }
276
277 /************************************************************************/
278 /*                        GDALGetMetadataItem()                         */
279 /************************************************************************/
280
281 /**
282  * @see GDALMajorObject::GetMetadataItem()
283  */
284
285 const char * CPL_STDCALL GDALGetMetadataItem( GDALMajorObjectH hObject,
286                                  const char *pszName,
287                                  const char *pszDomain )
288
289 {
290     return ((GDALMajorObject *) hObject)->GetMetadataItem( pszName, pszDomain);
291 }
292
293 /************************************************************************/
294 /*                          SetMetadataItem()                           */
295 /************************************************************************/
296
297 /**
298  * Set single metadata item.
299  *
300  * The C function GDALSetMetadataItem() does the same thing as this method.
301  *
302  * @param pszName the key for the metadata item to fetch.
303  * @param pszValue the value to assign to the key.
304  * @param pszDomain the domain to set within, use NULL for the default domain.
305  *
306  * @return CE_None on success, or an error code on failure.
307  */
308
309 CPLErr GDALMajorObject::SetMetadataItem( const char * pszName,
310                                          const char * pszValue,
311                                          const char * pszDomain )
312
313 {
314     nFlags |= GMO_MD_DIRTY;
315     return oMDMD.SetMetadataItem( pszName, pszValue,  pszDomain );
316 }
317
318 /************************************************************************/
319 /*                        GDALSetMetadataItem()                         */
320 /************************************************************************/
321
322 /**
323  * @see GDALMajorObject::SetMetadataItem()
324  */
325
326 CPLErr CPL_STDCALL
327 GDALSetMetadataItem( GDALMajorObjectH hObject,
328                      const char *pszName, const char *pszValue,
329                      const char *pszDomain )
330
331 {
332     return ((GDALMajorObject *) hObject)->SetMetadataItem( pszName, pszValue,
333                                                            pszDomain );
334 }
335
336 /************************************************************************/
337 /*                             GetMOFlags()                             */
338 /************************************************************************/
339
340 int GDALMajorObject::GetMOFlags()
341
342 {
343     return nFlags;
344 }
345
346 /************************************************************************/
347 /*                             SetMOFlags()                             */
348 /************************************************************************/
349
350 void GDALMajorObject::SetMOFlags( int nNewFlags )
351
352 {
353     nFlags = nNewFlags;
354 }
355
Note: See TracBrowser for help on using the browser.