MCPcopy Create free account
hub / github.com/FastLED/FastLED / getTypeName

Function getTypeName

src/fl/test/fltest.h:1751–1797  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1749// This extracts the type name from FL_PRETTY_FUNCTION (__PRETTY_FUNCTION__ or __FUNCSIG__)
1750template <typename T>
1751inline fl::string getTypeName() FL_NOEXCEPT {
1752#if defined(__clang__) || defined(__GNUC__)
1753 // FL_PRETTY_FUNCTION format: "fl::string fl::test::detail::getTypeName() [T = int]"
1754 const char* func = FL_PRETTY_FUNCTION;
1755 const char* begin = func;
1756 // Find "T = "
1757 while (*begin && !(begin[0] == 'T' && begin[1] == ' ' && begin[2] == '=' && begin[3] == ' '))
1758 ++begin;
1759 if (*begin) {
1760 begin += 4; // Skip "T = "
1761 const char* end = begin;
1762 int depth = 0;
1763 while (*end) {
1764 if (*end == '<') ++depth;
1765 else if (*end == '>') {
1766 if (depth == 0) break;
1767 --depth;
1768 }
1769 else if (*end == ']' && depth == 0) break;
1770 ++end;
1771 }
1772 return fl::string(begin, static_cast<fl::size>(end - begin));
1773 }
1774#elif defined(_MSC_VER)
1775 // FL_PRETTY_FUNCTION format: "class fl::string __cdecl fl::test::detail::getTypeName<int>(void)"
1776 const char* func = FL_PRETTY_FUNCTION;
1777 const char* begin = func;
1778 // Find "getTypeName<"
1779 while (*begin && !(begin[0] == 'g' && begin[1] == 'e' && begin[2] == 't' && begin[3] == 'T' &&
1780 begin[4] == 'y' && begin[5] == 'p' && begin[6] == 'e' && begin[7] == 'N' &&
1781 begin[8] == 'a' && begin[9] == 'm' && begin[10] == 'e' && begin[11] == '<'))
1782 ++begin;
1783 if (*begin) {
1784 begin += 12; // Skip "getTypeName<"
1785 const char* end = begin;
1786 int depth = 1; // We're inside the first <
1787 while (*end && depth > 0) {
1788 if (*end == '<') ++depth;
1789 else if (*end == '>') --depth;
1790 ++end;
1791 }
1792 if (end > begin && depth == 0) --end; // Back up before final >
1793 return fl::string(begin, static_cast<fl::size>(end - begin));
1794 }
1795#endif
1796 return fl::string("{unknown}");
1797}
1798
1799// Specialization holder for custom type names
1800template <typename T>

Callers

nothing calls this directly

Calls 1

stringClass · 0.50

Tested by

no test coverage detected