I’m working on a multithreaded library which monitors network traffic from winpcap and transforms the packets into several different types of data structures for consumption by various applications.
for each type of output, there will be several transformations required, each transformation could be described as taking 0-N objects of type X, and then producing 0-N types of Y which will then be consumed by the next step in the process.
It’s important to note that in the transformation of X’s to Y’s. If we currently only have 5 (as an example) X’s, that may or may not be enough to create a Y, or it might be enough to create many Y’s, depending on the transformation and the data recieved.
To be consistant, we would obviously like to use a standard pattern for each transformation object. I’m hoping that someone could point out a commonly used pattern for something like this that hopefully relies on std (or boost) libraries.
Additionaly we have been discussing the possibility of using chains of inheritance to link the different layers together.
IE.
class ProcessXtoY: ProcessWtoX
{
void processData(iterator<X> begin, iterator<X> end)
{
/* create Y's, send output to */
}
virtual void processData(iterator<Y> begin, iterator<Y> end) = 0;
}
class ProcessYtoZ: ProcessXtoY
{
void processData(iterator<Y> begin, iterator<Y> end)
{
/* ... */
}
}
Can anyone suggest some examples of commonly used patterns for this type of project?
Using inheritance to link the transformations together is not what inheritance should be used for and pretty unflexible in adding new transformations. If you ever need new combinations of transformations (for example W directly to Y).
Instead, have you considered creating transformation class(es) that describe each transformation algorithm and then use std::transform and chain the transformations together?