cleanup operator<<(ostream, *)

- basic implementation for StagePrivate
- implementation for Stage calls this
- implementation for ContainerBase recursively calls this
- implementation for Task added
This commit is contained in:
Robert Haschke 2018-02-17 21:01:05 +01:00
parent 1f4264c8c8
commit a4feb705d0
7 changed files with 34 additions and 23 deletions

View File

@ -76,6 +76,7 @@ public:
protected:
ContainerBase(ContainerBasePrivate* impl);
};
std::ostream& operator<<(std::ostream& os, const ContainerBase& stage);
class SerialContainerPrivate;

View File

@ -112,8 +112,6 @@ std::ostream& operator<<(std::ostream &os, const InitStageException& e);
class ContainerBase;
class StagePrivate;
class Stage {
friend std::ostream& operator<<(std::ostream &os, const Stage& stage);
public:
PRIVATE_CLASS(Stage)
typedef std::unique_ptr<Stage> pointer;
@ -299,5 +297,4 @@ public:
}
};
} }

View File

@ -139,4 +139,9 @@ private:
std::list<Task::TaskCallback> task_cbs_; // functions to monitor task's planning progress
};
inline std::ostream& operator<<(std::ostream& os, const Task& task) {
task.printState(os);
return os;
}
} }

View File

@ -225,6 +225,15 @@ void ContainerBase::init(const planning_scene::PlanningSceneConstPtr &scene)
throw errors;
}
std::ostream& operator<<(std::ostream& os, const ContainerBase& container) {
ContainerBase::StageCallback processor = [&os](const Stage& stage, int depth) -> bool {
os << std::string(2*depth, ' ') << *stage.pimpl() << std::endl;
return true;
};
container.traverseRecursively(processor);
return os;
}
struct SolutionCollector {
SolutionCollector(size_t max_depth) : max_depth(max_depth) {}

View File

@ -183,26 +183,25 @@ const char* direction(const StagePrivate& stage) {
return "<-";
}
std::ostream& operator<<(std::ostream &os, const Stage& stage) {
auto impl = stage.pimpl();
std::ostream& operator<<(std::ostream& os, const StagePrivate& impl) {
// starts
for (const InterfaceConstPtr& i : {impl->prevEnds(), impl->starts()}) {
for (const InterfaceConstPtr& i : {impl.prevEnds(), impl.starts()}) {
os << std::setw(3);
if (i) os << i->size();
else os << "-";
}
// trajectories
os << std::setw(5) << direction<READS_START, WRITES_PREV_END>(*impl)
<< std::setw(3) << stage.numSolutions()
<< std::setw(5) << direction<READS_END, WRITES_NEXT_START>(*impl);
os << std::setw(5) << direction<READS_START, WRITES_PREV_END>(impl)
<< std::setw(3) << impl.me()->numSolutions()
<< std::setw(5) << direction<READS_END, WRITES_NEXT_START>(impl);
// ends
for (const InterfaceConstPtr& i : {impl->ends(), impl->nextStarts()}) {
for (const InterfaceConstPtr& i : {impl.ends(), impl.nextStarts()}) {
os << std::setw(3);
if (i) os << i->size();
else os << "-";
}
// name
os << " / " << stage.name();
os << " / " << impl.name();
return os;
}
@ -550,4 +549,9 @@ void Connecting::connect(const InterfaceState& from, const InterfaceState& to,
impl->newSolution(trajectory);
}
std::ostream& operator<<(std::ostream& os, const Stage& stage) {
os << *stage.pimpl();
return os;
}
} }

View File

@ -286,13 +286,8 @@ std::string Task::id() const
return id_;
}
void Task::printState(std::ostream& os) const
{
ContainerBase::StageCallback processor = [&os](const Stage& stage, int depth) -> bool {
os << std::string(2*depth, ' ') << stage << std::endl;
return true;
};
stages()->traverseRecursively(processor);
void Task::printState(std::ostream& os) const {
os << *stages();
}
} }