I am trying to create a pipeline for my project. I freely rely on the VTK pipeline concept. However, there are significant differences.
In my design, mapping the type of I / O connection was done using variative patterns and recursive inheritance (similar to CRTP). This allows me to manually determine which segments can be associated with which segments, passing a list of abstract base classes to the base filter / mapper classes. This in itself does not cause any problems.
I need to be able to work with custom (not necessarily std/ primitive) data types. The VTK pipeline passes pointers to objects that come from one of the VTK ( vtkAlgorithmObject) classes through pipeline segments. This allows a fairly natural implementation of the pipeline I / O interface with multiple connections. That is where my problem is.
Implementation of VTK output port function:
vtkAlgorithmOutput* vtkAlgorithm::GetOutputPort (int index)
Unfortunately, I cannot return a custom class from the output port. Somehow, I need to have one (possibly overloaded) function getOutputPortthat will return another type based on a predefined index.
One way to do this is to use a combination of template arguments and overloading:
template<int N>
void getOutputPort(int& i)
{
if (N == 0)
i = 10;
else if (N == 2)
i = 20;
else
throw "Invalid template argument for the return type.";
}
template<int N>
void getOutputPort(string& str)
{
if (N == 1)
str = "qwerty";
else
throw "Invalid template argument for the return type.";
}
, , , , . std::unique_ptr. , .
, - ,
template<int N>
auto getOutputPort2()
{
if (N == 0)
return std::unique_ptr<int>(new int(10));
else if (N == 1)
return std::unique_ptr<string>(new string("qwerty"));
else if (N == 2)
return std::unique_ptr<int>(new int(20));
else
throw "Invalid template argument.";
}
" ". - ( auto)?
user1391279