From df787dfde330372591ff8e3ec1b89ede48b83194 Mon Sep 17 00:00:00 2001 From: Victor Poughon <victor.poughon@cnes.fr> Date: Thu, 2 Aug 2018 16:50:18 +0200 Subject: [PATCH] REFAC: make std::string overload the main implementation --- .../include/otbOGRExtendedFilenameToOptions.h | 3 +- .../src/otbOGRExtendedFilenameToOptions.cxx | 11 ++- .../include/otbExtendedFilenameHelper.h | 1 + .../Common/src/otbExtendedFilenameHelper.cxx | 8 ++ .../otbExtendedFilenameToReaderOptions.h | 4 +- .../otbExtendedFilenameToWriterOptions.h | 3 +- .../otbExtendedFilenameToReaderOptions.cxx | 12 ++- .../otbExtendedFilenameToWriterOptions.cxx | 12 ++- .../IO/ImageIO/include/otbImageFileReader.h | 2 +- .../IO/ImageIO/include/otbImageFileReader.hxx | 80 +++++++++---------- .../IO/ImageIO/include/otbImageFileWriter.h | 2 +- .../IO/ImageIO/include/otbImageFileWriter.hxx | 15 ++-- .../include/otbSimpleParallelTiffWriter.h | 2 +- .../include/otbSimpleParallelTiffWriter.hxx | 23 +++--- .../MPIVrtWriter/include/otbMPIVrtWriter.h | 2 +- .../MPIVrtWriter/include/otbMPIVrtWriter.hxx | 13 +-- 16 files changed, 122 insertions(+), 71 deletions(-) diff --git a/Modules/Adapters/GdalAdapters/include/otbOGRExtendedFilenameToOptions.h b/Modules/Adapters/GdalAdapters/include/otbOGRExtendedFilenameToOptions.h index 6ae631531f..935c55ecc7 100644 --- a/Modules/Adapters/GdalAdapters/include/otbOGRExtendedFilenameToOptions.h +++ b/Modules/Adapters/GdalAdapters/include/otbOGRExtendedFilenameToOptions.h @@ -72,7 +72,8 @@ public: }; /** Set extended filename */ - void SetExtendedFileName(const char * extFname) override; + void SetExtendedFileName(const char* extFname) override; + void SetExtendedFileName(const std::string& extFname) override; /** Get the GDAL option for type operation */ GDALOptionType GetGDALOptions( const std::string & type ) const ; diff --git a/Modules/Adapters/GdalAdapters/src/otbOGRExtendedFilenameToOptions.cxx b/Modules/Adapters/GdalAdapters/src/otbOGRExtendedFilenameToOptions.cxx index a34e709471..4d1c6e5908 100644 --- a/Modules/Adapters/GdalAdapters/src/otbOGRExtendedFilenameToOptions.cxx +++ b/Modules/Adapters/GdalAdapters/src/otbOGRExtendedFilenameToOptions.cxx @@ -48,10 +48,19 @@ GetGDALLayerOptionsHelper( const GDALOptionType & options ) return res; } +void +OGRExtendedFilenameToOptions:: +SetExtendedFileName(const char* extFname) +{ + if (extFname) + { + this->SetExtendedFileName(std::string(extFname)); + } +} void OGRExtendedFilenameToOptions:: -SetExtendedFileName(const char *extFname) +SetExtendedFileName(const std::string& extFname) { Superclass::SetExtendedFileName(extFname); m_HasFileName = true; diff --git a/Modules/Core/Common/include/otbExtendedFilenameHelper.h b/Modules/Core/Common/include/otbExtendedFilenameHelper.h index 983f101eeb..d5472c36ba 100644 --- a/Modules/Core/Common/include/otbExtendedFilenameHelper.h +++ b/Modules/Core/Common/include/otbExtendedFilenameHelper.h @@ -56,6 +56,7 @@ public: typedef std::map< std::string, std::string > OptionMapType; virtual void SetExtendedFileName(const char * extFname); + virtual void SetExtendedFileName(const std::string& extFname); const OptionMapType & GetOptionMap(void) const; itkGetStringMacro(ExtendedFileName); diff --git a/Modules/Core/Common/src/otbExtendedFilenameHelper.cxx b/Modules/Core/Common/src/otbExtendedFilenameHelper.cxx index dae7578305..052c458754 100644 --- a/Modules/Core/Common/src/otbExtendedFilenameHelper.cxx +++ b/Modules/Core/Common/src/otbExtendedFilenameHelper.cxx @@ -42,6 +42,14 @@ ExtendedFilenameHelper { itkGenericExceptionMacro( << "Filename is NULL" ); } + + this->SetExtendedFileName(std::string(extFname)); +} + +void +ExtendedFilenameHelper +::SetExtendedFileName(const std::string& extFname) +{ this->m_ExtendedFileName = extFname; this->m_OptionMap.clear(); std::vector<std::string> tmp1; diff --git a/Modules/IO/ExtendedFilename/include/otbExtendedFilenameToReaderOptions.h b/Modules/IO/ExtendedFilename/include/otbExtendedFilenameToReaderOptions.h index 6753c31479..b9e46ea678 100644 --- a/Modules/IO/ExtendedFilename/include/otbExtendedFilenameToReaderOptions.h +++ b/Modules/IO/ExtendedFilename/include/otbExtendedFilenameToReaderOptions.h @@ -80,7 +80,9 @@ public: }; /* Set Methods */ - void SetExtendedFileName(const char * extFname) override; + void SetExtendedFileName(const char*) override; + void SetExtendedFileName(const std::string&) override; + /* Get Methods */ bool SimpleFileNameIsSet () const; bool ExtGEOMFileNameIsSet () const; diff --git a/Modules/IO/ExtendedFilename/include/otbExtendedFilenameToWriterOptions.h b/Modules/IO/ExtendedFilename/include/otbExtendedFilenameToWriterOptions.h index 88f789482c..79b14931a7 100644 --- a/Modules/IO/ExtendedFilename/include/otbExtendedFilenameToWriterOptions.h +++ b/Modules/IO/ExtendedFilename/include/otbExtendedFilenameToWriterOptions.h @@ -84,7 +84,8 @@ public: bool has_noDataValue; /* Set Methods */ - void SetExtendedFileName(const char * extFname) override; + void SetExtendedFileName(const char*) override; + void SetExtendedFileName(const std::string& extFname) override; /* Get Methods */ bool SimpleFileNameIsSet () const; bool NoDataValueIsSet () const; diff --git a/Modules/IO/ExtendedFilename/src/otbExtendedFilenameToReaderOptions.cxx b/Modules/IO/ExtendedFilename/src/otbExtendedFilenameToReaderOptions.cxx index 308f5239c1..6a38363591 100644 --- a/Modules/IO/ExtendedFilename/src/otbExtendedFilenameToReaderOptions.cxx +++ b/Modules/IO/ExtendedFilename/src/otbExtendedFilenameToReaderOptions.cxx @@ -63,7 +63,17 @@ ExtendedFilenameToReaderOptions void ExtendedFilenameToReaderOptions -::SetExtendedFileName(const char *extFname) +::SetExtendedFileName(const char* extFname) +{ + if (extFname) + { + this->SetExtendedFileName(std::string(extFname)); + } +} + +void +ExtendedFilenameToReaderOptions +::SetExtendedFileName(const std::string& extFname) { Superclass::SetExtendedFileName(extFname); MapType map = GetOptionMap(); diff --git a/Modules/IO/ExtendedFilename/src/otbExtendedFilenameToWriterOptions.cxx b/Modules/IO/ExtendedFilename/src/otbExtendedFilenameToWriterOptions.cxx index e63a83ea55..d5b4ad84af 100644 --- a/Modules/IO/ExtendedFilename/src/otbExtendedFilenameToWriterOptions.cxx +++ b/Modules/IO/ExtendedFilename/src/otbExtendedFilenameToWriterOptions.cxx @@ -61,7 +61,17 @@ ExtendedFilenameToWriterOptions void ExtendedFilenameToWriterOptions -::SetExtendedFileName(const char *extFname) +::SetExtendedFileName(const char* extFname) +{ + if (extFname) + { + this->SetExtendedFileName(std::string(extFname)); + } +} + +void +ExtendedFilenameToWriterOptions +::SetExtendedFileName(const std::string& extFname) { this->Superclass::SetExtendedFileName(extFname); // TODO: Rename map to a less confusing (with std::map) name diff --git a/Modules/IO/ImageIO/include/otbImageFileReader.h b/Modules/IO/ImageIO/include/otbImageFileReader.h index 92b98e099e..c1ba386106 100644 --- a/Modules/IO/ImageIO/include/otbImageFileReader.h +++ b/Modules/IO/ImageIO/include/otbImageFileReader.h @@ -141,7 +141,7 @@ public: itkGetObjectMacro(ImageIO,otb::ImageIOBase); virtual void SetFileName(const char* extendedFileName); - virtual void SetFileName(std::string extendedFileName); + virtual void SetFileName(const std::string& extendedFileName); virtual const char* GetFileName () const; /** Get the resolution information from the file */ diff --git a/Modules/IO/ImageIO/include/otbImageFileReader.hxx b/Modules/IO/ImageIO/include/otbImageFileReader.hxx index b1a752a7df..ec269c5922 100644 --- a/Modules/IO/ImageIO/include/otbImageFileReader.hxx +++ b/Modules/IO/ImageIO/include/otbImageFileReader.hxx @@ -658,64 +658,64 @@ ImageFileReader<TOutputImage, ConvertPixelTraits> template <class TOutputImage, class ConvertPixelTraits> void ImageFileReader<TOutputImage, ConvertPixelTraits> -::SetFileName(std::string extendedFileName) +::SetFileName(const char* in) { - this->SetFileName(extendedFileName.c_str()); + if (in) + { + this->SetFileName(std::string(in)); + } } template <class TOutputImage, class ConvertPixelTraits> void ImageFileReader<TOutputImage, ConvertPixelTraits> -::SetFileName(const char* in) +::SetFileName(const std::string& extendedFileName) { const std::string skip_geom_key = "skipgeom"; const std::string geom_key = "geom"; - if (in) - { - // First, see if the simple filename has changed - typename FNameHelperType::Pointer helper = FNameHelperType::New(); + // First, see if the simple filename has changed + typename FNameHelperType::Pointer helper = FNameHelperType::New(); + + helper->SetExtendedFileName(extendedFileName); + std::string simpleFileName = helper->GetSimpleFileName(); - helper->SetExtendedFileName(in); - std::string simpleFileName = helper->GetSimpleFileName(); + if(simpleFileName == this->m_FileName) + { + // Then, see if the option map changed + const typename ExtendedFilenameHelper::OptionMapType & newMap = helper->GetOptionMap(); + const typename ExtendedFilenameHelper::OptionMapType & oldMap = m_FilenameHelper->GetOptionMap(); - if(simpleFileName == this->m_FileName) + // Both maps are not completely the same + if(oldMap.size() != newMap.size() || !std::equal(oldMap.begin(),oldMap.end(),newMap.begin())) { - // Then, see if the option map changed - const typename ExtendedFilenameHelper::OptionMapType & newMap = helper->GetOptionMap(); - const typename ExtendedFilenameHelper::OptionMapType & oldMap = m_FilenameHelper->GetOptionMap(); + this->Modified(); - // Both maps are not completely the same - if(oldMap.size() != newMap.size() || !std::equal(oldMap.begin(),oldMap.end(),newMap.begin())) + // Now check if keywordlist needs to be generated again + // Condition is: one of the old or new map has the skip_geom + // key and the other does not + // OR + // one of the old or new map has the geom key and the other + // does not + // OR + // both have the geom key but the geom value is different + if((oldMap.count(skip_geom_key) != newMap.count(skip_geom_key)) + || (oldMap.count(geom_key) != newMap.count(geom_key)) + || ((oldMap.count(geom_key) && newMap.count(geom_key)) + && oldMap.find(geom_key)->second != newMap.find(geom_key)->second)) { - this->Modified(); - - // Now check if keywordlist needs to be generated again - // Condition is: one of the old or new map has the skip_geom - // key and the other does not - // OR - // one of the old or new map has the geom key and the other - // does not - // OR - // both have the geom key but the geom value is different - if((oldMap.count(skip_geom_key) != newMap.count(skip_geom_key)) - || (oldMap.count(geom_key) != newMap.count(geom_key)) - || ((oldMap.count(geom_key) && newMap.count(geom_key)) - && oldMap.find(geom_key)->second != newMap.find(geom_key)->second)) - { - m_KeywordListUpToDate = false; - } + m_KeywordListUpToDate = false; } } - else - { - this->m_FileName = simpleFileName; - m_KeywordListUpToDate = false; - this->Modified(); - } - - m_FilenameHelper = helper; } + else + { + this->m_FileName = simpleFileName; + m_KeywordListUpToDate = false; + this->Modified(); + } + + m_FilenameHelper = helper; } template <class TOutputImage, class ConvertPixelTraits> diff --git a/Modules/IO/ImageIO/include/otbImageFileWriter.h b/Modules/IO/ImageIO/include/otbImageFileWriter.h index f59c57075f..8026aa6557 100644 --- a/Modules/IO/ImageIO/include/otbImageFileWriter.h +++ b/Modules/IO/ImageIO/include/otbImageFileWriter.h @@ -174,7 +174,7 @@ public: /** ImageFileWriter Methods */ virtual void SetFileName(const char* extendedFileName); - virtual void SetFileName(std::string extendedFileName); + virtual void SetFileName(const std::string& extendedFileName); virtual const char* GetFileName () const; /** Specify the region to write. If left NULL, then the whole image diff --git a/Modules/IO/ImageIO/include/otbImageFileWriter.hxx b/Modules/IO/ImageIO/include/otbImageFileWriter.hxx index d10dddeb77..3e24e8a260 100644 --- a/Modules/IO/ImageIO/include/otbImageFileWriter.hxx +++ b/Modules/IO/ImageIO/include/otbImageFileWriter.hxx @@ -832,9 +832,12 @@ ImageFileWriter<TInputImage> template <class TInputImage> void ImageFileWriter<TInputImage> -::SetFileName(std::string extendedFileName) +::SetFileName(const std::string& extendedFileName) { - this->SetFileName(extendedFileName.c_str()); + this->m_FilenameHelper->SetExtendedFileName(extendedFileName); + m_FileName = this->m_FilenameHelper->GetSimpleFileName(); + m_ImageIO = nullptr; + this->Modified(); } template <class TInputImage> @@ -842,10 +845,10 @@ void ImageFileWriter<TInputImage> ::SetFileName(const char* extendedFileName) { - this->m_FilenameHelper->SetExtendedFileName(extendedFileName); - m_FileName = this->m_FilenameHelper->GetSimpleFileName(); - m_ImageIO = nullptr; - this->Modified(); + if (extendedFileName) + { + this->SetFileName(std::string(extendedFileName)); + } } template <class TInputImage> diff --git a/Modules/MPI/MPITiffWriter/include/otbSimpleParallelTiffWriter.h b/Modules/MPI/MPITiffWriter/include/otbSimpleParallelTiffWriter.h index d68643c8b8..be6d73b14d 100644 --- a/Modules/MPI/MPITiffWriter/include/otbSimpleParallelTiffWriter.h +++ b/Modules/MPI/MPITiffWriter/include/otbSimpleParallelTiffWriter.h @@ -220,7 +220,7 @@ public: /** SimpleParallelTiffWriter Methods */ virtual void SetFileName(const char* extendedFileName); - virtual void SetFileName(std::string extendedFileName); + virtual void SetFileName(const std::string& extendedFileName); virtual const char* GetFileName () const; /** Specify the region to write. If left NULL, then the whole image diff --git a/Modules/MPI/MPITiffWriter/include/otbSimpleParallelTiffWriter.hxx b/Modules/MPI/MPITiffWriter/include/otbSimpleParallelTiffWriter.hxx index 1c6aa5033f..2254c12200 100644 --- a/Modules/MPI/MPITiffWriter/include/otbSimpleParallelTiffWriter.hxx +++ b/Modules/MPI/MPITiffWriter/include/otbSimpleParallelTiffWriter.hxx @@ -824,21 +824,24 @@ SimpleParallelTiffWriter<TInputImage> template <class TInputImage> void SimpleParallelTiffWriter<TInputImage> -::SetFileName(std::string extendedFileName) - { - this->SetFileName(extendedFileName.c_str()); - } +::SetFileName(const std::string& extendedFileName) +{ + this->m_FilenameHelper->SetExtendedFileName(extendedFileName); + m_FileName = this->m_FilenameHelper->GetSimpleFileName(); + m_ImageIO = NULL; + this->Modified(); +} template <class TInputImage> void SimpleParallelTiffWriter<TInputImage> ::SetFileName(const char* extendedFileName) - { - this->m_FilenameHelper->SetExtendedFileName(extendedFileName); - m_FileName = this->m_FilenameHelper->GetSimpleFileName(); - m_ImageIO = NULL; - this->Modified(); - } +{ + if (extendedFileName) + { + this->SetFileName(std::string(extendedFileName)); + } +} template <class TInputImage> const char* diff --git a/Modules/MPI/MPIVrtWriter/include/otbMPIVrtWriter.h b/Modules/MPI/MPIVrtWriter/include/otbMPIVrtWriter.h index c6126e924f..433dbf33a2 100644 --- a/Modules/MPI/MPIVrtWriter/include/otbMPIVrtWriter.h +++ b/Modules/MPI/MPIVrtWriter/include/otbMPIVrtWriter.h @@ -82,7 +82,7 @@ public: /** SimpleParallelTiffWriter Methods */ virtual void SetFileName(const char* extendedFileName); - virtual void SetFileName(std::string extendedFileName); + virtual void SetFileName(const std::string& extendedFileName); virtual const char* GetFileName () const; /** Specify the region to write. If left NULL, then the whole image diff --git a/Modules/MPI/MPIVrtWriter/include/otbMPIVrtWriter.hxx b/Modules/MPI/MPIVrtWriter/include/otbMPIVrtWriter.hxx index 33e8253c0a..ee02d55ed6 100644 --- a/Modules/MPI/MPIVrtWriter/include/otbMPIVrtWriter.hxx +++ b/Modules/MPI/MPIVrtWriter/include/otbMPIVrtWriter.hxx @@ -63,18 +63,21 @@ template <typename TImage> void MPIVrtWriter<TImage>::SetFileName(const char* extendedFileName) { - if (m_Filename.compare(extendedFileName) != 0 ) + if (extendedFileName) { - m_Filename = std::string(extendedFileName); - this->Modified(); + this->SetFileName(std::string(extendedFileName)); } } template <typename TImage> void -MPIVrtWriter<TImage>::SetFileName(std::string extendedFileName) +MPIVrtWriter<TImage>::SetFileName(const std::string& extendedFileName) { - this->SetFileName(extendedFileName.c_str()); + if (m_Filename.compare(extendedFileName) != 0 ) + { + m_Filename = extendedFileName; + this->Modified(); + } } template <typename TImage> -- GitLab