Skip to content

Commit

Permalink
GDALDataset: make GetRasterXSize/YSize/Count/Band() const
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Mar 19, 2024
1 parent fc7cebd commit 349fdc4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
11 changes: 6 additions & 5 deletions gcore/gdal_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -616,10 +616,11 @@ class CPL_DLL GDALDataset : public GDALMajorObject

virtual CPLErr Close();

int GetRasterXSize();
int GetRasterYSize();
int GetRasterCount();
int GetRasterXSize() const;
int GetRasterYSize() const;
int GetRasterCount() const;
GDALRasterBand *GetRasterBand(int);
const GDALRasterBand *GetRasterBand(int) const;

/**
* @brief SetQueryLoggerFunc
Expand Down Expand Up @@ -807,8 +808,8 @@ class CPL_DLL GDALDataset : public GDALMajorObject
);

#ifndef DOXYGEN_XML
void ReportError(CPLErr eErrClass, CPLErrorNum err_no, const char *fmt, ...)
CPL_PRINT_FUNC_FORMAT(4, 5);
void ReportError(CPLErr eErrClass, CPLErrorNum err_no, const char *fmt,
...) const CPL_PRINT_FUNC_FORMAT(4, 5);

static void ReportError(const char *pszDSName, CPLErr eErrClass,
CPLErrorNum err_no, const char *fmt, ...)
Expand Down
45 changes: 41 additions & 4 deletions gcore/gdaldataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ void GDALDataset::SetBand(int nNewBand, std::unique_ptr<GDALRasterBand> poBand)
*/

int GDALDataset::GetRasterXSize()
int GDALDataset::GetRasterXSize() const
{
return nRasterXSize;
}
Expand Down Expand Up @@ -968,7 +968,7 @@ int CPL_STDCALL GDALGetRasterXSize(GDALDatasetH hDataset)
*/

int GDALDataset::GetRasterYSize()
int GDALDataset::GetRasterYSize() const
{
return nRasterYSize;
}
Expand Down Expand Up @@ -1028,6 +1028,43 @@ GDALRasterBand *GDALDataset::GetRasterBand(int nBandId)
return nullptr;
}

/************************************************************************/
/* GetRasterBand() */
/************************************************************************/

/**
\brief Fetch a band object for a dataset.
See GetBands() for a C++ iterator version of this method.
Equivalent of the C function GDALGetRasterBand().
@param nBandId the index number of the band to fetch, from 1 to
GetRasterCount().
@return the nBandId th band object
*/

const GDALRasterBand *GDALDataset::GetRasterBand(int nBandId) const

{
if (papoBands)
{
if (nBandId < 1 || nBandId > nBands)
{
ReportError(CE_Failure, CPLE_IllegalArg,
"GDALDataset::GetRasterBand(%d) - Illegal band #\n",
nBandId);
return nullptr;
}

return papoBands[nBandId - 1];
}
return nullptr;
}

/************************************************************************/
/* GDALGetRasterBand() */
/************************************************************************/
Expand Down Expand Up @@ -1058,7 +1095,7 @@ GDALRasterBandH CPL_STDCALL GDALGetRasterBand(GDALDatasetH hDS, int nBandId)
* @return the number of raster bands.
*/

int GDALDataset::GetRasterCount()
int GDALDataset::GetRasterCount() const
{
return papoBands ? nBands : 0;
}
Expand Down Expand Up @@ -4500,7 +4537,7 @@ int GDALDataset::CloseDependentDatasets()
*/

void GDALDataset::ReportError(CPLErr eErrClass, CPLErrorNum err_no,
const char *fmt, ...)
const char *fmt, ...) const
{
va_list args;
va_start(args, fmt);
Expand Down

0 comments on commit 349fdc4

Please sign in to comment.