@@ -2017,7 +2017,7 @@ int CPL_STDCALL GDALGetGCPCount(GDALDatasetH hDS)
20172017 * It should not be altered, freed or expected to last for long.
20182018 */
20192019
2020- const char *GDALDataset::GetGCPProjection ()
2020+ const char *GDALDataset::GetGCPProjection () const
20212021{
20222022 const auto poSRS = GetGCPSpatialRef ();
20232023 if (!poSRS || !m_poPrivate)
@@ -5076,7 +5076,7 @@ char **GDALDataset::GetMetadataDomainList()
50765076/* * Return driver name.
50775077 * @return driver name.
50785078 */
5079- const char *GDALDataset::GetDriverName ()
5079+ const char *GDALDataset::GetDriverName () const
50805080{
50815081 if (poDriver)
50825082 return poDriver->GetDescription ();
@@ -9491,7 +9491,7 @@ bool GDALDataset::Bands::Iterator::operator!=(const Iterator &it) const
94919491}
94929492
94939493/* ***********************************************************************/
9494- /* GetBands() */
9494+ /* GetBands() */
94959495/* ***********************************************************************/
94969496
94979497/* * Function that returns an iterable object over GDALRasterBand in the dataset.
@@ -9611,6 +9611,184 @@ GDALRasterBand *GDALDataset::Bands::operator[](size_t iBand)
96119611 return m_poSelf->GetRasterBand (1 + static_cast <int >(iBand));
96129612}
96139613
9614+ /* ***********************************************************************/
9615+ /* GDALDataset::ConstBands::Iterator::Private */
9616+ /* ***********************************************************************/
9617+
9618+ struct GDALDataset ::ConstBands::Iterator::Private
9619+ {
9620+ const GDALRasterBand *m_poBand = nullptr ;
9621+ int m_iCurBand = 0 ;
9622+ int m_nBandCount = 0 ;
9623+ const GDALDataset *m_poDS = nullptr ;
9624+ };
9625+
9626+ GDALDataset::ConstBands::Iterator::Iterator (const GDALDataset *poDS,
9627+ bool bStart)
9628+ : m_poPrivate(new GDALDataset::ConstBands::Iterator::Private())
9629+ {
9630+ m_poPrivate->m_poDS = poDS;
9631+ m_poPrivate->m_nBandCount = poDS->GetRasterCount ();
9632+ if (bStart)
9633+ {
9634+ if (m_poPrivate->m_nBandCount )
9635+ m_poPrivate->m_poBand = poDS->GetRasterBand (1 );
9636+ }
9637+ else
9638+ {
9639+ m_poPrivate->m_iCurBand = m_poPrivate->m_nBandCount ;
9640+ }
9641+ }
9642+
9643+ GDALDataset::ConstBands::Iterator::~Iterator () = default ;
9644+
9645+ const GDALRasterBand *GDALDataset::ConstBands::Iterator::operator *() const
9646+ {
9647+ return m_poPrivate->m_poBand ;
9648+ }
9649+
9650+ GDALDataset::ConstBands::Iterator &
9651+ GDALDataset::ConstBands::Iterator::operator ++()
9652+ {
9653+ m_poPrivate->m_iCurBand ++;
9654+ if (m_poPrivate->m_iCurBand < m_poPrivate->m_nBandCount )
9655+ {
9656+ m_poPrivate->m_poBand =
9657+ m_poPrivate->m_poDS ->GetRasterBand (1 + m_poPrivate->m_iCurBand );
9658+ }
9659+ else
9660+ {
9661+ m_poPrivate->m_poBand = nullptr ;
9662+ }
9663+ return *this ;
9664+ }
9665+
9666+ bool GDALDataset::ConstBands::Iterator::operator !=(const Iterator &it) const
9667+ {
9668+ return m_poPrivate->m_iCurBand != it.m_poPrivate ->m_iCurBand ;
9669+ }
9670+
9671+ /* ***********************************************************************/
9672+ /* GetBands() */
9673+ /* ***********************************************************************/
9674+
9675+ /* * Function that returns an iterable object over GDALRasterBand in the dataset.
9676+ *
9677+ * This is a C++ iterator friendly version of GetRasterBand().
9678+ *
9679+ * Typical use is:
9680+ * \code{.cpp}
9681+ * for( const auto* poBand: poDS->GetConstBands() )
9682+ * {
9683+ * std::cout << "Band << poBand->GetDescription() << std::endl;
9684+ * }
9685+ * \endcode
9686+ *
9687+ * @see GetRasterBand()
9688+ *
9689+ * @since GDAL 3.12
9690+ */
9691+ GDALDataset::ConstBands GDALDataset::GetBands () const
9692+ {
9693+ return ConstBands (this );
9694+ }
9695+
9696+ /* ***********************************************************************/
9697+ /* begin() */
9698+ /* ***********************************************************************/
9699+
9700+ /* *
9701+ \brief Return beginning of band iterator.
9702+
9703+ @since GDAL 3.12
9704+ */
9705+
9706+ const GDALDataset::ConstBands::Iterator GDALDataset::ConstBands::begin () const
9707+ {
9708+ return {m_poSelf, true };
9709+ }
9710+
9711+ /* ***********************************************************************/
9712+ /* end() */
9713+ /* ***********************************************************************/
9714+
9715+ /* *
9716+ \brief Return end of band iterator.
9717+
9718+ @since GDAL 3.12
9719+ */
9720+
9721+ const GDALDataset::ConstBands::Iterator GDALDataset::ConstBands::end () const
9722+ {
9723+ return {m_poSelf, false };
9724+ }
9725+
9726+ /* ***********************************************************************/
9727+ /* size() */
9728+ /* ***********************************************************************/
9729+
9730+ /* *
9731+ \brief Get the number of raster bands in this dataset.
9732+
9733+ @return raster band count.
9734+
9735+ @since GDAL 3.12
9736+ */
9737+
9738+ size_t GDALDataset::ConstBands::size () const
9739+ {
9740+ return static_cast <size_t >(m_poSelf->GetRasterCount ());
9741+ }
9742+
9743+ /* ***********************************************************************/
9744+ /* operator[]() */
9745+ /* ***********************************************************************/
9746+ /* *
9747+ \brief Fetch a raster band by index.
9748+
9749+ The returned band remains owned by the
9750+ GDALDataset and should not be deleted by the application.
9751+
9752+ @warning Contrary to GDALDataset::GetRasterBand(), the indexing here is
9753+ consistent with the conventions of C/C++, i.e. starting at 0.
9754+
9755+ @param iBand a band index between 0 and size()-1.
9756+
9757+ @return the band, or nullptr if iBand is out of range or an error occurs.
9758+
9759+ @since GDAL 3.12
9760+ */
9761+
9762+ const GDALRasterBand *GDALDataset::ConstBands::operator [](int iBand) const
9763+ {
9764+ return m_poSelf->GetRasterBand (1 + iBand);
9765+ }
9766+
9767+ /* ***********************************************************************/
9768+ /* operator[]() */
9769+ /* ***********************************************************************/
9770+
9771+ /* *
9772+ \brief Fetch a raster band by index.
9773+
9774+ The returned band remains owned by the
9775+ GDALDataset and should not be deleted by the application.
9776+
9777+ @warning Contrary to GDALDataset::GetRasterBand(), the indexing here is
9778+ consistent with the conventions of C/C++, i.e. starting at 0.
9779+
9780+ @param iBand a band index between 0 and size()-1.
9781+
9782+ @return the band, or nullptr if iBand is out of range or an error occurs.
9783+
9784+ @since GDAL 3.12
9785+ */
9786+
9787+ const GDALRasterBand *GDALDataset::ConstBands::operator [](size_t iBand) const
9788+ {
9789+ return m_poSelf->GetRasterBand (1 + static_cast <int >(iBand));
9790+ }
9791+
96149792/* ***********************************************************************/
96159793/* GetRootGroup() */
96169794/* ***********************************************************************/
0 commit comments