[gdal-dev] C++ template functions with raster bands
Ari Jolma
ari.jolma at gmail.com
Tue Mar 29 08:35:26 PDT 2016
I want to write template functions like this:
template<typename cell_type>
void map(GDALRasterBand *b, mapper<cell_type> *mapper) {
...
This function would map the cell values of a band to new ones using some
logic that is coded within the mapper object (and the logic depends on
the cell_type).
I would like to catch errors which are due to mismatch between the band
data type and the template cell_type. So far I've discovered this:
band_wrapper band = band_initialize(b);
if (band.info.size_of_data_type != sizeof(cell_type))
goto fail_because_of_data_type_mismatch;
but it is not bullet proof since data types can have an equal size but
be different. The band_initialize contains a switch statement, which
sets the info element of the band wrapper.
Are there other ways to solve this problem? I could build long switch
statements but it is not very appealing. And it gets messy when there is
more than one band.
Ari
More information about the gdal-dev
mailing list