From 3722d87aee4ed72212f52fd683e682521935f28b Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Tue, 31 May 2022 00:58:37 +0200 Subject: [PATCH] Added type to string --- main/typeutils.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 main/typeutils.h diff --git a/main/typeutils.h b/main/typeutils.h new file mode 100644 index 0000000..4ead8e9 --- /dev/null +++ b/main/typeutils.h @@ -0,0 +1,56 @@ +#pragma once + +namespace typeutils { + using namespace std; +template +struct t_to_str +{ + t_to_str() = delete; + ~t_to_str() = delete; + + static const char *str; +}; + +template +const char *t_to_str::str = "unknown"; + +#define DEFINE_FOR_TYPE2(TYPE, STR) \ + template<> const char *t_to_str::str = #STR; \ + template<> const char *t_to_str::str = #STR; \ + template<> const char *t_to_str>::str = "std::optional<" #STR ">"; \ + template<> const char *t_to_str const&>::str = "std::optional<" #STR ">"; \ + template<> const char *t_to_str>::str = #STR; \ + template<> const char *t_to_str const&>::str = #STR; \ + template<> const char *t_to_str>::str = #STR; \ + template<> const char *t_to_str const&>::str = #STR; + +#define DEFINE_FOR_TYPE(TYPE) DEFINE_FOR_TYPE2(TYPE, TYPE) +DEFINE_FOR_TYPE(bool) +DEFINE_FOR_TYPE(int8_t) +DEFINE_FOR_TYPE(uint8_t) +DEFINE_FOR_TYPE(int16_t) +DEFINE_FOR_TYPE(uint16_t) +DEFINE_FOR_TYPE(int32_t) +DEFINE_FOR_TYPE(uint32_t) +DEFINE_FOR_TYPE(int64_t) +DEFINE_FOR_TYPE(uint64_t) +DEFINE_FOR_TYPE(long) +DEFINE_FOR_TYPE(unsigned long) +DEFINE_FOR_TYPE(float) +DEFINE_FOR_TYPE(double) +DEFINE_FOR_TYPE(string) +DEFINE_FOR_TYPE(sntp_sync_mode_t) +DEFINE_FOR_TYPE(espchrono::DayLightSavingMode) +DEFINE_FOR_TYPE(OtaAnimationModes) +DEFINE_FOR_TYPE(LedstripAnimation) +DEFINE_FOR_TYPE(HandbremseMode) +DEFINE_FOR_TYPE(BobbyQuickActions) +DEFINE_FOR_TYPE(CloudMode) +DEFINE_FOR_TYPE(BatteryCellType) +DEFINE_FOR_TYPE(wifi_auth_mode_t) +DEFINE_FOR_TYPE(wifi_stack::mac_t) +DEFINE_FOR_TYPE(wifi_stack::ip_address_t) +DEFINE_FOR_TYPE(espchrono::milliseconds32) +DEFINE_FOR_TYPE(espchrono::minutes32) +#undef DEFINE_FOR_TYPE +} // namespace typeutils