Skip to content
Snippets Groups Projects
Commit 7a41f23f authored by Cyrille Valladeau's avatar Cyrille Valladeau
Browse files

ADD: add WrapperParameterKey

parent 824a1b82
Branches
Tags
No related merge requests found
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#include "otbWrapperOutputVectorDataParameter.h" #include "otbWrapperOutputVectorDataParameter.h"
#include "otbWrapperRadiusParameter.h" #include "otbWrapperRadiusParameter.h"
#include "otbWrapperStringParameter.h" #include "otbWrapperStringParameter.h"
#include "otbWrapperParameterKey.h"
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
namespace otb namespace otb
...@@ -84,88 +86,61 @@ ParameterGroup::GetParametersKeys(bool recursive) ...@@ -84,88 +86,61 @@ ParameterGroup::GetParametersKeys(bool recursive)
void void
ParameterGroup::AddChoice(std::string paramKey, std::string paramName) ParameterGroup::AddChoice(std::string paramKey, std::string paramName)
{ {
ParameterKey pKey( paramKey );
// Split the parameter name // Split the parameter name
std::vector<std::string> splittedKey; std::vector<std::string> splittedKey = pKey.Split();
boost::algorithm::split(splittedKey, paramKey, boost::is_any_of("."), boost::token_compress_on);
// Get the last subkey
std::string lastkey = *splittedKey.rbegin();
Parameter::Pointer parentParam;
std::string parentkey;
// Get the immediate parent of paramKey if( splittedKey.size() >1 )
if (splittedKey.size() > 1)
{ {
// Remove the last subkey // Get the last subkey
std::ostringstream parentOss; std::string lastkey = pKey.GetLastElement();
std::vector<std::string>::const_iterator it = splittedKey.begin();
while(it != splittedKey.end() - 1) std::string parentkey = pKey.GetRoot();
{ Parameter::Pointer parentParam = GetParameterByKey(parentkey);
parentOss << *it;
++it; // parentParam must be a choice or this is an error
if (it != splittedKey.end() - 1) ChoiceParameter* parentAsChoice = dynamic_cast<ChoiceParameter*>(parentParam.GetPointer());
if (parentAsChoice)
{ {
parentOss << "."; parentAsChoice->AddChoice(lastkey, paramName);
}
else
{
itkExceptionMacro(<<parentkey << " is not a choice");
} }
}
parentkey = parentOss.str();
parentParam = GetParameterByKey(parentkey);
// parentParam must be a choice or this is an error
ChoiceParameter* parentAsChoice = dynamic_cast<ChoiceParameter*>(parentParam.GetPointer());
if (parentAsChoice)
{
parentAsChoice->AddChoice(lastkey, paramName);
}
else
{
itkExceptionMacro(<<parentkey << " is not a choice");
}
} }
else else
{ {
itkExceptionMacro(<<"No choice parameter key given"); itkExceptionMacro(<<"No choice parameter key given");
} }
} }
/** Add a new parameter to the parameter group */ /** Add a new parameter to the parameter group */
void void
ParameterGroup::AddParameter(ParameterType type, std::string paramKey, std::string paramName) ParameterGroup::AddParameter(ParameterType type, std::string paramKey, std::string paramName)
{ {
ParameterKey pKey( paramKey );
// Split the parameter name // Split the parameter name
std::vector<std::string> splittedKey; std::vector<std::string> splittedKey = pKey.Split();
boost::algorithm::split(splittedKey, paramKey, boost::is_any_of("."), boost::token_compress_on);
// Get the last subkey // Get the last subkey
std::string lastkey = *splittedKey.rbegin(); std::string lastkey = pKey.GetLastElement();
Parameter::Pointer parentParam;
std::string parentkey; std::string parentkey;
Parameter::Pointer parentParam;
// Get the immediate parent of paramKey
if (splittedKey.size() > 1) if (splittedKey.size() > 1)
{ {
// Remove the last subkey parentkey = pKey.GetRoot();
std::ostringstream parentOss; parentParam = GetParameterByKey(parentkey);
std::vector<std::string>::const_iterator it = splittedKey.begin();
while(it != splittedKey.end() - 1)
{
parentOss << *it;
++it;
if (it != splittedKey.end() - 1)
{
parentOss << ".";
}
}
parentkey = parentOss.str();
parentParam = GetParameterByKey(parentkey);
} }
else else
{ {
parentParam = this; parentParam = this;
} }
ParameterGroup* parentAsGroup = dynamic_cast<ParameterGroup*>(parentParam.GetPointer()); ParameterGroup* parentAsGroup = dynamic_cast<ParameterGroup*>(parentParam.GetPointer());
if (parentAsGroup) if (parentAsGroup)
...@@ -275,12 +250,12 @@ ParameterGroup::GetParameterByIndex(unsigned int i) ...@@ -275,12 +250,12 @@ ParameterGroup::GetParameterByIndex(unsigned int i)
Parameter::Pointer Parameter::Pointer
ParameterGroup::GetParameterByKey(std::string name) ParameterGroup::GetParameterByKey(std::string name)
{ {
// Split the parameter name ParameterKey pName(name);
std::vector<std::string> splittedName; // Split the parameter name
boost::algorithm::split(splittedName, name, boost::is_any_of("."), boost::token_compress_on); std::vector<std::string> splittedName = pName.Split();
// Get the first parameter key // Get the first parameter key
std::string parentName = splittedName[0]; std::string parentName = pName.GetFirstElement();
// Look for parentName in the current group // Look for parentName in the current group
Parameter::Pointer parentParam; Parameter::Pointer parentParam;
...@@ -362,6 +337,7 @@ ParameterGroup::GetParameterByKey(std::string name) ...@@ -362,6 +337,7 @@ ParameterGroup::GetParameterByKey(std::string name)
// Neither ParameterGroup, neither ChoiceParameter // Neither ParameterGroup, neither ChoiceParameter
itkExceptionMacro(<< "No parameter with key " << name); itkExceptionMacro(<< "No parameter with key " << name);
} }
return parentParam.GetPointer(); return parentParam.GetPointer();
} }
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
PURPOSE. See the above copyright notices for more information. PURPOSE. See the above copyright notices for more information.
=========================================================================*/ =========================================================================*/
#include "otbParameterKey.h" #include "otbWrapperParameterKey.h"
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
...@@ -65,7 +65,7 @@ std::vector<std::string> ...@@ -65,7 +65,7 @@ std::vector<std::string>
ParameterKey::Split() ParameterKey::Split()
{ {
std::vector<std::string> res; std::vector<std::string> res;
boost::split(res,m_Key,boost::is_any_of(".")); boost::split(res,m_Key,boost::is_any_of("."), boost::token_compress_on);
return res; return res;
} }
......
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
PURPOSE. See the above copyright notices for more information. PURPOSE. See the above copyright notices for more information.
=========================================================================*/ =========================================================================*/
#ifndef __otbParameterKey_h #ifndef __otbWrapperParameterKey_h
#define __otbParameterKey_h #define __otbWrapperParameterKey_h
#include <string> #include <string>
#include "otbMacro.h" #include "otbMacro.h"
...@@ -81,19 +81,21 @@ last() : return "tata" ...@@ -81,19 +81,21 @@ last() : return "tata"
/** Set Key value */ /** Set Key value */
void SetKey( const std::string & val ) void SetKey( const std::string & val )
{ {
/*
if( val.substr(1) == "." || if( val.substr(1) == "." ||
val.substr(val.size()-2, val.size()-1) == ".") val.substr(val.size()-2, val.size()-1) == ".")
{ {
itkGenericExceptionMacro( "invalid key. Can't start or begin with a \".\"."); itkGenericExceptionMacro( "invalid key. Can't start or begin with a \".\".");
} }
*/
m_Key = val; m_Key = val;
/*
if( this->Split().size() != 3 ) if( this->Split().size() != 3 )
{ {
m_Key = ""; m_Key = "";
itkGenericExceptionMacro( "Invalid key. Must follow the format \"string1.string2.string3\"."); itkGenericExceptionMacro( "Invalid key. Must follow the format \"string1.string2.string3\".");
} }
*/
} }
private: private:
...@@ -107,4 +109,4 @@ private: ...@@ -107,4 +109,4 @@ private:
} // end namespace Wrapper } // end namespace Wrapper
} //end namespace otb } //end namespace otb
#endif // __otbParameterKey_h_ #endif // __otbWrapperParameterKey_h_
...@@ -61,7 +61,7 @@ add_test(owTvApplicationRegistry ${OTB_WRAPPER_TESTS} ...@@ -61,7 +61,7 @@ add_test(owTvApplicationRegistry ${OTB_WRAPPER_TESTS}
# ParameterKey class test # ParameterKey class test
add_test(owTvParameterKey ${OTB_WRAPPER_TESTS} add_test(owTvParameterKey ${OTB_WRAPPER_TESTS}
otbParameterKey otbWrapperParameterKey
) )
# ----------------Source files CXX ----------------------------------- # ----------------Source files CXX -----------------------------------
...@@ -79,7 +79,7 @@ otbWrapperOutputImageParameterTest.cxx ...@@ -79,7 +79,7 @@ otbWrapperOutputImageParameterTest.cxx
otbWrapperParameterListTest.cxx otbWrapperParameterListTest.cxx
otbWrapperParameterTest.cxx otbWrapperParameterTest.cxx
otbWrapperApplicationRegistryTest.cxx otbWrapperApplicationRegistryTest.cxx
otbParameterKeyTest.cxx otbWrapperParameterKeyTest.cxx
) )
include_directories(${CMAKE_SOURCE_DIR}/Code/Core) include_directories(${CMAKE_SOURCE_DIR}/Code/Core)
......
...@@ -49,5 +49,5 @@ void RegisterTests() ...@@ -49,5 +49,5 @@ void RegisterTests()
REGISTER_TEST(otbWrapperApplicationRegistry); REGISTER_TEST(otbWrapperApplicationRegistry);
REGISTER_TEST(otbParameterKey); REGISTER_TEST(otbWrapperParameterKey);
} }
...@@ -19,9 +19,9 @@ ...@@ -19,9 +19,9 @@
#pragma warning ( disable : 4786 ) #pragma warning ( disable : 4786 )
#endif #endif
#include "otbParameterKey.h" #include "otbWrapperParameterKey.h"
int otbParameterKey(int argc, char* argv[]) int otbWrapperParameterKey(int argc, char* argv[])
{ {
std::string theKey = "parent.current.child"; std::string theKey = "parent.current.child";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment