00001 /****************************************************************************** 00002 * $Id: gdalmajorobject_cpp-source.html,v 1.13 2002/12/21 19:13:13 warmerda Exp $ 00003 * 00004 * Project: GDAL Core 00005 * Purpose: Base class for objects with metadata, etc. 00006 * Author: Frank Warmerdam, warmerda@home.com 00007 * 00008 ****************************************************************************** 00009 * Copyright (c) 2000, Frank Warmerdam 00010 * 00011 * Permission is hereby granted, free of charge, to any person obtaining a 00012 * copy of this software and associated documentation files (the "Software"), 00013 * to deal in the Software without restriction, including without limitation 00014 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00015 * and/or sell copies of the Software, and to permit persons to whom the 00016 * Software is furnished to do so, subject to the following conditions: 00017 * 00018 * The above copyright notice and this permission notice shall be included 00019 * in all copies or substantial portions of the Software. 00020 * 00021 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00022 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00023 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00024 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00025 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00026 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 00027 * DEALINGS IN THE SOFTWARE. 00028 ****************************************************************************** 00029 * 00030 * $Log: gdalmajorobject_cpp-source.html,v $ 00030 * Revision 1.13 2002/12/21 19:13:13 warmerda 00030 * updated 00030 * 00031 * Revision 1.5 2002/09/11 14:17:38 warmerda 00032 * added C GDALSetDescription() 00033 * 00034 * Revision 1.4 2001/09/25 15:56:37 warmerda 00035 * implemented rest of C entry points for metadata, document C++ methods 00036 * 00037 * Revision 1.3 2001/07/18 04:04:30 warmerda 00038 * added CPL_CVSID 00039 * 00040 * Revision 1.2 2000/06/26 15:26:21 warmerda 00041 * added GDALGetDescription 00042 * 00043 * Revision 1.1 2000/04/20 20:52:03 warmerda 00044 * New 00045 * 00046 */ 00047 00048 #include "gdal_priv.h" 00049 #include "cpl_string.h" 00050 00051 CPL_CVSID("$Id: gdalmajorobject_cpp-source.html,v 1.13 2002/12/21 19:13:13 warmerda Exp $"); 00052 00053 /************************************************************************/ 00054 /* GDALMajorObject() */ 00055 /************************************************************************/ 00056 00057 GDALMajorObject::GDALMajorObject() 00058 00059 { 00060 pszDescription = NULL; 00061 papszMetadata = NULL; 00062 } 00063 00064 /************************************************************************/ 00065 /* ~GDALMajorObject() */ 00066 /************************************************************************/ 00067 00068 GDALMajorObject::~GDALMajorObject() 00069 00070 { 00071 CPLFree( pszDescription ); 00072 CSLDestroy( papszMetadata ); 00073 } 00074 00075 /************************************************************************/ 00076 /* GetDescription() */ 00077 /************************************************************************/ 00078 00091 const char *GDALMajorObject::GetDescription() const 00092 00093 { 00094 if( pszDescription == NULL ) 00095 return ""; 00096 else 00097 return pszDescription; 00098 } 00099 00100 /************************************************************************/ 00101 /* GDALGetDescription() */ 00102 /************************************************************************/ 00103 00104 const char *GDALGetDescription( GDALMajorObjectH hObject ) 00105 00106 { 00107 return ((GDALMajorObject *) hObject)->GetDescription(); 00108 } 00109 00110 /************************************************************************/ 00111 /* SetDescription() */ 00112 /************************************************************************/ 00113 00127 void GDALMajorObject::SetDescription( const char * pszNewDesc ) 00128 00129 { 00130 CPLFree( pszDescription ); 00131 pszDescription = CPLStrdup( pszNewDesc ); 00132 } 00133 00134 /************************************************************************/ 00135 /* GDALSetDescription() */ 00136 /************************************************************************/ 00137 00138 void GDALSetDescription( GDALMajorObjectH hObject, const char *pszNewDesc ) 00139 00140 { 00141 ((GDALMajorObject *) hObject)->SetDescription( pszNewDesc ); 00142 } 00143 00144 /************************************************************************/ 00145 /* GetMetadata() */ 00146 /************************************************************************/ 00147 00166 char **GDALMajorObject::GetMetadata( const char * pszDomain ) 00167 00168 { 00169 if( pszDomain == NULL || EQUAL(pszDomain,"") ) 00170 return papszMetadata; 00171 else 00172 return NULL; 00173 } 00174 00175 /************************************************************************/ 00176 /* GDALGetMetadata() */ 00177 /************************************************************************/ 00178 00179 char **GDALGetMetadata( GDALMajorObjectH hObject, const char * pszDomain ) 00180 00181 { 00182 return ((GDALMajorObject *) hObject)->GetMetadata(pszDomain); 00183 } 00184 00185 /************************************************************************/ 00186 /* SetMetadata() */ 00187 /************************************************************************/ 00188 00203 CPLErr GDALMajorObject::SetMetadata( char ** papszMetadataIn, 00204 const char * pszDomain ) 00205 00206 { 00207 if( pszDomain != NULL && !EQUAL(pszDomain,"") ) 00208 { 00209 CPLError( CE_Failure, CPLE_NotSupported, 00210 "Non-default domain not supported for this object." ); 00211 return CE_Failure; 00212 } 00213 00214 CSLDestroy( papszMetadata ); 00215 papszMetadata = CSLDuplicate( papszMetadataIn ); 00216 00217 return CE_None; 00218 } 00219 00220 /************************************************************************/ 00221 /* GDALSetMetadata() */ 00222 /************************************************************************/ 00223 00224 CPLErr GDALSetMetadata( GDALMajorObjectH hObject, char **papszMD, 00225 const char *pszDomain ) 00226 00227 { 00228 return ((GDALMajorObject *) hObject)->SetMetadata( papszMD, pszDomain ); 00229 } 00230 00231 00232 /************************************************************************/ 00233 /* GetMetadataItem() */ 00234 /************************************************************************/ 00235 00248 const char *GDALMajorObject::GetMetadataItem( const char * pszName, 00249 const char * pszDomain ) 00250 00251 { 00252 char **papszMD = GetMetadata( pszDomain ); 00253 00254 return CSLFetchNameValue( papszMD, pszName ); 00255 } 00256 00257 /************************************************************************/ 00258 /* GDALGetMetadataItem() */ 00259 /************************************************************************/ 00260 00261 const char *GDALGetMetadataItem( GDALMajorObjectH hObject, 00262 const char *pszName, 00263 const char *pszDomain ) 00264 00265 { 00266 return ((GDALMajorObject *) hObject)->GetMetadataItem( pszName, pszDomain); 00267 } 00268 00269 /************************************************************************/ 00270 /* SetMetadataItem() */ 00271 /************************************************************************/ 00272 00285 CPLErr GDALMajorObject::SetMetadataItem( const char * pszName, 00286 const char * pszValue, 00287 const char * pszDomain ) 00288 00289 { 00290 if( pszDomain != NULL && !EQUAL(pszDomain,"") ) 00291 { 00292 CPLError( CE_Failure, CPLE_NotSupported, 00293 "Non-default domain not supported for this object." ); 00294 return CE_Failure; 00295 } 00296 00297 papszMetadata = CSLSetNameValue( papszMetadata, pszName, pszValue ); 00298 00299 return CE_None; 00300 } 00301 00302 /************************************************************************/ 00303 /* GDALSetMetadataItem() */ 00304 /************************************************************************/ 00305 00306 CPLErr GDALSetMetadataItem( GDALMajorObjectH hObject, 00307 const char *pszName, const char *pszValue, 00308 const char *pszDomain ) 00309 00310 { 00311 return ((GDALMajorObject *) hObject)->SetMetadataItem( pszName, pszValue, 00312 pszDomain ); 00313 }