Rework Problem::{check,print} into a recursive approach
Following dicussion of issue #289 (closed) @jsola raised the concern of reworking the way Problem::{check,print}
work. I reproduce his comment:
In fact, and since we are here, let me say that the functions print() and check() are horrible.
What we would need is a couple of viral functions print() and check() that:
- print the current node
- call print() on all child nodes
Moreover, each node's print would be virtual, so that derived classes can print more info / modified info , with respect to the base class.
A typical print()
function in a node Parent
, with children of type Child
, would be split into a header section and a viral section; The Header section can be derived and so it is virtual:
virtual ParentBase::printHeader()
{
// print relevant info of ParentBase
// ...
}
ParentBase::print()
{
printHeader();
for (const ChildBasePtr& child : child_list_)
{
child->print();
}
}
virtual ParentDerived::printHeader(options)
{
FooBase::printHeader(); // print base header
// print relevant info of ParentDerived
// ...
}
At this point, if all Nodes in wolf have these, we can call
problem->print(options);
and obtain the same behavior as now.