Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

gdalmajorobject.cpp

00001 /******************************************************************************
00002  * $Id: gdalmajorobject_cpp-source.html,v 1.8 2001/07/05 13:24:08 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.8  2001/07/05 13:24:08  warmerda
00030  * *** empty log message ***
00030  *
00031  * Revision 1.2  2000/06/26 15:26:21  warmerda
00032  * added GDALGetDescription
00033  *
00034  * Revision 1.1  2000/04/20 20:52:03  warmerda
00035  * New
00036  *
00037  */
00038 
00039 #include "gdal_priv.h"
00040 #include "cpl_string.h"
00041 
00042 /************************************************************************/
00043 /*                          GDALMajorObject()                           */
00044 /************************************************************************/
00045 
00046 GDALMajorObject::GDALMajorObject()
00047 
00048 {
00049     pszDescription = NULL;
00050     papszMetadata = NULL;
00051 }
00052 
00053 /************************************************************************/
00054 /*                          ~GDALMajorObject()                          */
00055 /************************************************************************/
00056 
00057 GDALMajorObject::~GDALMajorObject()
00058 
00059 {
00060     CPLFree( pszDescription );
00061     CSLDestroy( papszMetadata );
00062 }
00063 
00064 /************************************************************************/
00065 /*                           GetDescription()                           */
00066 /************************************************************************/
00067 
00078 const char *GDALMajorObject::GetDescription() const
00079 
00080 {
00081     if( pszDescription == NULL )
00082         return "";
00083     else
00084         return pszDescription;
00085 }
00086 
00087 /************************************************************************/
00088 /*                         GDALGetDescription()                         */
00089 /************************************************************************/
00090 
00091 const char *GDALGetDescription( GDALMajorObjectH hObject )
00092 
00093 {
00094     return ((GDALMajorObject *) hObject)->GetDescription();
00095 }
00096 
00097 /************************************************************************/
00098 /*                           SetDescription()                           */
00099 /************************************************************************/
00100 
00101 void GDALMajorObject::SetDescription( const char * pszNewDesc ) 
00102 
00103 {
00104     CPLFree( pszDescription );
00105     pszDescription = CPLStrdup( pszNewDesc );
00106 }
00107 
00108 /************************************************************************/
00109 /*                            GetMetadata()                             */
00110 /************************************************************************/
00111 
00130 char **GDALMajorObject::GetMetadata( const char * pszDomain )
00131 
00132 {
00133     if( pszDomain == NULL || EQUAL(pszDomain,"") )
00134         return papszMetadata;
00135     else
00136         return NULL;
00137 }
00138 
00139 /************************************************************************/
00140 /*                          GDALGetMetadata()                           */
00141 /************************************************************************/
00142 
00143 char **GDALGetMetadata( GDALMajorObjectH hObject, const char * pszDomain )
00144 
00145 {
00146     return ((GDALMajorObject *) hObject)->GetMetadata(pszDomain);
00147 }
00148 
00149 /************************************************************************/
00150 /*                            SetMetadata()                             */
00151 /************************************************************************/
00152 
00165 CPLErr GDALMajorObject::SetMetadata( char ** papszMetadataIn, 
00166                                      const char * pszDomain )
00167 
00168 {
00169     if( pszDomain != NULL && !EQUAL(pszDomain,"") )
00170     {
00171         CPLError( CE_Failure, CPLE_NotSupported, 
00172                   "Non-default domain not supported for this object." );
00173         return CE_Failure;
00174     }
00175 
00176     CSLDestroy( papszMetadata );
00177     papszMetadata = CSLDuplicate( papszMetadataIn );
00178     
00179     return CE_None;
00180 }
00181 
00182 /************************************************************************/
00183 /*                          GetMetadataItem()                           */
00184 /************************************************************************/
00185 
00186 const char *GDALMajorObject::GetMetadataItem( const char * pszName, 
00187                                               const char * pszDomain )
00188 
00189 {
00190     char  **papszMD = GetMetadata( pszDomain );
00191     
00192     return CSLFetchNameValue( papszMD, pszName );
00193 }
00194 
00195 /************************************************************************/
00196 /*                          SetMetadataItem()                           */
00197 /************************************************************************/
00198 
00199 CPLErr GDALMajorObject::SetMetadataItem( const char * pszName, 
00200                                          const char * pszValue, 
00201                                          const char * pszDomain )
00202 
00203 {
00204     if( pszDomain != NULL && !EQUAL(pszDomain,"") )
00205     {
00206         CPLError( CE_Failure, CPLE_NotSupported, 
00207                   "Non-default domain not supported for this object." );
00208         return CE_Failure;
00209     }
00210 
00211     papszMetadata = CSLSetNameValue( papszMetadata, pszName, pszValue );
00212 
00213     return CE_None;
00214 }
00215 

Generated at Thu Jul 5 09:16:13 2001 for GDAL by doxygen1.2.3-20001105 written by Dimitri van Heesch, © 1997-2000