AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AClass.h
    1/*
    2 * AUI Framework - Declarative UI toolkit for modern C++20
    3 * Copyright (C) 2020-2025 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
   18
   22template<class T>
   24public:
   25    static_assert(!std::is_reference<T>::value, "====================> AClass: attempt to use AClass on a reference.");
   27
   28    static AString name() {
   29#if AUI_COMPILER_MSVC
   30        AString s = __FUNCSIG__;
   31        auto openTag = s.find('<') + 1;
   32        auto closeTag = s.find('>');
   33        auto name = s.substr(openTag, closeTag - openTag);
   34        name = name.substr(name.rfind(' ') + 1);
   35        if (name.endsWith(" &"))
   36            name = name.substr(0, name.length() - 2);
   37        return name;
   38#elif AUI_COMPILER_CLANG
   39        AString s = __PRETTY_FUNCTION__;
   40        auto b = s.find("=") + 1;
   41        auto e = s.find("&", b);
   42        e = std::min(s.find("]", b), e);
   43        auto result = s.substr(b, e - b);
   44        result = result.trim();
   45        return result;
   46#else
   47        AString s = __PRETTY_FUNCTION__;
   48        auto b = s.find("with T = ") + 9;
   49        return { s.begin() + b, s.end() - 1 };
   50#endif
   51    }
   52
   53    static AString nameWithoutNamespace() {
   54        auto s = name();
   55        auto p = s.rfind("::");
   56        if (p != AString::NPOS) {
   57            return {s.begin() + p + 2, s.end()};
   58        }
   59        return s;
   60    }
   61
   62    static AString toString(const T& t) {
   63        return "<object of type " + name() + ">";
   64    }
   65};
   66
   67template<>
   68inline AString AClass<AString>::toString(const AString& t) {
   69    return "\"" + t + "\"";
   70}
   71
   72template<>
   73inline AString AClass<int>::toString(const int& t) {
   74    return AString::number(t);
   75}
[ARROW_ERROR_MESSAGE_EXAMPLE]
Definition AClass.h:23
static AString name()
[ARROW_ERROR_MESSAGE_EXAMPLE]
Definition AClass.h:28
Represents a Unicode character string.
Definition AString.h:38
type_of< T > t
Selects views that are of the specified C++ types.
Definition type_of.h:71