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

@ -86,7 +86,7 @@ typedef std::pair<const InterfaceState&, const InterfaceState&> InterfaceStatePa
/// exception thrown by Stage::init() /// exception thrown by Stage::init()
/// It collects individual errors in stages throughout the pipeline to allow overall error reporting /// It collects individual errors in stages throughout the pipeline to allow overall error reporting
class InitStageException : public std::exception { class InitStageException : public std::exception {
friend std::ostream& operator<<(std::ostream &os, const InitStageException& e); friend std::ostream& operator<<(std::ostream& os, const InitStageException& e);
public: public:
explicit InitStageException() {} explicit InitStageException() {}
@ -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;
@ -175,7 +173,7 @@ protected:
protected: protected:
StagePrivate* const pimpl_; // constness guarantees one initial write StagePrivate* const pimpl_; // constness guarantees one initial write
}; };
std::ostream& operator<<(std::ostream &os, const Stage& stage); std::ostream& operator<<(std::ostream& os, const Stage& stage);
class ComputeBasePrivate; class ComputeBasePrivate;
@ -299,5 +297,4 @@ public:
} }
}; };
} } } }

View File

@ -52,7 +52,7 @@ namespace moveit { namespace task_constructor {
class ContainerBase; class ContainerBase;
class StagePrivate { class StagePrivate {
friend class Stage; friend class Stage;
friend std::ostream& operator<<(std::ostream &os, const StagePrivate& stage); friend std::ostream& operator<<(std::ostream& os, const StagePrivate& stage);
public: public:
typedef std::list<Stage::pointer> container_type; typedef std::list<Stage::pointer> container_type;
@ -120,7 +120,7 @@ private:
Introspection* introspection_; // task's introspection instance Introspection* introspection_; // task's introspection instance
}; };
PIMPL_FUNCTIONS(Stage) PIMPL_FUNCTIONS(Stage)
std::ostream& operator<<(std::ostream &os, const StagePrivate& stage); std::ostream& operator<<(std::ostream& os, const StagePrivate& stage);
// ComputeBasePrivate is the base class for all computing stages, i.e. non-containers. // ComputeBasePrivate is the base class for all computing stages, i.e. non-containers.

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

@ -61,7 +61,7 @@ const char *InitStageException::what() const noexcept
return msg; return msg;
} }
std::ostream& operator<<(std::ostream &os, const InitStageException& e) { std::ostream& operator<<(std::ostream& os, const InitStageException& e) {
os << e.what() << std::endl; os << e.what() << std::endl;
for (const auto &pair : e.errors_) for (const auto &pair : e.errors_)
os << pair.first->name() << ": " << pair.second << std::endl; os << pair.first->name() << ": " << pair.second << std::endl;
@ -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);
} }
} } } }