[gdal-dev] Draft GDAL/OGR class hierarchy for GDAL 2.0

Vincent Mora vincent.mora at oslandia.com
Tue Mar 25 07:26:35 PDT 2014


>> Partial sound ok to me, but I not so good at naming  ?
>>
>> Considering the number of classes, I gave it some thoughts this morning
>> and, like Dmitry, thought of merging the Abtract (Partial) into the
>> interface before realizing that, even if it works (you can overload de
>> default function in Empty) it's a bit ugly and I ended up preferring
>> your solution.
>>
>> An altenative would be to have a Dataset with both aspects and provide
>> three partial specialisations: one for vector (it will behave like empty
>> raster) one for raster, and one for both. Code duplications could be
>> avoided by implementing protected member functions in the Dataset class
>> and simply calling them in the implementations of partial
>> specialization. This solution avoid the diamond shaped inheritance
>> diagram of hell :)
> Actually the diamond shaped inheritance does not work at all (as I somehow
> feared ;-)). I must have confused myself with how I would have done things in
> Java, but in C++, I can't manage to do it... Here's a self-contained code that
> does not compile : https://gist.github.com/rouault/9761494
>
> I think I'm going to try something more plain and stupid. Just "import" methods
> from OGRDataSource into GDALDataset, making OGRDataSource extends GDALDataset
> and make that compile...
>
> I'm not sure to have understood what you meant with "protected member functions
> in the Dataset class and simply calling them in the implementations of partial
> specialization". With an example it would be clearer to me.
>
Sorry, I mixed up things, what I meant was pure virtual with 
implementation (see below).

(note: I use struct instead of class because it avoid repeating 'public' 
all the time)

struct IGDALDataset
{
     virtual int         HandleRasterData() = 0;
     virtual int         HandleVectorData() = 0;
};

int IGDALDataset::HandleVectorData()
{
     return true;
}

int IGDALDataset::HandleRasterData()
{
     return true;
}

struct GDALVectorDataset: IGDALDataset
{
     int HandleRasterData(){ return false; }
     int HandleVectorData(){ return IGDALDataset::HandleVectorData(); }
};

struct GDALRasterDataset: IGDALDataset
{
     int HandleRasterData(){ return IGDALDataset::HandleRasterData(); }
     int HandleVectorData(){ return false; }
};


struct GDALDataset: IGDALDataset
{
     int HandleRasterData(){ return IGDALDataset::HandleRasterData(); }
     int HandleVectorData(){ return IGDALDataset::HandleVectorData(); }
};







More information about the gdal-dev mailing list