[gdal-dev] Casting poDS, in IReadBlock and similar places
Andrew C Aitchison
andrew at aitchison.me.uk
Tue May 23 03:40:08 PDT 2017
I see that in http://www.gdal.org/gdal_drivertut.html the function
JDEMRasterBand::IReadBlock has
JDEMDataset *poGDS = static_cast<JDEMDataset *>(poDS);
(this is a change from gdal-2.1.3 and earlier where
frmts/jdem/jdemdataset.cpp has
JDEMDataset *poGDS = (JDEMDataset *) poDS;
).
However, I see that amongst other 2.2.0 drivers, reinterpret_cast
is more common than static_cast and the dods driver has dynamic_cast:
egrep -l "_cast<" ~/gdal2.2.0/gdal-2.2.0/frmts/*/*cpp |\
xargs grep -A10 ::IReadBlock | egrep "_cast<.*Dataset \*>.*poDS *\);" |\
sed -e 's=/home/werdna/gdal2.2.0/gdal-2.2.0/frmts/==' | sort -t= -k2
dods/dodsdataset2.cpp- DODSDataset *poDODS = dynamic_cast<DODSDataset *>(poDS);
blx/blxdataset.cpp- BLXDataset *poGDS = reinterpret_cast<BLXDataset *>(poDS);
raw/cpgdataset.cpp- CPGDataset *poGDS = reinterpret_cast<CPGDataset *>( poDS );
raw/cpgdataset.cpp- CPGDataset *poGDS = reinterpret_cast<CPGDataset *>( poDS );
raw/genbindataset.cpp- GenBinDataset *poGDS = reinterpret_cast<GenBinDataset *>( poDS );
gsg/gsbgdataset.cpp- GSBGDataset *poGDS = reinterpret_cast<GSBGDataset *>(poDS);
hdf4/hdf4imagedataset.cpp- HDF4ImageDataset *poGDS = reinterpret_cast<HDF4ImageDataset *>( poDS );
jp2lura/jp2lurarasterband.cpp- JP2LuraDataset *poGDS = reinterpret_cast<JP2LuraDataset *>(poDS);
raw/landataset.cpp- LANDataset *poLAN_DS = reinterpret_cast<LANDataset *>( poDS );
leveller/levellerdataset.cpp- LevellerDataset *poGDS = reinterpret_cast<LevellerDataset *>( poDS );
ngsgeoid/ngsgeoiddataset.cpp- NGSGEOIDDataset *poGDS = reinterpret_cast<NGSGEOIDDataset *>( poDS );
nitf/nitfrasterband.cpp- NITFDataset *poGDS = reinterpret_cast<NITFDataset *>( poDS );
northwood/grcdataset.cpp- NWT_GRCDataset *poGDS = reinterpret_cast<NWT_GRCDataset *>( poDS );
northwood/grddataset.cpp- NWT_GRDDataset *poGDS = reinterpret_cast<NWT_GRDDataset *>(poDS);
ozi/ozidataset.cpp- OZIDataset *poGDS = reinterpret_cast<OZIDataset *>( poDS );
plmosaic/plmosaicdataset.cpp- PLMosaicDataset* poMOSDS = reinterpret_cast<PLMosaicDataset *>( poDS );
png/pngdataset.cpp- PNGDataset *poGDS = reinterpret_cast<PNGDataset *>( poDS );
rasterlite/rasterlitedataset.cpp- RasterliteDataset* poGDS = reinterpret_cast<RasterliteDataset *>( poDS );
rik/rikdataset.cpp- RIKDataset *poRDS = reinterpret_cast<RIKDataset *>( poDS );
rmf/rmfdataset.cpp- RMFDataset *poGDS = reinterpret_cast<RMFDataset *>( poDS );
sgi/sgidataset.cpp- SGIDataset* poGDS = reinterpret_cast<SGIDataset *>( poDS );
srtmhgt/srtmhgtdataset.cpp- SRTMHGTDataset* poGDS = reinterpret_cast<SRTMHGTDataset *>( poDS );
terragen/terragendataset.cpp- TerragenDataset& ds = *reinterpret_cast<TerragenDataset *>( poDS );
usgsdem/usgsdemdataset.cpp- USGSDEMDataset *poGDS = reinterpret_cast<USGSDEMDataset *>( poDS );
vrt/vrtwarped.cpp- VRTWarpedDataset *poWDS = reinterpret_cast<VRTWarpedDataset *>( poDS );
webp/webpdataset.cpp- WEBPDataset* poGDS = reinterpret_cast<WEBPDataset *>( poDS );
xyz/xyzdataset.cpp- XYZDataset *poGDS = reinterpret_cast<XYZDataset *>( poDS );
zmap/zmapdataset.cpp- ZMapDataset *poGDS = reinterpret_cast<ZMapDataset *>( poDS );
aaigrid/aaigriddataset.cpp- AAIGDataset *poODS = static_cast<AAIGDataset *>(poDS);
hdf5/hdf5imagedataset.cpp- HDF5ImageDataset *poGDS = static_cast<HDF5ImageDataset *>(poDS);
iris/irisdataset.cpp- IRISDataset *poGDS = static_cast<IRISDataset *>(poDS);
jdem/jdemdataset.cpp- JDEMDataset *poGDS = static_cast<JDEMDataset *>(poDS);
jpeg/jpgdataset.cpp- JPGDataset *poJDS = static_cast<JPGDataset *>(poDS);
saga/sagadataset.cpp- SAGADataset *poGDS = static_cast<SAGADataset *>( poDS );
My C++ is 25 years old and self taught, so I am still learning when to
use static_cast, dynamic_cast and reinterpret_cast (and const_cast).
Can anyone more familiar with modern C++ guide me ?
Thanks,
Andrew C Aitchison
More information about the gdal-dev
mailing list