AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
AClass.h
1/*
2 * AUI Framework - Declarative UI toolkit for modern C++20
3 * Copyright (C) 2020-2024 Alex2772 and Contributors
4 *
5 * SPDX-License-Identifier: MPL-2.0
6 *
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 */
11
12#pragma once
13
14#include "AUI/Common/AString.h"
15
16
17template<class T>
18class AClass {
19public:
20 static AString name() {
21#if AUI_COMPILER_MSVC
22 AString s = __FUNCSIG__;
23 auto openTag = s.find('<') + 1;
24 auto closeTag = s.find('>');
25 auto name = s.substr(openTag, closeTag - openTag);
26 name = name.substr(name.rfind(' ') + 1);
27 if (name.endsWith(" &"))
28 name = name.substr(0, name.length() - 2);
29 return name;
30#elif AUI_COMPILER_CLANG
31 AString s = __PRETTY_FUNCTION__;
32 auto b = s.find("=") + 1;
33 auto e = s.find("&", b);
34 e = std::min(s.find("]", b), e);
35 auto result = s.substr(b, e - b);
36 result = result.trim();
37 return result;
38#else
39 AString s = __PRETTY_FUNCTION__;
40 auto b = s.find("with T = ") + 9;
41 return { s.begin() + b, s.end() - 1 };
42#endif
43 }
44
45 static AString nameWithoutNamespace() {
46 auto s = name();
47 auto p = s.rfind("::");
48 if (p != AString::NPOS) {
49 return {s.begin() + p + 2, s.end()};
50 }
51 return s;
52 }
53
54 static AString toString(const T& t) {
55 return "<object of type " + name() + ">";
56 }
57};
58
59template<>
61 return "\"" + t + "\"";
62}
63
64template<>
65inline AString AClass<int>::toString(const int& t) {
66 return AString::number(t);
67}
Definition: AClass.h:18
Represents a Unicode character string.
Definition: AString.h:37