[Gdal-dev] GDALDataset as a Base Class

Mateusz Loskot mateusz at loskot.net
Wed Aug 30 11:20:38 EDT 2006


Matt Hanson wrote:
> I don't mind dealing with pointers.  The purpose of the GSImage and
> related objects is partly to simplify data access (for use by other
> programmers) and also to add functionality (for image processing).
> GSBand adds a data access function to return chunks of read data to
> CImg objects (see cimg.sourceforge.net ), but also will facilitate
> easy artihmetic and logical operators on entire bands.

I see.

> However I confused by the GDALRasterBand implementation, it's an
> abstract class due to the pure virtual IRead function.

Yes, because IReadBlock is implemented by subclasses for drivers, like

MSGRasterBand : public GDALRasterBand
PGCHIPRasterBand : public GDALRasterBand
VRTRasterBand : public GDALRasterBand

Second, and more important, is that there is a close relation
between GDALDataset and GDALRasterBand.
The former controls the latter, because of
friend class GDALDataset
in GDALRasterBand, etc.

So, I assume you need to rethink your idea.

> Thus to derive from it I would need to define that function.

Definitely.

> How does GDAL
> create instances of GDALRasterBand (within the GDALDataset) without
> first defining that function ?

Search for IReadBlock in the GDAL's sources subdirectory called 'frmts'
and see how it's implemented.

> Encapsulating the GDALRasterBand as a data member and
> recreating the interface to it is a relatively small task and works
> for this application.  I would use inheritance but I have too many
> questions with regard to the GDALRasterBand class. I'm not supposed
> to call the GDALRasterBand ctor directly, nor it's dtor, so how does
> this work with a dervied class??

Please, read somewhere about Base Abstract Class, polymorphism
and pure virtual function, for example here:

http://en.wikibooks.org/wiki/C++_Programming/Abstract_Classes
http://www.cplusplus.com/doc/language/tutorial/polymorphism.html


Sorry, I'm not able to give it deeper try today because of lack of time.

Good luck!
-- 
Mateusz Loskot
http://mateusz.loskot.net



More information about the Gdal-dev mailing list