Add an overload for io manip in the logger.

This commit is contained in:
Tomasz Sobczyk
2020-10-24 13:31:40 +02:00
committed by nodchip
parent 54dd6a2407
commit d824bd8ec5

View File

@@ -124,6 +124,13 @@ private:
}
}
RegionLock& operator << (std::ostream&(*pManip)(std::ostream&)) {
if (logger != nullptr)
logger->write(region_id, pManip);
return *this;
}
template <typename T>
RegionLock& operator << (const T& value) {
if (logger != nullptr)
@@ -159,6 +166,29 @@ private:
return id;
}
void write(RegionId id, std::ostream&(*pManip)(std::ostream&)) {
std::lock_guard lock(mutex);
if (regions.empty())
return;
if (id == regions.front().id) {
// We can just directly print to the output because
// we are at the front of the region queue.
out << *pManip;
} else {
// We have to schedule the print until previous regions are
// processed
auto* region = find_region_nolock(id);
if (region == nullptr)
return;
std::stringstream ss;
ss << *pManip;
region->pending_parts.emplace_back(std::move(ss).str());
}
}
template <typename T>
void write(RegionId id, const T& value) {
std::lock_guard lock(mutex);