10 std::lock_guard _{*m_lock};
11 return create_proxy(i < m_nodePart->m_filteredNodes.size()?
12 m_nodePart->m_filteredNodes.at(i).second:
13 m_nodePart->m_elseNode);
16auto C_ParaLog::C_NodeArrayProxy::create_proxy(C_NodePtr &holder)
const ->
C_NodeProxy
19 holder = std::make_unique<C_Node>();
21 return {*m_lock, *holder};
26 std::lock_guard _{*m_lock};
27 return create_proxy(m_nodePart->m_elseNode);
30void C_ParaLog::C_LockedNode::create_from(
const C_Node &node,
const std::function<std::ostream*(
I_ReenterableLog&)> &to_log)
32 for (
auto &i: node.m_loggers)
34 if (
const auto ret = to_log(*i))
35 m_loggers.emplace_back(i.get(), ret);
37 for (
auto &i: node.m_partitions)
39 auto &dstPart = m_partitions.emplace_back();
40 for (
auto &j: i.m_filteredNodes)
42 auto &dstPair = dstPart.m_filteredNodes.emplace_back(std::piecewise_construct, std::forward_as_tuple(j.first), std::forward_as_tuple());
44 dstPair.second.create_from(*j.second, to_log);
48 dstPart.m_elseNode.create_from(*i.m_elseNode, to_log);
49 if (dstPart.m_elseNode.empty())
50 while (dstPart.m_filteredNodes.back().second.empty())
51 dstPart.m_filteredNodes.pop_back();
53 m_partitions.pop_back();
57void C_ParaLog::C_LockedNode::log(std::string_view s,
bool flush)
const
59 for (
auto &i: m_loggers)
62 i.first->unuseLog(flush);
64 for (
auto &i: m_partitions)
67 for (
auto &j: i.m_filteredNodes)
71 j.second.log(s, flush);
77 i.m_elseNode.log(s, flush);
81std::ostream *
C_ParaLog::lockLog(
const std::function<std::ostream*(I_ReenterableLog&)> &to_log)
84 auto &dst = m_lockedStack.emplace_back();
85 dst.first.create_from(m_root, to_log);
86 if (!dst.first.empty())
89 m_lockedStack.pop_back();
96 return lockLog([](
auto &child){
return child.useLog(); });
101 return lockLog([ll](
auto &child){
return child.useLog(ll); });
106 const auto &back = m_lockedStack.back();
107 back.first.log(back.second.str(), flush);
108 m_lockedStack.pop_back();
C_NodeProxy operator[](size_t i) const
C_NodeProxy matchedNone() const
void unlockLog(bool flush) override
If the previous call to lockLog() returned null, the behavior is undefined.
std::ostream * lockLog() override
Return non-null pointer if possible.
THE common namespace of bux library.
Thread-unsafe implementation is preferred for performance.