File ColorTree.cpp changed (mode: 100644) (index c8c08b3..f2c24a5) |
... |
... |
ColorTree::append(ColorTree &&branch) |
291 |
291 |
void |
void |
292 |
292 |
ColorTree::visit(const visitorFunc &visitor) const |
ColorTree::visit(const visitorFunc &visitor) const |
293 |
293 |
{ |
{ |
294 |
|
std::stack<const ColorTree *> trees; |
|
295 |
|
trees.push(this); |
|
296 |
|
|
|
297 |
|
std::stack<const Format *> formats; |
|
298 |
|
Format fmt; |
|
299 |
|
formats.push(&fmt); |
|
300 |
|
|
|
301 |
|
FormatState formatState; |
|
302 |
|
while (!trees.empty()) { |
|
303 |
|
const ColorTree &tree = *trees.top(); |
|
304 |
|
trees.pop(); |
|
305 |
|
|
|
306 |
|
formatState -= *formats.top(); |
|
307 |
|
formats.top() = &tree.format; |
|
308 |
|
formatState += tree.format; |
|
309 |
|
|
|
310 |
|
if (tree.branches.empty()) { |
|
311 |
|
visitor(tree.text, formatState.getCurrent()); |
|
312 |
|
} else { |
|
313 |
|
for (auto it = tree.branches.crbegin(); |
|
314 |
|
it != tree.branches.crend(); |
|
315 |
|
++it) { |
|
316 |
|
trees.push(&*it); |
|
317 |
|
formats.emplace(&fmt); |
|
|
294 |
|
struct { |
|
295 |
|
const visitorFunc &visitor; |
|
296 |
|
FormatState formatState; |
|
297 |
|
|
|
298 |
|
void visit(const ColorTree &tree) |
|
299 |
|
{ |
|
300 |
|
formatState += tree.format; |
|
301 |
|
|
|
302 |
|
if (tree.branches.empty()) { |
|
303 |
|
visitor(tree.text, formatState.getCurrent()); |
|
304 |
|
} else { |
|
305 |
|
for (const ColorTree &branch : tree.branches) { |
|
306 |
|
visit(branch); |
|
307 |
|
} |
318 |
308 |
} |
} |
|
309 |
|
|
|
310 |
|
formatState -= tree.format; |
319 |
311 |
} |
} |
320 |
|
} |
|
|
312 |
|
} f = { visitor, {} }; |
|
313 |
|
|
|
314 |
|
f.visit(*this); |
321 |
315 |
} |
} |
322 |
316 |
|
|
323 |
317 |
int |
int |