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: protected:
ContainerBase(ContainerBasePrivate* impl); ContainerBase(ContainerBasePrivate* impl);
}; };
std::ostream& operator<<(std::ostream& os, const ContainerBase& stage);
class SerialContainerPrivate; class SerialContainerPrivate;

View File

@ -112,8 +112,6 @@ std::ostream& operator<<(std::ostream &os, const InitStageException& e);
class ContainerBase; class ContainerBase;
class StagePrivate; class StagePrivate;
class Stage { class Stage {
friend std::ostream& operator<<(std::ostream &os, const Stage& stage);
public: public:
PRIVATE_CLASS(Stage) PRIVATE_CLASS(Stage)
typedef std::unique_ptr<Stage> pointer; 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 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; 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 { struct SolutionCollector {
SolutionCollector(size_t max_depth) : max_depth(max_depth) {} SolutionCollector(size_t max_depth) : max_depth(max_depth) {}

View File

@ -183,26 +183,25 @@ const char* direction(const StagePrivate& stage) {
return "<-"; return "<-";
} }
std::ostream& operator<<(std::ostream &os, const Stage& stage) { std::ostream& operator<<(std::ostream& os, const StagePrivate& impl) {
auto impl = stage.pimpl();
// starts // starts
for (const InterfaceConstPtr& i : {impl->prevEnds(), impl->starts()}) { for (const InterfaceConstPtr& i : {impl.prevEnds(), impl.starts()}) {
os << std::setw(3); os << std::setw(3);
if (i) os << i->size(); if (i) os << i->size();
else os << "-"; else os << "-";
} }
// trajectories // trajectories
os << std::setw(5) << direction<READS_START, WRITES_PREV_END>(*impl) os << std::setw(5) << direction<READS_START, WRITES_PREV_END>(impl)
<< std::setw(3) << stage.numSolutions() << std::setw(3) << impl.me()->numSolutions()
<< std::setw(5) << direction<READS_END, WRITES_NEXT_START>(*impl); << std::setw(5) << direction<READS_END, WRITES_NEXT_START>(impl);
// ends // ends
for (const InterfaceConstPtr& i : {impl->ends(), impl->nextStarts()}) { for (const InterfaceConstPtr& i : {impl.ends(), impl.nextStarts()}) {
os << std::setw(3); os << std::setw(3);
if (i) os << i->size(); if (i) os << i->size();
else os << "-"; else os << "-";
} }
// name // name
os << " / " << stage.name(); os << " / " << impl.name();
return os; return os;
} }
@ -550,4 +549,9 @@ void Connecting::connect(const InterfaceState& from, const InterfaceState& to,
impl->newSolution(trajectory); 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_; return id_;
} }
void Task::printState(std::ostream& os) const void Task::printState(std::ostream& os) const {
{ os << *stages();
ContainerBase::StageCallback processor = [&os](const Stage& stage, int depth) -> bool {
os << std::string(2*depth, ' ') << stage << std::endl;
return true;
};
stages()->traverseRecursively(processor);
} }
} } } }