repr 0.1
Reconstructable string representations and more
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
layout.h
Go to the documentation of this file.
#pragma once
#include <librepr/visit.h>
#include <type_traits>
namespace librepr {
struct LayoutVisitor {
private:
bool separate = false;
void print_separator() {
if (separate) {
result << ", ";
} else {
separate = true;
}
}
template <typename T>
void print_name() {
if constexpr (std::is_pointer_v<T> && std::same_as<std::remove_const_t<std::remove_pointer_t<T>>, char>) {
result << "str";
} else {
}
}
template <category::can_descend T>
void descend(T info) {
separate = false;
info.visit(*this);
}
public:
template <typename T>
void operator()(T info) {
using type = typename T::type;
print_separator();
if constexpr (requires { typename type::value_type; }) {
// iterable container
result << '[';
if constexpr (requires {
typename type::key_type;
typename type::mapped_type;
}) {
// associative container
separate = false;
result << " -> ";
separate = false;
} else {
}
result << ']';
} else {
}
}
template <category::has_members T>
void operator()(T info) {
print_separator();
result << '{';
descend(info);
result << '}';
}
template <category::has_alternatives T>
void operator()(T info) {
print_separator();
T::alternatives::for_each([this, first=true]<typename U>() mutable {
if (!first) {
result << " | ";
}
first = false;
separate = false;
});
}
template <category::has_enumerator_names T>
void operator()(T info) {
print_separator();
for (auto const& name : info.enumerator_names) {
if (&*info.enumerator_names.begin() != &name) {
result << " | ";
}
result << name;
}
}
template <category::has_extent T>
requires requires { typename T::element_type; }
};
} // namespace librepr