Commit ca470c1e authored by Guillaume Pasero's avatar Guillaume Pasero

ENH: use a namespace instead of static functions

parent c1384e44
......@@ -33,99 +33,96 @@ namespace Wrapper
{
/**
* \class MetaDataHelper
* \namespace MetaDataHelper
*
* \brief Small helper to manipulate itk::MetaDataDictionary
* \brief Contains small helper functions to manipulate itk::MetaDataDictionary
*
* These functions are only here to instanciate the different template function that
* allow to get/set values in MetaDataDictionary.
*
* This class is only here to instanciate the different template function that
* allow to get/set values in MetaDataDictionary. All functions are static.
*
* \ingroup OTBApplicationEngine
*/
class OTBApplicationEngine_EXPORT MetaDataHelper
namespace MetaDataHelper
{
public:
MetaDataHelper();
virtual ~MetaDataHelper();
typedef enum
enum class MDType
{
MDType_STRING,
MDType_INT,
MDType_DOUBLE,
MDType_GCP,
MDType_VECTOR,
MDType_IMAGEKWL,
MDType_VECTORDATAKWL,
MDType_BOOLVECTOR
} MDType;
static MDType GetType(const std::string &val);
static std::string GetString(
String,
Int,
Double,
GCP,
Vector,
ImageKWL,
VectorDataKWL,
BoolVector
};
OTBApplicationEngine_EXPORT MDType GetType(const std::string &val);
OTBApplicationEngine_EXPORT std::string GetString(
const itk::MetaDataDictionary &dict,
const std::string &key);
static void SetString(
OTBApplicationEngine_EXPORT void SetString(
itk::MetaDataDictionary &dict,
const std::string &key,
const std::string &val);
static unsigned int GetInt(
OTBApplicationEngine_EXPORT unsigned int GetInt(
const itk::MetaDataDictionary &dict,
const std::string &key);
static void SetInt(
OTBApplicationEngine_EXPORT void SetInt(
itk::MetaDataDictionary &dict,
const std::string &key,
unsigned int val);
static double GetDouble(
OTBApplicationEngine_EXPORT double GetDouble(
const itk::MetaDataDictionary &dict,
const std::string &key);
static void SetDouble(
OTBApplicationEngine_EXPORT void SetDouble(
itk::MetaDataDictionary &dict,
const std::string &key,
double val);
static otb::OTB_GCP GetGCP(
OTBApplicationEngine_EXPORT otb::OTB_GCP GetGCP(
const itk::MetaDataDictionary &dict,
const std::string &key);
static void SetGCP(
OTBApplicationEngine_EXPORT void SetGCP(
itk::MetaDataDictionary &dict,
const std::string &key,
const otb::OTB_GCP &val);
static otb::MetaDataKey::VectorType GetVector(
OTBApplicationEngine_EXPORT otb::MetaDataKey::VectorType GetVector(
const itk::MetaDataDictionary &dict,
const std::string &key);
static void SetVector(
OTBApplicationEngine_EXPORT void SetVector(
itk::MetaDataDictionary &dict,
const std::string &key,
const otb::MetaDataKey::VectorType &val);
static otb::ImageKeywordlist GetImageKWL(
OTBApplicationEngine_EXPORT otb::ImageKeywordlist GetImageKWL(
const itk::MetaDataDictionary &dict,
const std::string &key);
static void SetImageKWL(
OTBApplicationEngine_EXPORT void SetImageKWL(
itk::MetaDataDictionary &dict,
const std::string &key,
const otb::ImageKeywordlist &val);
static otb::VectorDataKeywordlist GetVectorDataKWL(
OTBApplicationEngine_EXPORT otb::VectorDataKeywordlist GetVectorDataKWL(
const itk::MetaDataDictionary &dict,
const std::string &key);
static void SetVectorDataKWL(
OTBApplicationEngine_EXPORT void SetVectorDataKWL(
itk::MetaDataDictionary &dict,
const std::string &key,
const otb::VectorDataKeywordlist &val);
static otb::MetaDataKey::BoolVectorType GetBoolVector(
OTBApplicationEngine_EXPORT otb::MetaDataKey::BoolVectorType GetBoolVector(
const itk::MetaDataDictionary &dict,
const std::string &key);
static void SetBoolVector(
OTBApplicationEngine_EXPORT void SetBoolVector(
itk::MetaDataDictionary &dict,
const std::string &key,
const otb::MetaDataKey::BoolVectorType &val);
};
} // end of namespace MetaDataHelper
} // end of namespace Wrapper
} // end of namespace otb
......
......@@ -25,45 +25,38 @@ namespace otb
{
namespace Wrapper
{
MetaDataHelper::MetaDataHelper()
namespace MetaDataHelper
{
}
MetaDataHelper::~MetaDataHelper()
{
}
MetaDataHelper::MDType
MetaDataHelper::GetType(const std::string &val)
MDType GetType(const std::string &val)
{
MDType ret;
otb::MetaDataKey::KeyType kt = otb::MetaDataKey::GetKeyType(val);
switch (kt)
{
case otb::MetaDataKey::TSTRING:
ret = MDType_STRING;
ret = MDType::String;
break;
case otb::MetaDataKey::TENTIER:
ret = MDType_INT;
ret = MDType::Int;
break;
case otb::MetaDataKey::TDOUBLE:
ret = MDType_DOUBLE;
ret = MDType::Double;
break;
case otb::MetaDataKey::TOTB_GCP:
ret = MDType_GCP;
ret = MDType::GCP;
break;
case otb::MetaDataKey::TVECTOR:
ret = MDType_VECTOR;
ret = MDType::Vector;
break;
case otb::MetaDataKey::TOSSIMKEYWORDLIST:
ret = MDType_IMAGEKWL;
ret = MDType::ImageKWL;
break;
case otb::MetaDataKey::TVECTORDATAKEYWORDLIST:
ret = MDType_VECTORDATAKWL;
ret = MDType::VectorDataKWL;
break;
case otb::MetaDataKey::TBOOLVECTOR:
ret = MDType_BOOLVECTOR;
ret = MDType::BoolVector;
break;
default:
break;
......@@ -72,7 +65,7 @@ MetaDataHelper::GetType(const std::string &val)
}
std::string
MetaDataHelper::GetString(
GetString(
const itk::MetaDataDictionary &dict,
const std::string &key)
{
......@@ -82,7 +75,7 @@ MetaDataHelper::GetString(
}
void
MetaDataHelper::SetString(
SetString(
itk::MetaDataDictionary &dict,
const std::string &key,
const std::string &val)
......@@ -91,7 +84,7 @@ MetaDataHelper::SetString(
}
unsigned int
MetaDataHelper::GetInt(
GetInt(
const itk::MetaDataDictionary &dict,
const std::string &key)
{
......@@ -101,7 +94,7 @@ MetaDataHelper::GetInt(
}
void
MetaDataHelper::SetInt(
SetInt(
itk::MetaDataDictionary &dict,
const std::string &key,
unsigned int val)
......@@ -110,7 +103,7 @@ MetaDataHelper::SetInt(
}
double
MetaDataHelper::GetDouble(
GetDouble(
const itk::MetaDataDictionary &dict,
const std::string &key)
{
......@@ -120,7 +113,7 @@ MetaDataHelper::GetDouble(
}
void
MetaDataHelper::SetDouble(
SetDouble(
itk::MetaDataDictionary &dict,
const std::string &key,
double val)
......@@ -129,7 +122,7 @@ MetaDataHelper::SetDouble(
}
otb::OTB_GCP
MetaDataHelper::GetGCP(
GetGCP(
const itk::MetaDataDictionary &dict,
const std::string &key)
{
......@@ -139,7 +132,7 @@ MetaDataHelper::GetGCP(
}
void
MetaDataHelper::SetGCP(
SetGCP(
itk::MetaDataDictionary &dict,
const std::string &key,
const otb::OTB_GCP &val)
......@@ -148,7 +141,7 @@ MetaDataHelper::SetGCP(
}
otb::MetaDataKey::VectorType
MetaDataHelper::GetVector(
GetVector(
const itk::MetaDataDictionary &dict,
const std::string &key)
{
......@@ -158,7 +151,7 @@ MetaDataHelper::GetVector(
}
void
MetaDataHelper::SetVector(
SetVector(
itk::MetaDataDictionary &dict,
const std::string &key,
const otb::MetaDataKey::VectorType &val)
......@@ -167,7 +160,7 @@ MetaDataHelper::SetVector(
}
otb::ImageKeywordlist
MetaDataHelper::GetImageKWL(
GetImageKWL(
const itk::MetaDataDictionary &dict,
const std::string &key)
{
......@@ -177,7 +170,7 @@ MetaDataHelper::GetImageKWL(
}
void
MetaDataHelper::SetImageKWL(
SetImageKWL(
itk::MetaDataDictionary &dict,
const std::string &key,
const otb::ImageKeywordlist &val)
......@@ -186,7 +179,7 @@ MetaDataHelper::SetImageKWL(
}
otb::VectorDataKeywordlist
MetaDataHelper::GetVectorDataKWL(
GetVectorDataKWL(
const itk::MetaDataDictionary &dict,
const std::string &key)
{
......@@ -196,7 +189,7 @@ MetaDataHelper::GetVectorDataKWL(
}
void
MetaDataHelper::SetVectorDataKWL(
SetVectorDataKWL(
itk::MetaDataDictionary &dict,
const std::string &key,
const otb::VectorDataKeywordlist &val)
......@@ -205,7 +198,7 @@ MetaDataHelper::SetVectorDataKWL(
}
otb::MetaDataKey::BoolVectorType
MetaDataHelper::GetBoolVector(
GetBoolVector(
const itk::MetaDataDictionary &dict,
const std::string &key)
{
......@@ -215,7 +208,7 @@ MetaDataHelper::GetBoolVector(
}
void
MetaDataHelper::SetBoolVector(
SetBoolVector(
itk::MetaDataDictionary &dict,
const std::string &key,
const otb::MetaDataKey::BoolVectorType &val)
......@@ -223,5 +216,6 @@ MetaDataHelper::SetBoolVector(
itk::EncapsulateMetaData<otb::MetaDataKey::BoolVectorType>(dict, key, val);
}
} // end of namespace MetaDataHelper
} // end of namespace Wrapper
} // end of namespace otb
......@@ -908,130 +908,111 @@ public:
%include "PyCommand.i"
namespace otb
{
namespace Wrapper
{
class MetaDataHelper
%extend itkMetaDataDictionary
{
public:
MetaDataHelper();
virtual ~MetaDataHelper();
typedef enum
{
MDType_STRING,
MDType_INT,
MDType_DOUBLE,
MDType_GCP,
MDType_VECTOR,
MDType_IMAGEKWL,
MDType_VECTORDATAKWL,
MDType_BOOLVECTOR
} MDType;
static MDType GetType(const std::string &val);
static std::string GetString(
const itkMetaDataDictionary &dict,
const std::string &key);
static void SetString(
itkMetaDataDictionary &dict,
const std::string &key,
const std::string &val);
static unsigned int GetInt(
const itkMetaDataDictionary &dict,
const std::string &key);
static void SetInt(
itkMetaDataDictionary &dict,
const std::string &key,
unsigned int val);
static double GetDouble(
const itkMetaDataDictionary &dict,
const std::string &key);
static void SetDouble(
itkMetaDataDictionary &dict,
const std::string &key,
double val);
static OTB_GCP GetGCP(
const itkMetaDataDictionary &dict,
const std::string &key);
static void SetGCP(
itkMetaDataDictionary &dict,
const std::string &key,
const OTB_GCP &val);
static std::vector<double> GetVector(
const itkMetaDataDictionary &dict,
const std::string &key);
static void SetVector(
itkMetaDataDictionary &dict,
const std::string &key,
const std::vector<double> &val);
static ImageKeywordlist GetImageKWL(
const itkMetaDataDictionary &dict,
const std::string &key);
static void SetImageKWL(
itkMetaDataDictionary &dict,
const std::string &key,
const ImageKeywordlist &val);
static VectorDataKeywordlist GetVectorDataKWL(
const itkMetaDataDictionary &dict,
const std::string &key);
static void SetVectorDataKWL(
itkMetaDataDictionary &dict,
const std::string &key,
const VectorDataKeywordlist &val);
static std::vector<bool> GetBoolVector(
const itkMetaDataDictionary &dict,
const std::string &key);
static void SetBoolVector(
itkMetaDataDictionary &dict,
const std::string &key,
const std::vector<bool> &val);
};
int GetType(const std::string &key)
{
return (int) otb::Wrapper::MetaDataHelper::GetType(key);
}
} // end of namespace Wrapper
} // end of namespace otb
std::string GetString(const std::string &key)
{
return otb::Wrapper::MetaDataHelper::GetString(* $self,key);
}
void SetString(const std::string &key, const std::string &val)
{
otb::Wrapper::MetaDataHelper::SetString(* $self,key,val);
}
unsigned int GetInt(const std::string &key)
{
return otb::Wrapper::MetaDataHelper::GetInt(* $self,key);
}
void SetInt(const std::string &key, unsigned int val)
{
otb::Wrapper::MetaDataHelper::SetInt(* $self,key,val);
}
double GetDouble(const std::string &key)
{
return otb::Wrapper::MetaDataHelper::GetDouble(* $self,key);
}
void SetDouble(const std::string &key, double val)
{
otb::Wrapper::MetaDataHelper::SetDouble(* $self,key,val);
}
#if SWIGPYTHON
%pythoncode
{
MetaDataHelper.GetterMap = {
MetaDataHelper.MDType_STRING : MetaDataHelper.GetString,
MetaDataHelper.MDType_INT : MetaDataHelper.GetInt,
MetaDataHelper.MDType_DOUBLE : MetaDataHelper.GetDouble,
MetaDataHelper.MDType_GCP : MetaDataHelper.GetGCP,
MetaDataHelper.MDType_VECTOR : MetaDataHelper.GetVector,
MetaDataHelper.MDType_IMAGEKWL : MetaDataHelper.GetImageKWL,
MetaDataHelper.MDType_VECTORDATAKWL : MetaDataHelper.GetVectorDataKWL,
MetaDataHelper.MDType_BOOLVECTOR : MetaDataHelper.GetBoolVector,
}
otb::OTB_GCP GetGCP(const std::string &key)
{
return otb::Wrapper::MetaDataHelper::GetGCP(* $self,key);
}
void SetGCP(const std::string &key, const otb::OTB_GCP &val)
{
otb::Wrapper::MetaDataHelper::SetGCP(* $self,key,val);
}
MetaDataHelper.SetterMap = {
MetaDataHelper.MDType_STRING : MetaDataHelper.SetString,
MetaDataHelper.MDType_INT : MetaDataHelper.SetInt,
MetaDataHelper.MDType_DOUBLE : MetaDataHelper.SetDouble,
MetaDataHelper.MDType_GCP : MetaDataHelper.SetGCP,
MetaDataHelper.MDType_VECTOR : MetaDataHelper.SetVector,
MetaDataHelper.MDType_IMAGEKWL : MetaDataHelper.SetImageKWL,
MetaDataHelper.MDType_VECTORDATAKWL : MetaDataHelper.SetVectorDataKWL,
MetaDataHelper.MDType_BOOLVECTOR : MetaDataHelper.SetBoolVector,
}
}
std::vector<double> GetVector(const std::string &key)
{
return otb::Wrapper::MetaDataHelper::GetVector(* $self,key);
}
void SetVector(const std::string &key, const std::vector<double> &val)
{
otb::Wrapper::MetaDataHelper::SetVector(* $self,key,val);
}
otb::ImageKeywordlist GetImageKWL(const std::string &key)
{
return otb::Wrapper::MetaDataHelper::GetImageKWL(* $self,key);
}
void SetImageKWL(const std::string &key, const otb::ImageKeywordlist &val)
{
otb::Wrapper::MetaDataHelper::SetImageKWL(* $self,key,val);
}
otb::VectorDataKeywordlist GetVectorDataKWL(const std::string &key)
{
return otb::Wrapper::MetaDataHelper::GetVectorDataKWL(* $self,key);
}
void SetVectorDataKWL(const std::string &key, const otb::VectorDataKeywordlist &val)
{
otb::Wrapper::MetaDataHelper::SetVectorDataKWL(* $self,key,val);
}
std::vector<bool> GetBoolVector(const std::string &key)
{
return otb::Wrapper::MetaDataHelper::GetBoolVector(* $self,key);
}
void SetBoolVector(const std::string &key, const std::vector<bool> &val)
{
otb::Wrapper::MetaDataHelper::SetBoolVector(* $self,key,val);
}
#if SWIGPYTHON
// enhance the MetaDataDictionary class for Python
%extend itkMetaDataDictionary
{
%pythoncode
{
GetterMap = {
0 : GetString,
1 : GetInt,
2 : GetDouble,
3 : GetGCP,
4 : GetVector,
5 : GetImageKWL,
6 : GetVectorDataKWL,
7 : GetBoolVector,
}
SetterMap = {
0 : SetString,
1 : SetInt,
2 : SetDouble,
3 : SetGCP,
4 : SetVector,
5 : SetImageKWL,
6 : SetVectorDataKWL,
7 : SetBoolVector,
}
def __str__(self):
ret = ''
for k in self.GetKeys():
......@@ -1045,14 +1026,14 @@ MetaDataHelper.SetterMap = {
return self.GetKeys()
def __getitem__(self,key):
if key in self.GetKeys():
return MetaDataHelper.GetterMap[MetaDataHelper.GetType(key)](self,key)
return self.GetterMap[self.GetType(key)](self,key)
else:
raise IndexError('Key not recognized')
def __setitem__(self,key,val):
if key in self.GetKeys():
MetaDataHelper.SetterMap[MetaDataHelper.GetType(key)](self,key,val)
self.SetterMap[self.GetType(key)](self,key,val)
else:
raise IndexError('Key not recognized')
}
};
#endif
};
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