[Gdal-dev] GDALDataset as a Base Class
Mateusz Loskot
mateusz at loskot.net
Sat Sep 2 17:55:22 EDT 2006
Matt Hanson wrote:
> Obviously by making GImage a template it assumes, or
> rather makes, all bands of the same data type
IMHO it's not so obvious and fixed.
I think I understand your idea but I'm not able to talk
about it in details.
Generally, you can use template to generate type and algorithms
appropriate for particular enumerator from GDALDataType.
Shortly, or very shortly, template may be used in place of
switch expression, to make type decisions in compile time.
One of techniques are metafunctions, or type functions in other words.
For example, you can generate concrete type based on decisions like
if A is of type of X do ... else do ...
IMO MPL library (http://www.boost.org/libs/mpl/) is a
good place to start, especially
http://www.boost.org/libs/mpl/doc/refmanual/metafunctions.html
> 2 - Try and look up and return a typename based on the GDALDatatype
> enum. This means parsing the file and returning a typename, then the
> user can use typename to instantiate a GImage object. This is a very
> difficult thing to do, even if it is possible. I think that
> something similar to the ideas presented here:
> http://www.accu-usa.org/2000-05-Main.html may work. At the very
> least this approach requires pre-instantiated GImage classes of all
> the datatypes GDAL supports. i.e. typedef GImage<short> int16GImage;
> typedef CImage<double> doubleGImage; and so on.
CImage may be a like std::vector<T>, where user specifies T
passing appropriate type. You can add some compile-time checks
and "if's", etc. using metafunctions.
Simply, you can generate the code based on user's type selection.
I know I'm giving general ideas, but it's a nice piece of design
and sorry I am not able consider all details of it.
Cheers
--
Mateusz Loskot
http://mateusz.loskot.net
More information about the Gdal-dev
mailing list