17#ifndef DOXYGEN_SHOULD_SKIP_THIS
22 template <std::size_t... Idxs>
23 constexpr auto substring_as_array(std::string_view str,
24 std::index_sequence<Idxs...>)
26 return std::array{str[Idxs]...,
'\0'};
30 constexpr auto type_name_array()
33 constexpr auto prefix = std::string_view{
"[T = symmetri::"};
34 constexpr auto suffix = std::string_view{
"]"};
35 constexpr auto function = std::string_view{__PRETTY_FUNCTION__};
36#elif defined(__GNUC__)
37 constexpr auto prefix = std::string_view{
"with T = symmetri::"};
38 constexpr auto suffix = std::string_view{
"]"};
39 constexpr auto function = std::string_view{__PRETTY_FUNCTION__};
40#elif defined(_MSC_VER)
41 constexpr auto prefix = std::string_view{
"type_name_array<symmetri::"};
42 constexpr auto suffix = std::string_view{
">(void)"};
43 constexpr auto function = std::string_view{__FUNCSIG__};
45#error Unsupported compiler
48 constexpr auto start = function.find(prefix) + prefix.size();
49 constexpr auto end = function.rfind(suffix);
51 static_assert(start < end);
53 constexpr auto name = function.substr(start, (end - start));
54 return substring_as_array(name, std::make_index_sequence<name.size()>{});
58 struct type_name_holder
60 static inline constexpr auto value = type_name_array<T>();
64 constexpr auto type_name() -> std::string_view
66 constexpr auto &value = type_name_holder<T>::value;
67 return std::string_view{value.data(), value.size()};
93 std::vector<const char *> _colors;
94 _colors.reserve(colors.size());
95 std::copy_if(colors.begin(), colors.end(), std::back_inserter(_colors),
97 { return color != nullptr; });
101 constexpr const auto &toString()
const {
return colors[id]; }
104 constexpr bool operator==(
const T &t)
const
109 constexpr bool operator<(
const Token &rhs)
const
111 return id < rhs.toIndex();
114 constexpr bool operator>(
const Token &rhs)
const
116 return id > rhs.toIndex();
119 constexpr size_t toIndex()
const {
return id; }
121 static constexpr bool equals(
const char *a,
const char *b)
123 return *a == *b && (*a ==
'\0' || equals(a + 1, b + 1));
126 template <
class X,
class V>
127 static constexpr auto find(X &x, V key)
132 if (x[i] !=
nullptr && equals(x[i], key))
141 static constexpr auto findSlot(X &x)
154 constexpr Token(
const char *_id)
155 : id(find(colors, _id) <
kMaxTokenColors ? find(colors, _id) : findSlot(colors))
157 assert(
id < colors.size() &&
158 "There can only be kMaxTokenColors different token-colors.");
165 inline static std::array<const char *, kMaxTokenColors> colors = {
nullptr};
173struct std::hash<symmetri::Token>
175 constexpr std::size_t operator()(
const symmetri::Token &s)
const noexcept
186#define CREATE_CUSTOM_TOKEN(name) \
189 struct name : public Token \
192 : Token(sym_impl::type_name<name>().data()) {} \
194 static inline name name; \
Tokens are elements that can reside in places. Tokens can have a color which makes them distinguishab...
Definition colors.hpp:84
static std::vector< const char * > getColors()
Get a list of all the colors.
Definition colors.hpp:91
static const size_t kMaxTokenColors
Maximum amount of different colors.
Definition colors.hpp:163
#define CREATE_CUSTOM_TOKEN(name)
A macro from which we can create token-colors. Colors ceated this way end up in the symmetri namespac...
Definition colors.hpp:186