Commit fdd50297 authored by Antoine Regimbeau's avatar Antoine Regimbeau

ENH: change map to unordered_map and add layer option manipulation function

parent 1eabd31e
......@@ -21,7 +21,7 @@
#ifndef otbOGRExtendedFilenameToOptions_h
#define otbOGRExtendedFilenameToOptions_h
#include <set>
#include <unordered_map>
#include "otbExtendedFilenameHelper.h"
namespace otb
......@@ -51,21 +51,20 @@ public:
struct OpenOptionType
{
std::pair< bool, std::string > simpleFileName;
std::pair< bool, GDALOptionType > gdalOptions;
std::map< std::string , bool > availableOptions;
GDALOptionType gdalOptions;
// std::unordered_map< std::string , bool > availableOptions;
};
struct CreationOptionType
{
std::pair< bool, std::string > simpleFileName;
std::pair< bool, GDALOptionType > gdalOptions;
std::map< std::string , bool > availableOptions;
GDALOptionType gdalOptions;
// std::unordered_map< std::string , bool > availableOptions;
};
struct LayerOptionType
{
std::pair< bool, GDALOptionType > gdalOptions;
std::map< std::string , bool > availableOptions;
std::unordered_map< std::string , std::string > gdalOptions;
};
/* Set Methods */
......@@ -77,6 +76,9 @@ public:
GDALOptionType GetGDALCreationOptions() const ;
GDALOptionType GetGDALLayerOptions() const ;
void SetGDALLayerOptions( const GDALOptionType & options );
void AddGDALLayerOptions( const GDALOptionType & options );
protected:
......
......@@ -59,18 +59,15 @@ SetExtendedFileName(const char *extFname)
{
if ( tmp[1]=="oo" )
{
m_OpenOptions.gdalOptions.first = true;
m_OpenOptions.gdalOptions.second.push_back(tmp[2] + "=" +it->second);
m_OpenOptions.gdalOptions.push_back(tmp[2] + "=" +it->second);
}
else if ( tmp[1]=="co" )
{
m_CreationOptions.gdalOptions.first = true;
m_CreationOptions.gdalOptions.second.push_back(tmp[2] + "=" +it->second);
m_CreationOptions.gdalOptions.push_back(tmp[2] + "=" +it->second);
}
else if ( tmp[1]=="lco" )
{
m_LayerOptions.gdalOptions.first = true;
m_LayerOptions.gdalOptions.second.push_back(tmp[2] + "=" +it->second);
m_LayerOptions.gdalOptions[tmp[2]] = it->second;
}
else
{
......@@ -87,11 +84,11 @@ OGRExtendedFilenameToOptions::
GetGDALOptions( const std::string & type ) const
{
if ( type == "layer" )
return m_LayerOptions.gdalOptions.second;
return GetGDALLayerOptions();
else if ( type == "creation" )
return m_CreationOptions.gdalOptions.second;
return m_CreationOptions.gdalOptions;
else if ( type == "open" )
return m_OpenOptions.gdalOptions.second;
return m_OpenOptions.gdalOptions;
else
{
// warn user : wrong option
......@@ -99,8 +96,42 @@ GetGDALOptions( const std::string & type ) const
}
}
OGRExtendedFilenameToOptions::
GDALOptionType
OGRExtendedFilenameToOptions::
GetGDALLayerOptions() const
{
GDALOptionType options;
for (const auto & option : m_LayerOptions.gdalOptions )
{
options.push_back( option.first + "=" + option.second );
}
return options;
}
void
OGRExtendedFilenameToOptions::
SetGDALLayerOptions( const OGRExtendedFilenameToOptions::GDALOptionType & options )
{
std::vector<std::string> tmp;
for ( const auto & option : options )
{
boost::split(tmp, option , boost::is_any_of(":"), boost::token_compress_on);
m_LayerOptions.gdalOptions[ tmp[0] ] = tmp[1] ;
}
}
void
OGRExtendedFilenameToOptions::
AddGDALLayerOptions( const OGRExtendedFilenameToOptions::GDALOptionType & options )
{
std::vector<std::string> tmp;
for ( const auto & option : options )
{
boost::split(tmp, option , boost::is_any_of(":"), boost::token_compress_on);
m_LayerOptions.gdalOptions[ tmp[0] ] = tmp[1] ;
}
}
#define GetGDALOptionMacro( Type ) \
OGRExtendedFilenameToOptions:: \
......@@ -108,12 +139,12 @@ GDALOptionType \
OGRExtendedFilenameToOptions:: \
GetGDAL##Type##Options() const \
{ \
return m_##Type##Options.gdalOptions.second; \
return m_##Type##Options.gdalOptions; \
} \
GetGDALOptionMacro( Open )
GetGDALOptionMacro( Creation )
GetGDALOptionMacro( Layer )
// GetGDALOptionMacro( Layer )
......
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