Successor
Added successor traits to a derived class.
The template adds the ability for a class to store a successor to itself which allows the 'Chain of Responsibility' design
pattern to be implemented in a consistent fashion.
etl::successor<typename T>
T The successor type
____________________________________________________________________________________________________
Member types
successor_type T
____________________________________________________________________________________________________
Constructor
successor()
Constructs a default successor.
has_successor() will return false.
successor(successor_type& s)
Constructs a successor from the supplied parameter s.
has_successor() will return true.
____________________________________________________________________________________________________
Member functions
void set_successor(successor_type& s)
Sets the successor to s.
has_successor() will return true.
successor_type& get_successor() const
Gets a reference to the successor.
Undefined behaviour if a successor has not been set.
bool has_successor() const
Returns true if a successor has been set.
____________________________________________________________________________________________________
Example
class Processor : public etl::successor<Processor>
{
public:
bool Process(const Data& data)
{
bool handled = CheckData(data);
if (handled == false)
{
if (has_successor())
{
return get_successor().Process(data);
}
}
return handled;
}
bool CheckData(const Data& data)
{
bool did_we_handle_it = false;
return did_we_handle_it;
}
};
Processor processor1;
Processor processor2;
proccessor1.set_successor(processor2);