| 40 | namespace |
| 41 | { |
| 42 | struct join_visitor { |
| 43 | swoc::BufferWriter &_w; |
| 44 | TextView _glue; |
| 45 | unsigned _recurse = 0; |
| 46 | |
| 47 | swoc::BufferWriter & |
| 48 | glue() const |
| 49 | { |
| 50 | if (_w.size()) { |
| 51 | _w.write(_glue); |
| 52 | } |
| 53 | return _w; |
| 54 | } |
| 55 | |
| 56 | void |
| 57 | operator()(feature_type_for<NIL>) const |
| 58 | { |
| 59 | } |
| 60 | void |
| 61 | operator()(feature_type_for<STRING> const &s) const |
| 62 | { |
| 63 | this->glue().write(s); |
| 64 | } |
| 65 | void |
| 66 | operator()(feature_type_for<INTEGER> n) const |
| 67 | { |
| 68 | this->glue().print("{}", n); |
| 69 | } |
| 70 | void |
| 71 | operator()(feature_type_for<BOOLEAN> flag) const |
| 72 | { |
| 73 | this->glue().print("{}", flag); |
| 74 | } |
| 75 | void |
| 76 | operator()(feature_type_for<DURATION> d) const |
| 77 | { |
| 78 | this->glue().print("{}", d); |
| 79 | } |
| 80 | void |
| 81 | operator()(feature_type_for<TUPLE> t) const |
| 82 | { |
| 83 | this->glue(); |
| 84 | if (_recurse) { |
| 85 | _w.write("[ "_tv); |
| 86 | } |
| 87 | auto lw = swoc::FixedBufferWriter{_w.aux_span()}; |
| 88 | for (auto const &item : t) { |
| 89 | std::visit(join_visitor{lw, _glue, _recurse + 1}, item); |
| 90 | } |
| 91 | _w.commit(lw.size()); |
| 92 | if (_recurse) { |
| 93 | _w.write(" ]"_tv); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | template <typename T> |
| 98 | auto |
| 99 | operator()(T const &) const -> EnableForFeatureTypes<T, void> |