File indexing completed on 2026-07-26 08:22:17
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "traccc/examples/utils/printable.hpp"
0010
0011
0012 #include <sstream>
0013
0014 namespace traccc {
0015 std::string configuration_printable::print() const {
0016 std::size_t mkw = get_max_key_width_impl();
0017 std::ostringstream oss;
0018 print_impl("", "", 0, mkw, oss);
0019 return oss.str();
0020 };
0021
0022 configuration_printable::~configuration_printable() = default;
0023
0024 configuration_category::configuration_category(std::string_view n) : name(n) {}
0025
0026 void configuration_category::add_child(
0027 std::unique_ptr<configuration_printable> elem) {
0028 elements.push_back(std::move(elem));
0029 }
0030
0031 void configuration_category::print_impl(const std::string& self_prefix,
0032 const std::string& child_prefix,
0033 std::size_t prefix_len,
0034 std::size_t max_key_width,
0035 std::ostream& out) const {
0036 out << self_prefix << name << ":\n";
0037
0038 for (std::size_t i = 0; i < elements.size(); i++) {
0039 if (i == elements.size() - 1) {
0040 elements[i]->print_impl(child_prefix + "└ ", child_prefix + " ",
0041 prefix_len + 2, max_key_width, out);
0042 } else {
0043 elements[i]->print_impl(child_prefix + "├ ", child_prefix + "│ ",
0044 prefix_len + 2, max_key_width, out);
0045 }
0046 }
0047 }
0048
0049 std::size_t configuration_category::get_max_key_width_impl() const {
0050 std::size_t res = 0;
0051
0052 for (auto& i : elements) {
0053 res = std::max(res, 2 + i->get_max_key_width_impl());
0054 }
0055
0056 return res;
0057 }
0058
0059 configuration_category::~configuration_category() = default;
0060
0061 configuration_list::configuration_list() = default;
0062
0063 void configuration_list::add_child(
0064 std::unique_ptr<configuration_printable> elem) {
0065 elements.push_back(std::move(elem));
0066 }
0067
0068 void configuration_list::print_impl(const std::string& self_prefix,
0069 const std::string& child_prefix,
0070 std::size_t prefix_len,
0071 std::size_t max_key_width,
0072 std::ostream& out) const {
0073 for (auto& i : elements) {
0074 i->print_impl(self_prefix, child_prefix, prefix_len, max_key_width, out);
0075 }
0076 }
0077
0078 std::size_t configuration_list::get_max_key_width_impl() const {
0079 std::size_t res = 0;
0080
0081 for (auto& i : elements) {
0082 res = std::max(res, i->get_max_key_width_impl());
0083 }
0084
0085 return res;
0086 }
0087
0088 configuration_list::~configuration_list() = default;
0089
0090 configuration_kv_pair::configuration_kv_pair(std::string_view k,
0091 std::string_view v)
0092 : key(k), value(v) {}
0093
0094 void configuration_kv_pair::print_impl(const std::string& self_prefix,
0095 const std::string&,
0096 std::size_t prefix_len,
0097 std::size_t max_key_width,
0098 std::ostream& out) const {
0099 out << self_prefix << key << ": "
0100 << std::string((max_key_width - (prefix_len + key.length())), ' ')
0101 << value << "\n";
0102 }
0103
0104 std::size_t configuration_kv_pair::get_max_key_width_impl() const {
0105 return key.length();
0106 }
0107
0108 configuration_kv_pair::~configuration_kv_pair() = default;
0109 }