I have a class template DataProcessor
, which looks like this:
struct DataProcessorBase
{
typedef std::shared_ptr<DataProcessorBase> Ptr;
}; // struct DataProcessorBase
template <class _Input, class _Output>
struct DataProcessor : DataProcessorBase
{
typedef _Input Input;
typedef _Output Output;
virtual Output process(const Input * input) = 0;
}; // struct DataProcessor
I am looking to create a Pipeline class, which concatenates multiple DataProcessor
instances together. This means that the Output of processor 1 must match the input of processor 2, and so forth. Something like the following:
template <class _Input, class _Output>
class Pipeline : DataProcessor<_Input, _Output>
{
public:
Output process(const Input * input);
private:
std::vector<DataProcessorBase::Ptr> _processors;
}; // class Pipeline
template <class _Input, class _Output>
_Output Pipeline<_Input, _Output>::process(const _Input * input)
{
// this is where I start guessing...
auto rawPtr = dynamic_cast<DataProcessor<_Input, TYPEOFFIRSTPROCESSORSOUTPUT>*>(_processors[0]);
assert(rawPtr);
for (size_t i = 0; i < _processors.size(); ++i)
{
...
}
}
I can tell that this way of implementing Pipeline::process is not the right way. Can someone point me in the right direction?