Commit 0f26e689 authored by Manuel Grizonnet's avatar Manuel Grizonnet

STYLE: Use ITK_NULLPTR to utilize c++11 features

    Where available, use c++11 features to identify
    potential nullptr usage errors.

    python run-clang-tidy.py -clang-tidy-binary ~/software/clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang-tidy -checks=-*,modernize-use-nullptr -header-filter=/home/grizonnetm/projets/otb/src/OTB/Modules/.*/.*/include/.* -j8 -fix -p ~/projets/otb/bin/release/OTB-clang3.8/ ~/projets/otb/src/OTB/Modules/*/*/src/*.cxx ~/projets/otb/src/OTB/Modules/*/*/app/*.cxx ~/projets/otb/src/OTB/Examples/*/*.cxx ~/projets/otb/src/OTB/Modules/*/*/test/*.cxx > ~/temporary/run-clang-tidy-nullptr-log.txt

    find . -type f -print -name "*.h" -o -name "*.txx" -o -name "*.cxx" |xargs perl -pi -e 's/nullptr/ITK_NULLPTR/g'
parent 037f971c
int main(int argc, char *argv[])
{
int *p = nullptr;
int *p = ITK_NULLPTR;
return 0;
}
......@@ -62,7 +62,7 @@ private:
otb::ogr::UniqueGeometryPtr
ReprojectTransformationFunctor::operator()(OGRGeometry const* in) const
{
otb::ogr::UniqueGeometryPtr out(in ? in->clone() : 0);
otb::ogr::UniqueGeometryPtr out(in ? in->clone() : ITK_NULLPTR);
if (out)
{
const OGRErr err = out->transform(m_reprojector.get());
......@@ -204,7 +204,7 @@ int main (int argc, char **argv)
otb::ogr::DataSource::Pointer output
= options.workingInplace ? input
: options.outputIsStdout ? 0
: options.outputIsStdout ? ITK_NULLPTR
: otb::ogr::DataSource::New( options.outputFile, otb::ogr::DataSource::Modes::Update_LayerCreateOnly);
std::cout << "input: " << otb::ogr::version_proxy::GetFileListAsStringVector(&input->ogr())[0] << " should be: " << options.inputFile << "\n";
if (output)
......@@ -231,7 +231,7 @@ int main (int argc, char **argv)
}
else
{
filter->UpdateOutputData(0);
filter->UpdateOutputData(ITK_NULLPTR);
assert(filter->GetOutput() && "output not set");
filter->GetOutput()->Print(std::cout, 0);
}
......
......@@ -32,7 +32,7 @@ struct SwapXYFunctor
typedef OGRGeometry TransformedElementType;
otb::ogr::UniqueGeometryPtr operator()(OGRGeometry const* in) const
{
otb::ogr::UniqueGeometryPtr out(in ? in->clone() : 0);
otb::ogr::UniqueGeometryPtr out(in ? in->clone() : ITK_NULLPTR);
if (out)
{
#if GDAL_VERSION_NUM >= 1900
......@@ -71,7 +71,7 @@ int main (int argc, char **argv)
otb::ogr::DataSource::Pointer output
= workingInplace ? input
: outputIsStdout ? 0
: outputIsStdout ? ITK_NULLPTR
: otb::ogr::DataSource::New( outputFile, otb::ogr::DataSource::Modes::Update_LayerCreateOnly);
std::cout << "input: " << otb::ogr::version_proxy::GetFileListAsStringVector(&input->ogr())[0] << " should be: " << inputFile << "\n";
if (output)
......@@ -94,7 +94,7 @@ int main (int argc, char **argv)
}
else
{
filter->UpdateOutputData(0);
filter->UpdateOutputData(ITK_NULLPTR);
assert(filter->GetOutput() && "output not set");
filter->GetOutput()->Print(std::cout, 0);
}
......
......@@ -106,7 +106,7 @@ int main(int argc, char * argv[])
otb::ogr::DataSource::Pointer destination = otb::ogr::DataSource::New(
argv[2], otb::ogr::DataSource::Modes::Update_LayerCreateOnly);
otb::ogr::Layer destLayer = destination->CreateLayer(
argv[2], 0, wkbMultiPolygon);
argv[2], ITK_NULLPTR, wkbMultiPolygon);
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
......
......@@ -100,7 +100,7 @@ int main(int argc, char * argv[])
// Software Guide : EndCodeSnippet
char * fileNameIn = argv[1];
char * fileNameImgInit = NULL;
char * fileNameImgInit = ITK_NULLPTR;
char * fileNameOut = argv[2];
int numberOfClasses = atoi(argv[3]);
int numberOfIteration = atoi(argv[4]);
......@@ -146,7 +146,7 @@ int main(int argc, char * argv[])
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
if (fileNameImgInit != NULL)
if (fileNameImgInit != ITK_NULLPTR)
{
typedef otb::ImageFileReader<OutputImageType> ImgInitReaderType;
ImgInitReaderType::Pointer segReader = ImgInitReaderType::New();
......
......@@ -406,7 +406,7 @@ int main(int itkNotUsed(argc), char* argv[])
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
if (actMapFileName != NULL)
if (actMapFileName != ITK_NULLPTR)
{
ActivationWriterType::Pointer actWriter = ActivationWriterType::New();
actWriter->SetFileName(actMapFileName);
......
......@@ -152,8 +152,8 @@ int main(int argc, char* argv[])
orthoRectifFilter->SetDisplacementFieldSpacing(gridSpacing);
ImageType::PointType origin;
origin[0] = strtod(argv[5], NULL);
origin[1] = strtod(argv[6], NULL);
origin[0] = strtod(argv[5], ITK_NULLPTR);
origin[1] = strtod(argv[6], ITK_NULLPTR);
orthoRectifFilter->SetOutputOrigin(origin);
// Software Guide : EndCodeSnippet
......
......@@ -184,8 +184,8 @@ int main(int argc, char* argv[])
spacing[1] = -0.00001;
ImageType::PointType origin;
origin[0] = strtod(argv[3], NULL); //longitude
origin[1] = strtod(argv[4], NULL); //latitude
origin[0] = strtod(argv[3], ITK_NULLPTR); //longitude
origin[1] = strtod(argv[4], ITK_NULLPTR); //latitude
ImageType::RegionType region;
......
......@@ -130,7 +130,7 @@ public:
protected:
ImageUniqueValuesCalculator()
{
m_Image = NULL;
m_Image = ITK_NULLPTR;
}
~ImageUniqueValuesCalculator() ITK_OVERRIDE
{
......@@ -469,7 +469,7 @@ private:
int main(int argc, char *argv[])
{
char *cmifname = NULL;
char *cmifname = ITK_NULLPTR;
if (argc != 10)
{
if (argc == 11) // cloud mask filename optional parameter
......@@ -804,7 +804,7 @@ int main(int argc, char *argv[])
miReader->UpdateOutputInformation();
MaskImageType::Pointer maskImage = miReader->GetOutput();
if (cmifname != NULL)
if (cmifname != ITK_NULLPTR)
{
MaskReaderType::Pointer cmiReader = MaskReaderType::New();
......
......@@ -139,8 +139,8 @@ int main(int argc, char* argv[])
spacing[1] = atof(argv[11]);
ImageType::PointType origin;
origin[0] = strtod(argv[6], NULL);
origin[1] = strtod(argv[7], NULL);
origin[0] = strtod(argv[6], ITK_NULLPTR);
origin[1] = strtod(argv[7], ITK_NULLPTR);
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
......
......@@ -175,7 +175,7 @@ public:
{
m_File = fopen(infname, "wb");
if (m_File == NULL)
if (m_File == ITK_NULLPTR)
{
itkExceptionMacro(<<" otbCurlHelper::FileResource : failed to open the file ."<< infname);
}
......
......@@ -276,7 +276,7 @@ public:
* \return the extent of all layers
* \throw itk::ExceptionObject if the layers extents can not be retrieved.
*/
OGREnvelope GetGlobalExtent(bool force = false, std::string * outwkt=0) const;
OGREnvelope GetGlobalExtent(bool force = false, std::string * outwkt=ITK_NULLPTR) const;
/** Grafts data and information from one data source to another.
* \deprecated \c OGRLayer has an embedded input iterator. As a consequence,
......@@ -323,7 +323,7 @@ public:
*/
Layer CreateLayer(
std::string const& name,
OGRSpatialReference * poSpatialRef = NULL,
OGRSpatialReference * poSpatialRef = ITK_NULLPTR,
OGRwkbGeometryType eGType = wkbUnknown,
std::vector<std::string> const& papszOptions = std::vector<std::string>());
......@@ -363,7 +363,7 @@ public:
Layer CopyLayer(
Layer & srcLayer,
std::string const& newName,
char ** papszOptions = NULL);
char ** papszOptions = ITK_NULLPTR);
//@}
/**\name Layers access
......@@ -466,7 +466,7 @@ public:
* \see <em>Imperfect C++</em>, Matthew Wilson, Addisson-Welsey, par 24.6
*/
operator int boolean ::* () const {
return m_DataSource ? &boolean::i : 0;
return m_DataSource ? &boolean::i : ITK_NULLPTR;
}
/** Flushes all changes to disk.
......
......@@ -76,7 +76,7 @@ struct StringListConverter
{
m_raw.push_back(b->c_str());
}
m_raw.push_back(0);
m_raw.push_back(ITK_NULLPTR);
assert(CSLCount(const_cast <char**>(&m_raw[0])) == static_cast<int>(boost::size(strings)));
}
/**
......@@ -85,7 +85,7 @@ struct StringListConverter
char ** to_ogr() const
{
return m_raw.size() == 1
? NULL
? ITK_NULLPTR
: const_cast <char**>(&m_raw[0]);
}
private:
......
......@@ -230,7 +230,7 @@ public:
*/
operator int boolean ::* () const
{
return m_Layer ? &boolean::i : 0;
return m_Layer ? &boolean::i : ITK_NULLPTR;
}
/** Access to raw \c OGRLayer.
......@@ -332,12 +332,12 @@ public:
struct enabler {};
public:
feature_iter()
: m_Layer(0), m_Crt(0) {}
: m_Layer(ITK_NULLPTR), m_Crt(ITK_NULLPTR) {}
explicit feature_iter(otb::ogr::Layer & layer)
: m_Layer(&layer), m_Crt(layer.GetNextFeature()) {}
template <class OtherValue> feature_iter(
feature_iter<OtherValue> const& other,
typename boost::enable_if<boost::is_convertible<OtherValue*,Value*> >::type* = 0
typename boost::enable_if<boost::is_convertible<OtherValue*,Value*> >::type* = ITK_NULLPTR
)
: m_Layer(other.m_Layer), m_Crt(other.m_Crt)
{}
......
......@@ -216,7 +216,7 @@ void otb::GeometriesToGeometriesFilter::GenerateData(void )
OGRSpatialReference* otb::GeometriesToGeometriesFilter::DoDefineNewLayerSpatialReference(
ogr::Layer const& itkNotUsed(source)) const
{
return 0;
return ITK_NULLPTR;
}
/*virtual*/
......
......@@ -40,7 +40,7 @@
/*===========================================================================*/
bool otb::ogr::DataSource::Clear()
{
Reset(0);
Reset(ITK_NULLPTR);
return true;
}
......@@ -104,7 +104,7 @@ char const* DeduceDriverName(std::string filename)
boost::bind(&ExtensionDriverAssociation::Matches, _1, extension));
if (whichIt == boost::end(k_ExtensionDriverMap))
{
return 0; // nothing found
return ITK_NULLPTR; // nothing found
}
return whichIt->driverName;
}
......@@ -112,7 +112,7 @@ char const* DeduceDriverName(std::string filename)
otb::ogr::DataSource::DataSource()
: m_DataSource(0),
: m_DataSource(ITK_NULLPTR),
m_OpenMode(Modes::Update_LayerUpdate),
m_FirstModifiableLayerID(0)
{
......@@ -195,7 +195,7 @@ otb::ogr::DataSource::New(std::string const& datasourceName, Modes::type mode)
ogr::version_proxy::GDALDatasetType * ds = ogr::version_proxy::Open(datasourceName.c_str(),true);
bool ds_exists = (ds!=NULL);
bool ds_exists = (ds!=ITK_NULLPTR);
ogr::version_proxy::Close(ds);
......@@ -343,7 +343,7 @@ otb::ogr::Layer otb::ogr::DataSource::CreateLayer(
}
itkGenericExceptionMacro(<< "GDALDataset opening mode not supported");
return Layer(0, false); // keep compiler happy
return Layer(ITK_NULLPTR, false); // keep compiler happy
}
otb::ogr::Layer otb::ogr::DataSource::CopyLayer(
......@@ -542,7 +542,7 @@ otb::ogr::Layer otb::ogr::DataSource::ExecuteSQL(
// Cannot use the deleter made for result sets obtained from
// GDALDataset::ExecuteSQL because it checks for non-nullity....
// *sigh*
return otb::ogr::Layer(0, modifiable);
return otb::ogr::Layer(ITK_NULLPTR, modifiable);
#endif
}
return otb::ogr::Layer(layer_ptr, *m_DataSource, modifiable);
......
......@@ -270,7 +270,7 @@ OGRSpatialReference const* otb::ogr::Layer::GetSpatialRef() const
std::string otb::ogr::Layer::GetProjectionRef() const
{
assert(m_Layer && "OGRLayer not initialized");
char * wkt = 0;
char * wkt = ITK_NULLPTR;
OGRSpatialReference const* srs = GetSpatialRef();
if(srs)
{
......
......@@ -57,7 +57,7 @@ bool Delete(const char * name)
{
// Open dataset
GDALDatasetType * poDS = Open(name,false);
GDALDriverType * poDriver = NULL;
GDALDriverType * poDriver = ITK_NULLPTR;
if(poDS)
{
poDriver = poDS->GetDriver();
......
......@@ -188,7 +188,7 @@ BOOST_AUTO_TEST_CASE(OGRDataSource_shp_overwrite)
ogr::DataSource::Pointer ds
= ogr::DataSource::New(filename, ogr::DataSource::Modes::Overwrite);
BOOST_ASSERT(ds);
ogr::Layer l = ds -> CreateLayer(layer1, 0, wkbPoint);
ogr::Layer l = ds -> CreateLayer(layer1, ITK_NULLPTR, wkbPoint);
OGRFeatureDefn & defn = l.GetLayerDefn();
l.CreateField(k_f0);
l.CreateField(k_f1);
......@@ -222,7 +222,7 @@ BOOST_AUTO_TEST_CASE(OGRDataSource_shp_overwrite)
ogr::DataSource::Pointer ds
= ogr::DataSource::New(filename, ogr::DataSource::Modes::Overwrite);
BOOST_ASSERT(ds);
ogr::Layer l = ds -> CreateLayer(layer1, 0, wkbPoint);
ogr::Layer l = ds -> CreateLayer(layer1, ITK_NULLPTR, wkbPoint);
OGRFeatureDefn & defn = l.GetLayerDefn();
l.CreateField(k_f0);
l.CreateField(k_f1);
......@@ -473,7 +473,7 @@ BOOST_AUTO_TEST_CASE(OGRDataSource_sqlite_overwrite)
ogr::DataSource::Pointer ds
= ogr::DataSource::New(filename, ogr::DataSource::Modes::Overwrite);
BOOST_ASSERT(ds);
ogr::Layer l = ds -> CreateLayer(layer1, 0, wkbPoint);
ogr::Layer l = ds -> CreateLayer(layer1, ITK_NULLPTR, wkbPoint);
OGRFeatureDefn & defn = l.GetLayerDefn();
l.CreateField(k_f0);
l.CreateField(k_f1);
......@@ -507,7 +507,7 @@ BOOST_AUTO_TEST_CASE(OGRDataSource_sqlite_overwrite)
ogr::DataSource::Pointer ds
= ogr::DataSource::New(filename, ogr::DataSource::Modes::Overwrite);
BOOST_ASSERT(ds);
ogr::Layer l = ds -> CreateLayer(layer1, 0, wkbPoint);
ogr::Layer l = ds -> CreateLayer(layer1, ITK_NULLPTR, wkbPoint);
OGRFeatureDefn & defn = l.GetLayerDefn();
l.CreateField(k_f0);
l.CreateField(k_f1);
......@@ -600,7 +600,7 @@ BOOST_AUTO_TEST_CASE(OGRDataSource_sqlite_overwrite)
// Check that we can read the file
BOOST_ASSERT(ds);
ogr::Layer l = ds -> CreateLayer(layer1, 0, wkbPoint);
ogr::Layer l = ds -> CreateLayer(layer1, ITK_NULLPTR, wkbPoint);
BOOST_CHECK_EQUAL(l.GetFeatureCount(true), 0);
// OGRFeatureDefn & defn = l.GetLayerDefn();
......@@ -675,7 +675,7 @@ BOOST_AUTO_TEST_CASE(Add_n_Del_Fields)
ogr::FieldDefn f5(*defn.GetFieldDefn(5));
BOOST_CHECK_EQUAL(f5, k_f5);
BOOST_CHECK_EQUAL(defn.GetFieldDefn(6), (void*)0);
BOOST_CHECK_EQUAL(defn.GetFieldDefn(6), (void*)ITK_NULLPTR);
}
#if GDAL_VERSION_NUM >= 1900
......@@ -799,7 +799,7 @@ BOOST_AUTO_TEST_CASE(OGRDataSource_new_shp_with_features)
const std::string k_shp = "SomeShapeFileWithFeatures";
ogr::DataSource::Pointer ds = ogr::DataSource::New(k_shp+".shp", ogr::DataSource::Modes::Overwrite);
ogr::Layer l = ds -> CreateLayer(k_one, 0, wkbPoint);
ogr::Layer l = ds -> CreateLayer(k_one, ITK_NULLPTR, wkbPoint);
OGRFeatureDefn & defn = l.GetLayerDefn();
l.CreateField(k_f0);
......@@ -837,7 +837,7 @@ BOOST_AUTO_TEST_CASE(Local_Geometries)
BOOST_AUTO_TEST_CASE(Add_n_Read_Geometries)
{
ogr::DataSource::Pointer ds = ogr::DataSource::New();
ogr::Layer l = ds -> CreateLayer(k_one, 0, wkbPoint);
ogr::Layer l = ds -> CreateLayer(k_one, ITK_NULLPTR, wkbPoint);
OGRFeatureDefn & defn = l.GetLayerDefn();
for (int u=-10; u!=10; ++u) {
......
......@@ -89,7 +89,7 @@ int DEMConvertAdapter::Convert(std::string tempFilename, std::string output)
ih->initialize();
ossimRefPtr<ossimImageSource> source = ih.get();
ossimRefPtr<ossimBandSelector> bs = 0;
ossimRefPtr<ossimBandSelector> bs = ITK_NULLPTR;
// Get the image rectangle for the rrLevel selected.
......
......@@ -48,15 +48,15 @@
namespace otb
{
/** Initialize the singleton */
DEMHandler::Pointer DEMHandler::m_Singleton = NULL;
DEMHandler::Pointer DEMHandler::m_Singleton = ITK_NULLPTR;
DEMHandler::Pointer DEMHandler::Instance()
{
if(m_Singleton.GetPointer() == NULL)
if(m_Singleton.GetPointer() == ITK_NULLPTR)
{
m_Singleton = itk::ObjectFactory<Self>::Create();
if(m_Singleton.GetPointer() == NULL)
if(m_Singleton.GetPointer() == ITK_NULLPTR)
{
m_Singleton = new DEMHandler;
}
......@@ -149,7 +149,7 @@ bool
DEMHandler
::OpenGeoidFile(const char* geoidFile)
{
if ((ossimGeoidManager::instance()->findGeoidByShortName("geoid1996")) == 0)
if ((ossimGeoidManager::instance()->findGeoidByShortName("geoid1996")) == ITK_NULLPTR)
{
otbMsgDevMacro(<< "Opening geoid: " << geoidFile);
ossimFilename geoid(geoidFile);
......
......@@ -29,7 +29,7 @@ DateTimeAdapter::DateTimeAdapter()
DateTimeAdapter::~DateTimeAdapter()
{
if (m_LocalTm != NULL)
if (m_LocalTm != ITK_NULLPTR)
{
delete m_LocalTm;
}
......
......@@ -41,7 +41,7 @@ EllipsoidAdapter::EllipsoidAdapter()
EllipsoidAdapter::~EllipsoidAdapter()
{
if (m_Ellipsoid != NULL)
if (m_Ellipsoid != ITK_NULLPTR)
{
delete m_Ellipsoid;
}
......
......@@ -42,16 +42,16 @@
namespace otb {
GeometricSarSensorModelAdapter::GeometricSarSensorModelAdapter():
m_SensorModel(NULL)
m_SensorModel(ITK_NULLPTR)
{
}
GeometricSarSensorModelAdapter::~GeometricSarSensorModelAdapter()
{
if (m_SensorModel != NULL)
if (m_SensorModel != ITK_NULLPTR)
{
delete m_SensorModel;
m_SensorModel = NULL;
m_SensorModel = ITK_NULLPTR;
}
}
......
......@@ -258,7 +258,7 @@ ReadGeometryFromImage(const std::string& filename, bool checkRpcTag)
// Free memory
delete projection;
projection = 0;
projection = ITK_NULLPTR;
}
......@@ -433,15 +433,15 @@ ReadGeometryFromRPCTag(const std::string& filename)
// try to use GeoTiff RPC tag if present.
// Warning : RPC in subdatasets are not supported
GDALDriverH identifyDriverH = GDALIdentifyDriver(filename.c_str(), NULL);
if(identifyDriverH == NULL)
GDALDriverH identifyDriverH = GDALIdentifyDriver(filename.c_str(), ITK_NULLPTR);
if(identifyDriverH == ITK_NULLPTR)
{
// If no driver has identified the dataset, don't try to open it and exit
return otb_kwl;
}
GDALDatasetH datasetH = GDALOpen(filename.c_str(), GA_ReadOnly);
if (datasetH != NULL)
if (datasetH != ITK_NULLPTR)
{
GDALDataset* dataset = static_cast<GDALDataset*>(datasetH);
GDALRPCInfo rpcStruct;
......
......@@ -73,13 +73,13 @@ namespace otb
{
MapProjectionAdapter::MapProjectionAdapter():
m_MapProjection(NULL), m_ProjectionRefWkt(""), m_ReinstanciateProjection(true)
m_MapProjection(ITK_NULLPTR), m_ProjectionRefWkt(""), m_ReinstanciateProjection(true)
{
}
MapProjectionAdapter::~MapProjectionAdapter()
{
if (m_MapProjection != NULL)
if (m_MapProjection != ITK_NULLPTR)
{
delete m_MapProjection;
}
......@@ -88,7 +88,7 @@ MapProjectionAdapter::~MapProjectionAdapter()
MapProjectionAdapter::InternalMapProjectionPointer MapProjectionAdapter::GetMapProjection()
{
itkDebugMacro("returning MapProjection address " << this->m_MapProjection);
if ((m_ReinstanciateProjection) || (m_MapProjection == NULL))
if ((m_ReinstanciateProjection) || (m_MapProjection == ITK_NULLPTR))
{
this->InstanciateProjection();
}
......@@ -99,7 +99,7 @@ MapProjectionAdapter::InternalMapProjectionPointer MapProjectionAdapter::GetMapP
MapProjectionAdapter::InternalMapProjectionConstPointer MapProjectionAdapter::GetMapProjection() const
{
itkDebugMacro("returning MapProjection address " << this->m_MapProjection);
if ((m_ReinstanciateProjection) || (m_MapProjection == NULL))
if ((m_ReinstanciateProjection) || (m_MapProjection == ITK_NULLPTR))
{
itkExceptionMacro(<< "m_MapProjection not up-to-date, call InstanciateProjection() first");
}
......@@ -111,7 +111,7 @@ std::string MapProjectionAdapter::GetWkt() const
{
ossimKeywordlist kwl;
this->GetMapProjection();
if (m_MapProjection == NULL)
if (m_MapProjection == ITK_NULLPTR)
{
return "";
}
......@@ -217,7 +217,7 @@ std::string MapProjectionAdapter::GetParameter(const std::string& key) const