Casting between mitk::BaseData and derived classes is usually straight forward by converting to a pointer and using a dynamic_cast. But this solution is not readilly available in the wrapping scenario.
I wrote a (very) basic ConvertTo<T>(BaseData::Pointer) that casts the input BaseData object to a Smartpointer of the type T. Right now I implmented a very basic version, without any tpye checking. And I implemented this version within the files used for the wrapping, e.g. it cannot be used within the "traditional" MITK.
The question is: Do we want such a function within the general mitk code (perhaps even the core?)
My thoughs so far:
- I will need this function within the wrapping, so we will have it at some place in the code. It might be beneficial to have it accessible for a wider range of people.
- There is no absolute hard need to have such a method, it won't add any new functionality.
- If this function is added to the core, i would suggest to extend it.
- An error instead of an Null-Pointer is returned if the casting fails
- Template over two parameters, the last one could define the input. Using template parameter deduction, a fast covnersion from any BaseData-Derived type to any other type would be possible.
- An advantage of such a solution could be code that is easier to read and more fail-safe:
- Avoid calling .GetPointer(),
- no need to define the "dynamic_cast<Class *> construct,
- No NULL-Pointers but exceptions.
What are your thoughts on this?