// clang-format off // SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company // clang-format on // SPDX-FileContributor: Andrew Hayzen // // SPDX-License-Identifier: MIT OR Apache-2.0 #pragma once #include #include #include namespace rust { namespace cxxqtlib1 { using c_void = void; template T construct(Args... args) { return T(args...); } template void drop(T& value) { value.~T(); } template QString toQString(const T& value) { // We can't convert value directly into a string. // However most Qt types are able to stream into a QDebug object such as // qDebug() << value // // We can then construct a QDebug object that outputs into a string (instead // of logging), and return that string. Thus we have a pretty reliable and // generic "toString" implementation for most Qt types. QString res; QDebug serializer{ &res }; serializer << value; return res; } template bool operatorEq(const T& a, const T& b) { return a == b; } template ::std::int8_t operatorCmp(const T& a, const T& b) { return operatorEq(a, b) ? 0 : (a < b ? -1 : 1); } template A operatorPlus(const A& a, const B& b) { return a + b; } template A operatorMinus(const A& a, const B& b) { return a - b; } template T operatorMul(const S scalar, const T& t) { return scalar * t; } template T operatorDiv(const S scalar, const T& t) { return t / scalar; } template std::unique_ptr make_unique(Args... args) { return std::make_unique(std::forward(args)...); } template std::shared_ptr make_shared(Args... args) { return std::make_shared(std::forward(args)...); } template T* new_ptr(Args... args) { return new T(std::forward(args)...); } } // namespace cxxqtlib1 } // namespace rust