diff --git a/Code/Core/otbWrapperParameterGroup.cxx b/Code/Core/otbWrapperParameterGroup.cxx index 47bf4a81216cfdcf1335ee8681152c2fc9207e84..76d19e7cdb0464390569a296af4e3159bc352efa 100644 --- a/Code/Core/otbWrapperParameterGroup.cxx +++ b/Code/Core/otbWrapperParameterGroup.cxx @@ -28,6 +28,8 @@ #include "otbWrapperOutputVectorDataParameter.h" #include "otbWrapperRadiusParameter.h" #include "otbWrapperStringParameter.h" +#include "otbWrapperParameterKey.h" + #include <boost/algorithm/string.hpp> namespace otb @@ -84,88 +86,61 @@ ParameterGroup::GetParametersKeys(bool recursive) void ParameterGroup::AddChoice(std::string paramKey, std::string paramName) { + ParameterKey pKey( paramKey ); // Split the parameter name - std::vector<std::string> splittedKey; - 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; + std::vector<std::string> splittedKey = pKey.Split(); - // Get the immediate parent of paramKey - if (splittedKey.size() > 1) + if( splittedKey.size() >1 ) { - // Remove the last subkey - std::ostringstream parentOss; - std::vector<std::string>::const_iterator it = splittedKey.begin(); - while(it != splittedKey.end() - 1) - { - parentOss << *it; - ++it; - if (it != splittedKey.end() - 1) + // Get the last subkey + std::string lastkey = pKey.GetLastElement(); + + std::string parentkey = pKey.GetRoot(); + Parameter::Pointer parentParam = GetParameterByKey(parentkey); + + // parentParam must be a choice or this is an error + 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 { - itkExceptionMacro(<<"No choice parameter key given"); + itkExceptionMacro(<<"No choice parameter key given"); } } - - + + /** Add a new parameter to the parameter group */ void ParameterGroup::AddParameter(ParameterType type, std::string paramKey, std::string paramName) { + ParameterKey pKey( paramKey ); // Split the parameter name - std::vector<std::string> splittedKey; - boost::algorithm::split(splittedKey, paramKey, boost::is_any_of("."), boost::token_compress_on); - + std::vector<std::string> splittedKey = pKey.Split(); + // Get the last subkey - std::string lastkey = *splittedKey.rbegin(); - Parameter::Pointer parentParam; + std::string lastkey = pKey.GetLastElement(); + std::string parentkey; - - // Get the immediate parent of paramKey + Parameter::Pointer parentParam; + if (splittedKey.size() > 1) { - // Remove the last subkey - std::ostringstream parentOss; - 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); + parentkey = pKey.GetRoot(); + parentParam = GetParameterByKey(parentkey); } else { - parentParam = this; + parentParam = this; } + ParameterGroup* parentAsGroup = dynamic_cast<ParameterGroup*>(parentParam.GetPointer()); if (parentAsGroup) @@ -275,12 +250,12 @@ ParameterGroup::GetParameterByIndex(unsigned int i) Parameter::Pointer ParameterGroup::GetParameterByKey(std::string name) { - // Split the parameter name - std::vector<std::string> splittedName; - boost::algorithm::split(splittedName, name, boost::is_any_of("."), boost::token_compress_on); + ParameterKey pName(name); + // Split the parameter name + std::vector<std::string> splittedName = pName.Split(); // Get the first parameter key - std::string parentName = splittedName[0]; + std::string parentName = pName.GetFirstElement(); // Look for parentName in the current group Parameter::Pointer parentParam; @@ -362,6 +337,7 @@ ParameterGroup::GetParameterByKey(std::string name) // Neither ParameterGroup, neither ChoiceParameter itkExceptionMacro(<< "No parameter with key " << name); } + return parentParam.GetPointer(); } diff --git a/Code/Core/otbParameterKey.cxx b/Code/Core/otbWrapperParameterKey.cxx similarity index 93% rename from Code/Core/otbParameterKey.cxx rename to Code/Core/otbWrapperParameterKey.cxx index d1d2ed561b56ecc15193780cc2d86cce4a58f2e5..4c67028a359a4408e3f162d064b084a50666fba6 100644 --- a/Code/Core/otbParameterKey.cxx +++ b/Code/Core/otbWrapperParameterKey.cxx @@ -15,7 +15,7 @@ PURPOSE. See the above copyright notices for more information. =========================================================================*/ -#include "otbParameterKey.h" +#include "otbWrapperParameterKey.h" #include <boost/algorithm/string.hpp> @@ -65,7 +65,7 @@ std::vector<std::string> ParameterKey::Split() { 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; } diff --git a/Code/Core/otbParameterKey.h b/Code/Core/otbWrapperParameterKey.h similarity index 95% rename from Code/Core/otbParameterKey.h rename to Code/Core/otbWrapperParameterKey.h index 5535ae7050b38697fc7ed616ef7f9e3f3a027966..0d09ce7cf91909737cad21e02c6b88411d09bb3f 100644 --- a/Code/Core/otbParameterKey.h +++ b/Code/Core/otbWrapperParameterKey.h @@ -15,8 +15,8 @@ PURPOSE. See the above copyright notices for more information. =========================================================================*/ -#ifndef __otbParameterKey_h -#define __otbParameterKey_h +#ifndef __otbWrapperParameterKey_h +#define __otbWrapperParameterKey_h #include <string> #include "otbMacro.h" @@ -81,19 +81,21 @@ last() : return "tata" /** Set Key value */ void SetKey( const std::string & val ) { + /* if( val.substr(1) == "." || val.substr(val.size()-2, val.size()-1) == ".") { itkGenericExceptionMacro( "invalid key. Can't start or begin with a \".\"."); } - + */ m_Key = val; - + /* if( this->Split().size() != 3 ) { m_Key = ""; itkGenericExceptionMacro( "Invalid key. Must follow the format \"string1.string2.string3\"."); } + */ } private: @@ -107,4 +109,4 @@ private: } // end namespace Wrapper } //end namespace otb -#endif // __otbParameterKey_h_ +#endif // __otbWrapperParameterKey_h_ diff --git a/Testing/Core/CMakeLists.txt b/Testing/Core/CMakeLists.txt index bb918ca5c7c78688d792346c3be462d5b9be0107..e2303c84471e46e6d5ccfba480f98a6125191207 100644 --- a/Testing/Core/CMakeLists.txt +++ b/Testing/Core/CMakeLists.txt @@ -61,7 +61,7 @@ add_test(owTvApplicationRegistry ${OTB_WRAPPER_TESTS} # ParameterKey class test add_test(owTvParameterKey ${OTB_WRAPPER_TESTS} - otbParameterKey + otbWrapperParameterKey ) # ----------------Source files CXX ----------------------------------- @@ -79,7 +79,7 @@ otbWrapperOutputImageParameterTest.cxx otbWrapperParameterListTest.cxx otbWrapperParameterTest.cxx otbWrapperApplicationRegistryTest.cxx -otbParameterKeyTest.cxx +otbWrapperParameterKeyTest.cxx ) include_directories(${CMAKE_SOURCE_DIR}/Code/Core) diff --git a/Testing/Core/otbWrapperCoreTests.cxx b/Testing/Core/otbWrapperCoreTests.cxx index d95019eaed69fa6c284d141756f6e52d722b72ea..a2ac5be3d945a840dc57ee2d8fbc3114cc61f4d4 100644 --- a/Testing/Core/otbWrapperCoreTests.cxx +++ b/Testing/Core/otbWrapperCoreTests.cxx @@ -49,5 +49,5 @@ void RegisterTests() REGISTER_TEST(otbWrapperApplicationRegistry); - REGISTER_TEST(otbParameterKey); + REGISTER_TEST(otbWrapperParameterKey); } diff --git a/Testing/Core/otbParameterKeyTest.cxx b/Testing/Core/otbWrapperParameterKeyTest.cxx similarity index 96% rename from Testing/Core/otbParameterKeyTest.cxx rename to Testing/Core/otbWrapperParameterKeyTest.cxx index ab10c6d3e8b140c61a2983e3c310f7cb44a3755f..0913a8023d897ac6f25b8e5ce878153fb6922485 100644 --- a/Testing/Core/otbParameterKeyTest.cxx +++ b/Testing/Core/otbWrapperParameterKeyTest.cxx @@ -19,9 +19,9 @@ #pragma warning ( disable : 4786 ) #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";