From 1955deee74c31ce05cdc288df65b517fd225e2fc Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Wed, 20 Nov 2024 19:22:23 -0800 Subject: [PATCH] dbus/properties: add QObjectBindableProperty based dbus property Many times more lightweight than the original QObject-based one. --- src/core/util.hpp | 38 +++++++++--- src/dbus/properties.cpp | 4 ++ src/dbus/properties.hpp | 124 +++++++++++++++++++++++++++++++++++++--- 3 files changed, 151 insertions(+), 15 deletions(-) diff --git a/src/core/util.hpp b/src/core/util.hpp index 5dae122f..62264b93 100644 --- a/src/core/util.hpp +++ b/src/core/util.hpp @@ -2,22 +2,45 @@ #include #include +#include #include #include #include +#include #include #include -template +template struct StringLiteral { - constexpr StringLiteral(const char (&str)[Length]) { // NOLINT - std::copy_n(str, Length, this->value); + constexpr StringLiteral(const char (&str)[length]) { // NOLINT + std::copy_n(str, length, this->value); } constexpr operator const char*() const noexcept { return this->value; } - operator QLatin1StringView() const { return QLatin1String(this->value, Length); } + operator QLatin1StringView() const { return QLatin1String(this->value, length); } - char value[Length]; // NOLINT + char value[length]; // NOLINT +}; + +template +struct StringLiteral16 { + constexpr StringLiteral16(const char16_t (&str)[length]) { // NOLINT + std::copy_n(str, length, this->value); + } + + [[nodiscard]] constexpr const QChar* qCharPtr() const noexcept { + return std::bit_cast(&this->value); + } + + [[nodiscard]] Q_ALWAYS_INLINE operator QString() const noexcept { + return QString::fromRawData(this->qCharPtr(), static_cast(length - 1)); + } + + [[nodiscard]] Q_ALWAYS_INLINE operator QStringView() const noexcept { + return QStringView(this->qCharPtr(), static_cast(length - 1)); + } + + char16_t value[length]; // NOLINT }; // NOLINTBEGIN @@ -149,11 +172,10 @@ private: // NOLINTEND template -class MemberPointerTraits; +struct MemberPointerTraits; template -class MemberPointerTraits { -public: +struct MemberPointerTraits { using Class = C; using Type = T; }; diff --git a/src/dbus/properties.cpp b/src/dbus/properties.cpp index a1cd7e68..08146637 100644 --- a/src/dbus/properties.cpp +++ b/src/dbus/properties.cpp @@ -162,6 +162,10 @@ void DBusPropertyGroup::attachProperty(AbstractDBusProperty* property) { property->group = this; } +void DBusPropertyGroup::attachProperty(DBusPropertyCore* property) { + this->properties.append(property); +} + void DBusPropertyGroup::updateAllDirect() { qCDebug(logDbusProperties).noquote() << "Updating all properties of" << this->toString() << "via individual queries"; diff --git a/src/dbus/properties.hpp b/src/dbus/properties.hpp index 3008d357..11e7e063 100644 --- a/src/dbus/properties.hpp +++ b/src/dbus/properties.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -14,10 +15,14 @@ #include #include #include +#include +#include #include #include #include +#include "../core/util.hpp" + class DBusPropertiesInterface; Q_DECLARE_LOGGING_CATEGORY(logDbusProperties); @@ -132,21 +137,94 @@ private: friend class DBusPropertyGroup; }; +namespace bindable_p { + +template +struct BindableParams; + +template