Commit fc923078 authored by Victor Poughon's avatar Victor Poughon
Browse files

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
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment