LCOV - code coverage report
Current view: directory - gcore - gdalmajorobject.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 46 45 97.8 %
Date: 2012-12-26 Functions: 19 16 84.2 %

       1                 : /******************************************************************************
       2                 :  * $Id: gdalmajorobject.cpp 23156 2011-10-01 15:34:16Z rouault $
       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                 : #include "gdal_priv.h"
      31                 : #include "cpl_string.h"
      32                 : 
      33                 : CPL_CVSID("$Id: gdalmajorobject.cpp 23156 2011-10-01 15:34:16Z rouault $");
      34                 : 
      35                 : /************************************************************************/
      36                 : /*                          GDALMajorObject()                           */
      37                 : /************************************************************************/
      38                 : 
      39          716718 : GDALMajorObject::GDALMajorObject()
      40                 : 
      41                 : {
      42          716718 :     nFlags = GMO_VALID;
      43          716718 : }
      44                 : 
      45                 : /************************************************************************/
      46                 : /*                          ~GDALMajorObject()                          */
      47                 : /************************************************************************/
      48                 : 
      49          714267 : GDALMajorObject::~GDALMajorObject()
      50                 : 
      51                 : {
      52          714267 :     if( (nFlags & GMO_VALID) == 0 )
      53               0 :         CPLDebug( "GDAL", "In ~GDALMajorObject on invalid object" );
      54                 : 
      55          714267 :     nFlags &= ~GMO_VALID;
      56          714267 : }
      57                 : 
      58                 : /************************************************************************/
      59                 : /*                           GetDescription()                           */
      60                 : /************************************************************************/
      61                 : 
      62                 : /**
      63                 :  * \brief Fetch object description. 
      64                 :  *
      65                 :  * The semantics of the returned description are specific to the derived
      66                 :  * type.  For GDALDatasets it is the dataset name.  For GDALRasterBands
      67                 :  * it is actually a description (if supported) or "".
      68                 :  *
      69                 :  * This method is the same as the C function GDALGetDescription().
      70                 :  * 
      71                 :  * @return non-null pointer to internal description string.
      72                 :  */
      73                 : 
      74         9679093 : const char *GDALMajorObject::GetDescription() const
      75                 : 
      76                 : {
      77         9679093 :     return sDescription.c_str();
      78                 : }
      79                 : 
      80                 : /************************************************************************/
      81                 : /*                         GDALGetDescription()                         */
      82                 : /************************************************************************/
      83                 : 
      84                 : /**
      85                 :  * \brief Fetch object description. 
      86                 :  *
      87                 :  * @see GDALMajorObject::GetDescription()
      88                 :  */ 
      89                 : 
      90             452 : const char * CPL_STDCALL GDALGetDescription( GDALMajorObjectH hObject )
      91                 : 
      92                 : {
      93             452 :     VALIDATE_POINTER1( hObject, "GDALGetDescription", NULL );
      94                 : 
      95             452 :     return ((GDALMajorObject *) hObject)->GetDescription();
      96                 : }
      97                 : 
      98                 : /************************************************************************/
      99                 : /*                           SetDescription()                           */
     100                 : /************************************************************************/
     101                 : 
     102                 : /**
     103                 :  * \brief Set object description. 
     104                 :  *
     105                 :  * The semantics of the description are specific to the derived
     106                 :  * type.  For GDALDatasets it is the dataset name.  For GDALRasterBands
     107                 :  * it is actually a description (if supported) or "".
     108                 :  *
     109                 :  * Normally application code should not set the "description" for 
     110                 :  * GDALDatasets.  It is handled internally.  
     111                 :  *
     112                 :  * This method is the same as the C function GDALSetDescription().
     113                 :  */
     114                 : 
     115           88689 : void GDALMajorObject::SetDescription( const char * pszNewDesc ) 
     116                 : 
     117                 : {
     118           88689 :     sDescription = pszNewDesc;
     119           88689 : }
     120                 : 
     121                 : /************************************************************************/
     122                 : /*                         GDALSetDescription()                         */
     123                 : /************************************************************************/
     124                 : 
     125                 : /**
     126                 :  * \brief Set object description. 
     127                 :  *
     128                 :  * @see GDALMajorObject::SetDescription()
     129                 :  */ 
     130                 : 
     131              40 : void CPL_STDCALL GDALSetDescription( GDALMajorObjectH hObject, const char *pszNewDesc )
     132                 : 
     133                 : {
     134              40 :     VALIDATE_POINTER0( hObject, "GDALSetDescription" );
     135                 : 
     136              40 :     ((GDALMajorObject *) hObject)->SetDescription( pszNewDesc );
     137                 : }
     138                 : 
     139                 : /************************************************************************/
     140                 : /*                            GetMetadata()                             */
     141                 : /************************************************************************/
     142                 : 
     143                 : /**
     144                 :  * \brief Fetch metadata.
     145                 :  *
     146                 :  * The returned string list is owned by the object, and may change at
     147                 :  * any time.  It is formated as a "Name=value" list with the last pointer
     148                 :  * value being NULL.  Use the the CPL StringList functions such as 
     149                 :  * CSLFetchNameValue() to manipulate it. 
     150                 :  *
     151                 :  * Note that relatively few formats return any metadata at this time. 
     152                 :  *
     153                 :  * This method does the same thing as the C function GDALGetMetadata().
     154                 :  *
     155                 :  * @param pszDomain the domain of interest.  Use "" or NULL for the default
     156                 :  * domain.
     157                 :  * 
     158                 :  * @return NULL or a string list. 
     159                 :  */
     160                 : 
     161            5776 : char **GDALMajorObject::GetMetadata( const char * pszDomain )
     162                 : 
     163                 : {
     164            5776 :     return oMDMD.GetMetadata( pszDomain );
     165                 : }
     166                 : 
     167                 : /************************************************************************/
     168                 : /*                          GDALGetMetadata()                           */
     169                 : /************************************************************************/
     170                 : 
     171                 : /**
     172                 :  * \brief Fetch metadata.
     173                 :  *
     174                 :  * @see GDALMajorObject::GetMetadata()
     175                 :  */ 
     176                 : 
     177                 : char ** CPL_STDCALL 
     178            3994 : GDALGetMetadata( GDALMajorObjectH hObject, const char * pszDomain )
     179                 : 
     180                 : {
     181            3994 :     VALIDATE_POINTER1( hObject, "GDALGetMetadata", NULL );
     182                 : 
     183            3994 :     return ((GDALMajorObject *) hObject)->GetMetadata(pszDomain);
     184                 : }
     185                 : 
     186                 : /************************************************************************/
     187                 : /*                            SetMetadata()                             */
     188                 : /************************************************************************/
     189                 : 
     190                 : /** 
     191                 :  * \brief Set metadata. 
     192                 :  *
     193                 :  * The C function GDALSetMetadata() does the same thing as this method.
     194                 :  *
     195                 :  * @param papszMetadataIn the metadata in name=value string list format to
     196                 :  * apply.  
     197                 :  * @param pszDomain the domain of interest.  Use "" or NULL for the default
     198                 :  * domain. 
     199                 :  * @return CE_None on success, CE_Failure on failure and CE_Warning if the
     200                 :  * metadata has been accepted, but is likely not maintained persistently 
     201                 :  * by the underlying object between sessions.
     202                 :  */
     203                 : 
     204            2445 : CPLErr GDALMajorObject::SetMetadata( char ** papszMetadataIn, 
     205                 :                                      const char * pszDomain )
     206                 : 
     207                 : {
     208            2445 :     nFlags |= GMO_MD_DIRTY;
     209            2445 :     return oMDMD.SetMetadata( papszMetadataIn, pszDomain );
     210                 : }
     211                 : 
     212                 : /************************************************************************/
     213                 : /*                          GDALSetMetadata()                           */
     214                 : /************************************************************************/
     215                 : 
     216                 : /**
     217                 :  * \brief Set metadata. 
     218                 :  *
     219                 :  * @see GDALMajorObject::SetMetadata()
     220                 :  */ 
     221                 : 
     222                 : CPLErr CPL_STDCALL 
     223             353 : GDALSetMetadata( GDALMajorObjectH hObject, char **papszMD, 
     224                 :                  const char *pszDomain )
     225                 : 
     226                 : {
     227             353 :     VALIDATE_POINTER1( hObject, "GDALSetMetadata", CE_Failure );
     228                 : 
     229             353 :     return ((GDALMajorObject *) hObject)->SetMetadata( papszMD, pszDomain );
     230                 : }
     231                 : 
     232                 : 
     233                 : /************************************************************************/
     234                 : /*                          GetMetadataItem()                           */
     235                 : /************************************************************************/
     236                 : 
     237                 : /**
     238                 :  * \brief Fetch single metadata item.
     239                 :  *
     240                 :  * The C function GDALGetMetadataItem() does the same thing as this method.
     241                 :  *
     242                 :  * @param pszName the key for the metadata item to fetch.
     243                 :  * @param pszDomain the domain to fetch for, use NULL for the default domain.
     244                 :  *
     245                 :  * @return NULL on failure to find the key, or a pointer to an internal
     246                 :  * copy of the value string on success.
     247                 :  */
     248                 : 
     249           32415 : const char *GDALMajorObject::GetMetadataItem( const char * pszName, 
     250                 :                                               const char * pszDomain )
     251                 : 
     252                 : {
     253           32415 :     return oMDMD.GetMetadataItem( pszName, pszDomain );
     254                 : }
     255                 : 
     256                 : /************************************************************************/
     257                 : /*                        GDALGetMetadataItem()                         */
     258                 : /************************************************************************/
     259                 : 
     260                 : /**
     261                 :  * \brief Fetch single metadata item.
     262                 :  *
     263                 :  * @see GDALMajorObject::GetMetadataItem()
     264                 :  */ 
     265                 : 
     266            1443 : const char * CPL_STDCALL GDALGetMetadataItem( GDALMajorObjectH hObject, 
     267                 :                                  const char *pszName, 
     268                 :                                  const char *pszDomain )
     269                 : 
     270                 : {
     271            1443 :     VALIDATE_POINTER1( hObject, "GDALGetMetadataItem", NULL );
     272                 : 
     273            1443 :     return ((GDALMajorObject *) hObject)->GetMetadataItem( pszName, pszDomain);
     274                 : }
     275                 : 
     276                 : /************************************************************************/
     277                 : /*                          SetMetadataItem()                           */
     278                 : /************************************************************************/
     279                 : 
     280                 : /**
     281                 :  * \brief Set single metadata item.
     282                 :  *
     283                 :  * The C function GDALSetMetadataItem() does the same thing as this method.
     284                 :  *
     285                 :  * @param pszName the key for the metadata item to fetch.
     286                 :  * @param pszValue the value to assign to the key.
     287                 :  * @param pszDomain the domain to set within, use NULL for the default domain.
     288                 :  *
     289                 :  * @return CE_None on success, or an error code on failure.
     290                 :  */
     291                 : 
     292          347150 : CPLErr GDALMajorObject::SetMetadataItem( const char * pszName, 
     293                 :                                          const char * pszValue, 
     294                 :                                          const char * pszDomain )
     295                 : 
     296                 : {
     297          347150 :     nFlags |= GMO_MD_DIRTY;
     298          347150 :     return oMDMD.SetMetadataItem( pszName, pszValue,  pszDomain );
     299                 : }
     300                 : 
     301                 : /************************************************************************/
     302                 : /*                        GDALSetMetadataItem()                         */
     303                 : /************************************************************************/
     304                 : 
     305                 : /**
     306                 :  * \brief Set single metadata item.
     307                 :  *
     308                 :  * @see GDALMajorObject::SetMetadataItem()
     309                 :  */ 
     310                 : 
     311                 : CPLErr CPL_STDCALL 
     312              34 : GDALSetMetadataItem( GDALMajorObjectH hObject, 
     313                 :                      const char *pszName, const char *pszValue, 
     314                 :                      const char *pszDomain )
     315                 : 
     316                 : {
     317              34 :     VALIDATE_POINTER1( hObject, "GDALSetMetadataItem", CE_Failure );
     318                 : 
     319                 :     return ((GDALMajorObject *) hObject)->SetMetadataItem( pszName, pszValue,
     320              34 :                                                            pszDomain );
     321                 : }
     322                 : 
     323                 : /************************************************************************/
     324                 : /*                             GetMOFlags()                             */
     325                 : /************************************************************************/
     326                 : 
     327         1601365 : int GDALMajorObject::GetMOFlags()
     328                 : 
     329                 : {
     330         1601365 :     return nFlags;
     331                 : }
     332                 : 
     333                 : /************************************************************************/
     334                 : /*                             SetMOFlags()                             */
     335                 : /************************************************************************/
     336                 : 
     337          636279 : void GDALMajorObject::SetMOFlags( int nNewFlags )
     338                 : 
     339                 : {
     340          636279 :     nFlags = nNewFlags;
     341          636279 : }
     342                 : 

Generated by: LCOV version 1.7