Commit fc923078 authored by Victor Poughon's avatar Victor Poughon

COMP: add missing string includes

Before this commit, many files are using std::string without including
<string>. It can work accidentally but causes issues when refactoring,
especially if using operator <<() which is included implicitly by some
compilers.

To find guilty header files, I used:

    grep -l "^ *std::string" $(grep -L "#include <string>" $(find . -type f -name "*.h"))

which finds all files containing "std::string" at the beginning of a line
(usually a member or variable declaration), but not "#include <string>".
And then this script to add the includes (plus some manual ediing):

    #!/usr/bin/env python3

    import re
    import argparse

    def fix_file(filename, header):

        with open(filename, "r") as f:
            content = f.read()

        matches = list(re.finditer(r"(#include .*\n)\n", content))
        if len(matches) == 0:
            print("no include!")
            sys.exit(-1)

        pos = matches[-1].end(1)
        open(filename, "w").write(content[:pos] + "#include <{}>\n".format(header) + content[pos:])

    if __name__ == "__main__":
        parser = argparse.ArgumentParser()
        parser.add_argument('--header', type=str, required=True)
        parser.add_argument('files', type=str, nargs='+')
        args = parser.parse_args()

        for filename in args.files:
            fix_file(filename, args.header)
parent 205fd8d8
......@@ -22,6 +22,7 @@
#define otbCurlHelper_h
#include "otbCurlHelperInterface.h"
#include <string>
namespace otb
{
......
......@@ -37,6 +37,7 @@
// #include "itkIndent.h", included from field
#include "otbOGRFeatureWrapper.h"
#include "otbOGRVersionProxy.h"
#include <string>
// #include "ogr_core.h" // OGRwkbGeometryType, included from feature -> field
// Forward declarations
......
......@@ -29,6 +29,7 @@
#include "itkPoint.h"
#include "OTBOSSIMAdaptersExport.h"
#include <string>
class ossimElevManager;
......
......@@ -32,6 +32,7 @@
//Estimator
#include "otbMachineLearningModelFactory.h"
#include <string>
namespace otb
{
......
......@@ -28,6 +28,7 @@
#include "otbImageToEnvelopeVectorDataFilter.h"
#include "otbSamplingRateCalculator.h"
#include "otbOGRDataToSamplePositionFilter.h"
#include <string>
namespace otb
{
......
......@@ -36,6 +36,7 @@
#include <algorithm>
#include <locale>
#include <string>
namespace otb
{
......
......@@ -136,6 +136,7 @@ private:
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbTrainDimensionalityReductionApplicationBase.hxx"
#include "otbDimensionalityReductionTrainSOM.hxx"
#include <string>
#ifdef OTB_USE_SHARK
#include "otbDimensionalityReductionTrainAutoencoder.hxx"
......
......@@ -27,6 +27,7 @@
#include "itkObject.h"
#include "itkObjectFactory.h"
#include "OTBCommonExport.h"
#include <string>
namespace otb
{
......
......@@ -27,6 +27,7 @@
#include "otbImageKeywordlist.h"
#include "itkImageRegion.h"
#include <string>
namespace otb
{
......
......@@ -32,6 +32,7 @@
#include "otbPolygon.h"
#include <map>
#include <string>
namespace otb
{
......
......@@ -25,6 +25,7 @@
#include "otbLabelMapFeaturesFunctorImageFilter.h"
#include "itkMatrix.h"
#include "itkVector.h"
#include <string>
namespace otb
{
......
......@@ -22,6 +22,7 @@
#define otbFormosatImageMetadataInterface_h
#include "otbOpticalImageMetadataInterface.h"
#include <string>
namespace otb
{
......
......@@ -22,6 +22,7 @@
#define otbPleiadesImageMetadataInterface_h
#include "otbOpticalImageMetadataInterface.h"
#include <string>
namespace otb
{
......
......@@ -22,6 +22,7 @@
#define otbSpot6ImageMetadataInterface_h
#include "otbOpticalImageMetadataInterface.h"
#include <string>
namespace otb
{
......
......@@ -22,6 +22,7 @@
#define otbSpotImageMetadataInterface_h
#include "otbOpticalImageMetadataInterface.h"
#include <string>
namespace otb
{
......
......@@ -26,6 +26,7 @@
#include "otbTransform.h"
#include "itkMacro.h"
#include "otbMapProjectionAdapter.h"
#include <string>
namespace otb
{
......
......@@ -22,6 +22,7 @@
#define otbGenericRSTransform_h
#include "otbCompositeTransform.h"
#include <string>
namespace otb
{
......
......@@ -23,6 +23,7 @@
#include "itkObject.h"
#include "otbGenericRSTransform.h"
#include <string>
namespace otb {
......
......@@ -28,6 +28,7 @@
#include "ogrsf_frmts.h"
#include <string>
namespace otb
{
......
......@@ -23,6 +23,7 @@
#include "itkDataObject.h"
#include "itkObjectFactory.h"
#include <string>
namespace otb
{
......
......@@ -33,6 +33,7 @@
#include "itkMetaDataObject.h"
#include "otbRemoteSensingRegion.h"
#include "otbMacro.h"
#include <string>
namespace otb
{
......
......@@ -23,6 +23,7 @@
#include <iosfwd>
#include <vector>
#include <string>
#include "itkLightObject.h"
#include "itkObjectFactory.h"
......
......@@ -26,6 +26,7 @@
#include "itkPreOrderTreeIterator.h"
#include "itkMersenneTwisterRandomVariateGenerator.h"
#include "itkEuclideanDistanceMetric.h"
#include <string>
namespace otb
......
......@@ -22,6 +22,7 @@
#define otbObjectDetectionClassifier_h
#include <vector>
#include <string>
#include "itkImageRegion.h"
#include "itkFixedArray.h"
......
......@@ -23,6 +23,7 @@
#include "otbPathListToPathListFilter.h"
#include "otbMacro.h"
#include <string>
namespace otb
{
......
......@@ -22,6 +22,7 @@
#define otbDEMToImageGenerator_h
#include <stdio.h>
#include <string>
#include "itkImageSource.h"
#include "otbImage.h"
......
......@@ -28,6 +28,7 @@
#include "itkArray.h"
#include "otbParser.h"
#include <string>
namespace otb
{
......
......@@ -26,6 +26,7 @@
#include "otbParser.h"
#include "otbMacro.h"
#include "otbBinarySpectralAngleFunctor.h"
#include <string>
namespace otb
{
......
......@@ -25,6 +25,7 @@
#include "otbParser.h"
#include "otbMacro.h"
#include <string>
namespace otb
......
......@@ -24,6 +24,7 @@
#include "otbDataNodeImageFunction.h"
#include "otbPolyLineImageConstIterator.h"
#include "otbMaskMuParserFunctor.h"
#include <string>
namespace otb
{
......
......@@ -31,6 +31,7 @@
#include "otbParserX.h"
#include <vector>
#include <string>
namespace otb
......
......@@ -23,6 +23,7 @@
#include "otbStreamingResampleImageFilter.h"
#include "otbPhysicalToRPCSensorModelImageFilter.h"
#include <string>
namespace otb
{
......
......@@ -28,6 +28,7 @@
#include "otbGenericRSTransform.h"
#include "OTBProjectionExport.h"
#include <string>
class OGRCoordinateTransformation;
......
......@@ -23,6 +23,7 @@
#include "otbVectorDataSource.h"
#include "otbGenericRSTransform.h"
#include <string>
namespace otb
{
......
......@@ -24,6 +24,7 @@
#include "otbVectorDataToVectorDataFilter.h"
#include "otbGenericRSTransform.h"
#include "otbImageKeywordlist.h"
#include <string>
namespace otb
{
......
......@@ -26,6 +26,7 @@
#include "itkListSample.h"
#include "itkPreOrderTreeIterator.h"
#include "itkMersenneTwisterRandomVariateGenerator.h"
#include <string>
namespace otb
{
......
......@@ -22,6 +22,7 @@
#define otbPatternSampler_h
#include "otbSamplerBase.h"
#include <string>
namespace otb
{
......
......@@ -25,6 +25,7 @@
#include "otbVectorData.h"
#include "itkPreOrderTreeIterator.h"
#include "itkMersenneTwisterRandomVariateGenerator.h"
#include <string>
namespace otb
{
......
......@@ -25,6 +25,7 @@
#include "itkImageSource.h"
#include "otbRGBAPixelConverter.h"
#include "otbVectorDataExtractROI.h"
#include <string>
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
......
......@@ -25,6 +25,7 @@
#include "itkMultiThreader.h"
#include "otbCurlHelperInterface.h"
#include "OTBCartoExport.h"
#include <string>
namespace otb
{
......
......@@ -37,6 +37,7 @@
// projection filter
#include "otbGenericRSResampleImageFilter.h"
#include <string>
namespace otb
{
......
......@@ -23,6 +23,7 @@
#include "otbCurlHelperInterface.h"
#include "OTBCartoExport.h"
#include <string>
namespace otb
{
......
......@@ -26,6 +26,7 @@
#include "itkObject.h"
#include "itkObjectFactory.h"
#include "OTBCartoExport.h"
#include <string>
namespace otb {
......
......@@ -22,6 +22,7 @@
#define otbExtendedFilenameToReaderOptions_h
#include "otbExtendedFilenameHelper.h"
#include <string>
namespace otb
{
......
......@@ -23,6 +23,7 @@
#include "otbExtendedFilenameHelper.h"
#include "otbGDALImageIO.h"
#include <string>
namespace otb
{
......
......@@ -30,6 +30,7 @@
#include "otbConfigure.h"
#include "OTBIOGDALExport.h"
#include <string>
namespace otb
{
......
......@@ -22,6 +22,7 @@
#define otbStatisticsXMLFileReader_h
#include "itkProcessObject.h"
#include <string>
namespace otb {
......
......@@ -36,6 +36,7 @@
#include "otbDefaultConvertPixelTraits.h"
#include "otbImageKeywordlist.h"
#include "otbExtendedFilenameToReaderOptions.h"
#include <string>
namespace otb
{
......
......@@ -26,6 +26,7 @@
#include "otbStreamingManager.h"
#include "otbExtendedFilenameToWriterOptions.h"
#include "itkFastMutexLock.h"
#include <string>
namespace otb
{
......
......@@ -39,6 +39,7 @@
// Possibility to includes vectordatas necessary includes
#include "otbVectorData.h"
#include "otbVectorDataFileWriter.h"
#include <string>
namespace otb
......
......@@ -23,6 +23,7 @@
#include "otbVectorDataSource.h"
#include "otbVectorDataIOBase.h"
#include <string>
namespace otb
{
......
......@@ -24,6 +24,7 @@
#include "itkProcessObject.h"
#include "itkMacro.h"
#include "otbVectorDataIOBase.h"
#include <string>
namespace otb
{
......
......@@ -24,6 +24,7 @@
#include "itkSingleValuedCostFunction.h"
#include "otbVectorDataToDSValidatedVectorDataFilter.h"
#include <string>
namespace otb
{
......
......@@ -32,6 +32,7 @@
#include "otbFuzzyVariable.h"
#include "otbJointMassOfBeliefFilter.h"
#include "otbParser.h"
#include <string>
namespace otb
{
......
......@@ -22,6 +22,7 @@
#include "otbMachineLearningModelTraits.h"
#include "otbMachineLearningModel.h"
#include <string>
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
......
......@@ -25,6 +25,7 @@
#include "otbPersistentFilterStreamingDecorator.h"
#include "otbOGRDataSourceWrapper.h"
#include "otbImage.h"
#include <string>
namespace otb
{
......
......@@ -24,6 +24,7 @@
#include "otbPersistentSamplingFilterBase.h"
#include "otbPersistentFilterStreamingDecorator.h"
#include "itkSimpleDataObjectDecorator.h"
#include <string>
namespace otb
{
......
......@@ -26,6 +26,7 @@
#include "otbSamplingRateCalculator.h"
#include "otbPeriodicSampler.h"
#include "otbImage.h"
#include <string>
namespace otb
{
......
......@@ -24,6 +24,7 @@
#include "otbPersistentImageFilter.h"
#include "otbOGRDataSourceWrapper.h"
#include "otbImage.h"
#include <string>
namespace otb
{
......
......@@ -25,6 +25,7 @@
#include "otbOGRDataSourceWrapper.h"
#include "otbSampleAugmentation.h"
#include "OTBSamplingExport.h"
#include <string>
namespace otb
{
......
......@@ -26,6 +26,7 @@
#include <itkObject.h>
#include <itkObjectFactory.h>
#include <itkVariableSizeMatrix.h>
#include <string>
namespace otb
{
......
......@@ -59,6 +59,7 @@
// SPTW
#include <algorithm>
#include <vector>
#include <string>
#if defined(__GNUC__) || defined(__clang__)
# pragma GCC diagnostic push
......
......@@ -27,6 +27,7 @@
#include "otbNumberOfDivisionsTiledStreamingManager.h"
#include <vector>
#include <sstream>
#include <string>
#include <itksys/SystemTools.hxx>
......
......@@ -23,6 +23,7 @@
#include "otbRCC8GraphSource.h"
#include "itkMacro.h"
#include <string>
namespace otb
{
......
......@@ -24,6 +24,7 @@
#include "itkProcessObject.h"
#include "itkMacro.h"
#include "otbRCC8Graph.h"
#include <string>
namespace otb
{
......
......@@ -22,6 +22,7 @@
#define otbBuiltUpIndicesFunctor_h
#include "otbVegetationIndicesFunctor.h"
#include <string>
namespace otb
{
......
......@@ -27,6 +27,7 @@
#include "otbFuzzyVariable.h"
#include <vector>
#include <algorithm>
#include <string>
namespace otb
{
......
......@@ -24,6 +24,7 @@
#include "otbMath.h"
#include "itkVariableLengthVector.h"
#include "otbBandName.h"
#include <string>
namespace otb
{
......
......@@ -24,6 +24,7 @@
#include "otbMath.h"
#include "itkVariableLengthVector.h"
#include "otbBandName.h"
#include <string>
namespace otb
{
......
......@@ -25,6 +25,7 @@
#include "itkVariableLengthVector.h"
#include "otbSqrtSpectralAngleFunctor.h"
#include "otbBandName.h"
#include <string>
namespace otb
{
......
......@@ -22,6 +22,7 @@
#define otbLandsatTMSRBC_h
#include "otbLandsatTMIndices.h"
#include <string>
namespace otb
{
......
......@@ -25,6 +25,7 @@
#include "itkObjectFactory.h"
#include "itkMacro.h"
#include "OTBOpticalCalibrationExport.h"
#include <string>
namespace otb
{
......
......@@ -28,6 +28,7 @@
#include "otbObjectList.h"
#include "otbFilterFunctionValues.h"
#include <vector>
#include <string>
namespace otb
{
......
......@@ -28,6 +28,7 @@
#include "otbObjectList.h"
#include "otbFilterFunctionValues.h"
#include <vector>
#include <string>
namespace otb
{
......