Commit df787dfd authored by Victor Poughon's avatar Victor Poughon

REFAC: make std::string overload the main implementation

parent 5ed8e9f1
......@@ -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 ;
......
......@@ -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;
......
......@@ -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);
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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();
......
......@@ -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
......
......@@ -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 */
......
......@@ -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>
......
......@@ -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
......
......@@ -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>
......
......@@ -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
......
......@@ -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*
......
......@@ -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
......
......@@ -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>
......
Markdown is supported
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