operator<< for Interface + Priority

Co-authored by v4hn
This commit is contained in:
Robert Haschke 2020-12-07 07:10:19 +01:00 committed by v4hn
parent 7c6eb1c0f3
commit 9466517f72
2 changed files with 18 additions and 4 deletions

View File

@ -205,6 +205,9 @@ private:
using base_type::remove_if;
};
std::ostream& operator<<(std::ostream& os, const InterfaceState::Priority& prio);
std::ostream& operator<<(std::ostream& os, const Interface& interface);
class CostTerm;
class StagePrivate;
class ContainerBasePrivate;

View File

@ -81,10 +81,6 @@ bool InterfaceState::Priority::operator<(const InterfaceState::Priority& other)
return depth() > other.depth(); // larger depth = smaller prio!
}
std::ostream& operator<<(std::ostream& os, const InterfaceState::Priority& p) {
return os << "[depth: " << p.depth() << ", cost: " << p.cost() << "]";
}
Interface::Interface(const Interface::NotifyFunction& notify) : notify_(notify) {}
// Announce a new InterfaceState
@ -138,6 +134,21 @@ void Interface::updatePriority(InterfaceState* state, const InterfaceState::Prio
notify_(it, true); // notify callback
}
std::ostream& operator<<(std::ostream& os, const Interface& interface) {
if (interface.empty())
os << "---";
for (const auto& istate : interface)
os << istate->priority() << " ";
return os;
}
std::ostream& operator<<(std::ostream& os, const InterfaceState::Priority& prio) {
static const char* red = "\033[31m";
static const char* green = "\033[32m";
static const char* color_reset = "\033[m";
os << (prio.enabled() ? green : red) << prio.depth() << ":" << prio.cost() << color_reset;
return os;
}
void SolutionBase::setCreator(Stage* creator) {
assert(creator_ == nullptr || creator_ == creator); // creator must only set once
creator_ = creator;