Refactor application parameters dynamic_cast pattern
All threads resolved!
All threads resolved!
Compare changes
@@ -160,7 +160,6 @@ private:
Refactor otbWrapperApplication.cxx
and application parameter's:
GetTypes/ToInt/FromInt/ToString/FromString/etc
virtual methods in Parameter to replace dynamic_castsNumericalParameter
& its test
boost::optional
instead of boost::any
.cxx
fileFix 5 bugs:
StringList
usage in DSFuzzyModelEstimationSetDefaultParameterFloat
in SARPolarSynthSetParameterFloat
in Bug804.pyHeavy usage of dynamic_cast
is an anti-pattern. Using virtual functions is more idiomatic and much less error prone. The code is simpler to read and easier to maintain. Using this refactoring I found 5 bugs that were silent before (because there was no error checking).
Related to #1531 (closed), #1842 (closed)
The key idea is that the base class Parameter
defines virtual functions for type conversion with a default implementation that raises an exception. Derived classes can override this implementation if they are able to provide the conversion.
An important point is that parameter type conversion and error checking is now much more strict. For example SetParameterFloat
on a parameter of type ParameterType_Int
will now result in a runtime error:
itk::ERROR: Cannot convert parameter 'sizex' of type Int to/from type Float
TODO in future MR:
otbWrapperParameter.h
)The copyright owner is CNES and has signed the ORFEO ToolBox Contributor License Agreement.
Check before merging: