mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 12:55:33 +08:00
refs #413 Decomposed dbus-related functions of CValueObject into Mixin::DBusByTuple.
This commit is contained in:
@@ -160,8 +160,9 @@ namespace BlackMisc
|
||||
//! \copydoc BlackMisc::CValueObject::getMetaTypeId
|
||||
int getMetaTypeId() const { return qMetaTypeId<C<T>>(); }
|
||||
|
||||
public:
|
||||
//! \copydoc BlackMisc::CValueObject::marshallToDbus
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const override
|
||||
void marshallToDbus(QDBusArgument &argument) const
|
||||
{
|
||||
argument.beginArray(qMetaTypeId<T>());
|
||||
std::for_each(derived().cbegin(), derived().cend(), [ & ](const T & value) { argument << value; });
|
||||
@@ -169,7 +170,7 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
//! \copydoc BlackMisc::CValueObject::unmarshallFromDbus
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override
|
||||
void unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
argument.beginArray();
|
||||
while (!argument.atEnd()) { T value; argument >> value; derived().insert(value); }
|
||||
|
||||
@@ -418,14 +418,15 @@ namespace BlackMisc
|
||||
return str += "}";
|
||||
}
|
||||
|
||||
public:
|
||||
//! \copydoc BlackMisc::CValueObject::marshallToDbus
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const override
|
||||
void marshallToDbus(QDBusArgument &argument) const
|
||||
{
|
||||
argument << m_impl;
|
||||
}
|
||||
|
||||
//! \copydoc BlackMisc::CValueObject::unmarshallFromDbus
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override
|
||||
void unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
argument >> m_impl;
|
||||
}
|
||||
|
||||
@@ -86,11 +86,12 @@ namespace BlackMisc
|
||||
//! \copydoc CValueObject::convertToQString()
|
||||
virtual QString convertToQString(bool i18n = false) const override;
|
||||
|
||||
public:
|
||||
//! \copydoc CValueObject::marshallToDbus()
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const override;
|
||||
void marshallToDbus(QDBusArgument &argument) const;
|
||||
|
||||
//! \copydoc CValueObject::marshallFromDbus()
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
|
||||
void unmarshallFromDbus(const QDBusArgument &argument);
|
||||
|
||||
private:
|
||||
bool checkInvariants() const;
|
||||
|
||||
@@ -253,21 +253,21 @@ namespace BlackMisc
|
||||
return this->getSymbol(i18n);
|
||||
}
|
||||
|
||||
public:
|
||||
//! \copydoc CValueObject::marshallToDbus
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const override
|
||||
void marshallToDbus(QDBusArgument &argument) const
|
||||
{
|
||||
argument << this->m_symbol;
|
||||
}
|
||||
|
||||
//! \copydoc CValueObject::unmarshallFromDbus
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &) override
|
||||
void unmarshallFromDbus(const QDBusArgument &)
|
||||
{
|
||||
// the concrete implementations will override this default
|
||||
// this is required so I can also stream None
|
||||
(*this) = CMeasurementUnit::None();
|
||||
}
|
||||
|
||||
public:
|
||||
//! Default constructor for meta system
|
||||
//! \remarks Only public because the need, to use this with the metasystem
|
||||
CMeasurementUnit() : m_name("none"), m_symbol(""), m_epsilon(0), m_displayDigits(0)
|
||||
|
||||
@@ -193,10 +193,10 @@ namespace BlackMisc
|
||||
void makeNegative();
|
||||
|
||||
//! \copydoc CValueObject::marshallToDbus
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const override;
|
||||
void marshallToDbus(QDBusArgument &argument) const;
|
||||
|
||||
//! \copydoc CValueObject::unmarshallFromDbus
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
|
||||
void unmarshallFromDbus(const QDBusArgument &argument);
|
||||
|
||||
//! \copydoc CValueObject::qHash
|
||||
uint getValueHash() const;
|
||||
|
||||
@@ -135,9 +135,8 @@ namespace BlackMisc
|
||||
return u;
|
||||
}
|
||||
|
||||
protected:
|
||||
//! \copydoc CValueObject::unmarshallFromDbus
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override
|
||||
void unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
QString unitName;
|
||||
argument >> unitName;
|
||||
@@ -226,9 +225,8 @@ namespace BlackMisc
|
||||
return u;
|
||||
}
|
||||
|
||||
protected:
|
||||
//! \copydoc CValueObject::unmarshallFromDbus
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override
|
||||
void unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
QString unitName;
|
||||
argument >> unitName;
|
||||
@@ -308,9 +306,8 @@ namespace BlackMisc
|
||||
return u;
|
||||
}
|
||||
|
||||
protected:
|
||||
//! \copydoc CValueObject::unmarshallFromDbus
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override
|
||||
void unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
QString unitName;
|
||||
argument >> unitName;
|
||||
@@ -399,9 +396,8 @@ namespace BlackMisc
|
||||
return u;
|
||||
}
|
||||
|
||||
protected:
|
||||
//! \copydoc CValueObject::unmarshallFromDbus
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override
|
||||
void unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
QString unitName;
|
||||
argument >> unitName;
|
||||
@@ -507,9 +503,8 @@ namespace BlackMisc
|
||||
return u;
|
||||
}
|
||||
|
||||
protected:
|
||||
//! \copydoc CValueObject::unmarshallFromDbus
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override
|
||||
void unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
QString unitName;
|
||||
argument >> unitName;
|
||||
@@ -590,9 +585,8 @@ namespace BlackMisc
|
||||
return u;
|
||||
}
|
||||
|
||||
protected:
|
||||
//! \copydoc CValueObject::unmarshallFromDbus
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override
|
||||
void unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
QString unitName;
|
||||
argument >> unitName;
|
||||
@@ -692,9 +686,8 @@ namespace BlackMisc
|
||||
return u;
|
||||
}
|
||||
|
||||
protected:
|
||||
//! \copydoc CValueObject::unmarshallFromDbus
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override
|
||||
void unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
QString unitName;
|
||||
argument >> unitName;
|
||||
@@ -818,9 +811,8 @@ namespace BlackMisc
|
||||
return u;
|
||||
}
|
||||
|
||||
protected:
|
||||
//! \copydoc CValueObject::unmarshallFromDbus
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override
|
||||
void unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
QString unitName;
|
||||
argument >> unitName;
|
||||
@@ -884,9 +876,8 @@ namespace BlackMisc
|
||||
return u;
|
||||
}
|
||||
|
||||
protected:
|
||||
//! \copydoc CValueObject::unmarshallFromDbus
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override
|
||||
void unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
QString unitName;
|
||||
argument >> unitName;
|
||||
|
||||
@@ -157,11 +157,12 @@ namespace BlackMisc
|
||||
//! \copydoc CValueObject::convertToQString
|
||||
virtual QString convertToQString(bool i18n = false) const override;
|
||||
|
||||
public:
|
||||
//! \copydoc CValueObject::marshallToDbus
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const override;
|
||||
void marshallToDbus(QDBusArgument &argument) const;
|
||||
|
||||
//! \copydoc CValueObject::unmarshallFromDbus
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
|
||||
void unmarshallFromDbus(const QDBusArgument &argument);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -115,12 +115,6 @@ namespace BlackMisc
|
||||
|
||||
//! From JSON
|
||||
static void convertFromJson(const QJsonObject &) {}
|
||||
|
||||
//! Marshall to DBus
|
||||
static void marshallToDbus(QDBusArgument &) {}
|
||||
|
||||
//! Unmarshall from DBus
|
||||
static void unmarshallFromDbus(const QDBusArgument &) {}
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -267,6 +261,98 @@ namespace BlackMisc
|
||||
class HashByTuple<Derived, false>
|
||||
{};
|
||||
|
||||
/*!
|
||||
* CRTP class template from which a derived class can inherit common methods dealing with marshalling instances by metatuple.
|
||||
*/
|
||||
template <class Derived, bool IsTupleBased = true>
|
||||
class DBusByTuple : private Private::EncapsulationBreaker
|
||||
{
|
||||
public:
|
||||
//! Unmarshalling operator >>, DBus to object
|
||||
friend const QDBusArgument &operator>>(const QDBusArgument &arg, Derived &obj)
|
||||
{
|
||||
arg.beginStructure();
|
||||
obj.unmarshallFromDbus(arg);
|
||||
arg.endStructure();
|
||||
return arg;
|
||||
}
|
||||
|
||||
//! Marshalling operator <<, object to DBus
|
||||
friend QDBusArgument &operator<<(QDBusArgument &arg, const Derived &obj)
|
||||
{
|
||||
arg.beginStructure();
|
||||
obj.marshallToDbus(arg);
|
||||
arg.endStructure();
|
||||
return arg;
|
||||
}
|
||||
|
||||
//! Marshall without begin/endStructure, for when composed within another object
|
||||
void marshallToDbus(QDBusArgument &arg) const
|
||||
{
|
||||
baseMarshall(static_cast<const typename Derived::base_type &>(*derived()), arg);
|
||||
using BlackMisc::operator<<;
|
||||
arg << Private::EncapsulationBreaker::toMetaTuple(*derived());
|
||||
}
|
||||
|
||||
//! Unmarshall without begin/endStructure, for when composed within another object
|
||||
void unmarshallFromDbus(const QDBusArgument &arg)
|
||||
{
|
||||
baseUnmarshall(static_cast<typename Derived::base_type &>(*derived()), arg);
|
||||
using BlackMisc::operator>>;
|
||||
arg >> Private::EncapsulationBreaker::toMetaTuple(*derived());
|
||||
}
|
||||
|
||||
private:
|
||||
const Derived *derived() const { return static_cast<const Derived *>(this); }
|
||||
Derived *derived() { return static_cast<Derived *>(this); }
|
||||
|
||||
template <typename T> static void baseMarshall(const T &base, QDBusArgument &arg) { base.marshallToDbus(arg); }
|
||||
template <typename T> static void baseUnmarshall(T &base, const QDBusArgument &arg) { base.unmarshallFromDbus(arg); }
|
||||
static void baseMarshall(const CEmpty &, QDBusArgument &) {}
|
||||
static void baseUnmarshall(CEmpty &, const QDBusArgument &) {}
|
||||
};
|
||||
|
||||
/*!
|
||||
* Specialization of DBusByTuple for classes not registered with the tuple system.
|
||||
*/
|
||||
template <class Derived>
|
||||
class DBusByTuple<Derived, false>
|
||||
{
|
||||
public:
|
||||
//! Unmarshalling operator >>, DBus to object
|
||||
friend const QDBusArgument &operator>>(const QDBusArgument &arg, Derived &obj)
|
||||
{
|
||||
arg.beginStructure();
|
||||
obj.unmarshallFromDbus(arg);
|
||||
arg.endStructure();
|
||||
return arg;
|
||||
}
|
||||
|
||||
//! Marshalling operator <<, object to DBus
|
||||
friend QDBusArgument &operator<<(QDBusArgument &arg, const Derived &obj)
|
||||
{
|
||||
arg.beginStructure();
|
||||
obj.marshallToDbus(arg);
|
||||
arg.endStructure();
|
||||
return arg;
|
||||
}
|
||||
|
||||
//! Do nothing
|
||||
void marshallToDbus(QDBusArgument &arg) const { baseMarshall(static_cast<const typename Derived::base_type &>(*derived()), arg); }
|
||||
|
||||
//! Do nothing
|
||||
void unmarshallFromDbus(const QDBusArgument &arg) { baseUnmarshall(static_cast<typename Derived::base_type &>(*derived()), arg); }
|
||||
|
||||
private:
|
||||
const Derived *derived() const { return static_cast<const Derived *>(this); }
|
||||
Derived *derived() { return static_cast<Derived *>(this); }
|
||||
|
||||
template <typename T> static void baseMarshall(const T &base, QDBusArgument &arg) { base.marshallToDbus(arg); }
|
||||
template <typename T> static void baseUnmarshall(T &base, const QDBusArgument &arg) { base.unmarshallFromDbus(arg); }
|
||||
static void baseMarshall(const CEmpty &, QDBusArgument &) {}
|
||||
static void baseUnmarshall(CEmpty &, const QDBusArgument &) {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -283,13 +369,13 @@ namespace BlackMisc
|
||||
public Base,
|
||||
public Mixin::MetaType<Derived>,
|
||||
public Mixin::HashByTuple<Derived, Policy::Hash::IsMetaTuple<Derived, Base>::value>,
|
||||
public Mixin::DBusByTuple<Derived, Policy::DBus::IsMetaTuple<Derived, Base>::value>,
|
||||
private CValueObjectPolicy<Derived>::Equals::template Ops<Derived, Base>,
|
||||
private CValueObjectPolicy<Derived>::LessThan::template Ops<Derived, Base>,
|
||||
private CValueObjectPolicy<Derived>::Compare::template Ops<Derived, Base>
|
||||
{
|
||||
static_assert(std::is_same<CEmpty, Base>::value || IsValueObject<Base>::value, "Base must be either CEmpty or derived from CValueObject");
|
||||
|
||||
using DBusPolicy = typename CValueObjectPolicy<Derived>::DBus;
|
||||
using JsonPolicy = typename CValueObjectPolicy<Derived>::Json;
|
||||
using PropertyIndexPolicy = typename CValueObjectPolicy<Derived>::PropertyIndex;
|
||||
|
||||
@@ -330,24 +416,6 @@ namespace BlackMisc
|
||||
return ostr;
|
||||
}
|
||||
|
||||
//! Unmarshalling operator >>, DBus to object
|
||||
friend const QDBusArgument &operator>>(const QDBusArgument &arg, Derived &obj)
|
||||
{
|
||||
arg.beginStructure();
|
||||
static_cast<CValueObject &>(obj).unmarshallFromDbus(arg); // virtual method is protected in Derived
|
||||
arg.endStructure();
|
||||
return arg;
|
||||
}
|
||||
|
||||
//! Marshalling operator <<, object to DBus
|
||||
friend QDBusArgument &operator<<(QDBusArgument &arg, const Derived &obj)
|
||||
{
|
||||
arg.beginStructure();
|
||||
static_cast<const CValueObject &>(obj).marshallToDbus(arg); // virtual method is protected in Derived
|
||||
arg.endStructure();
|
||||
return arg;
|
||||
}
|
||||
|
||||
//! operator >> for JSON
|
||||
friend const QJsonObject &operator>>(const QJsonObject &json, Derived &valueObject)
|
||||
{
|
||||
@@ -480,19 +548,11 @@ namespace BlackMisc
|
||||
using Mixin::MetaType<Derived>::getMetaTypeId;
|
||||
|
||||
public:
|
||||
//! Marshall to DBus
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const
|
||||
{
|
||||
BaseOrDummy::marshallToDbus(argument);
|
||||
DBusPolicy::marshallImpl(argument, *derived());
|
||||
}
|
||||
//! \copydoc BlackMisc::Mixin::DBusByTuple::marshallToDbus
|
||||
using Mixin::DBusByTuple<Derived, Policy::DBus::IsMetaTuple<Derived, Base>::value>::marshallToDbus;
|
||||
|
||||
//! Unmarshall from DBus
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
BaseOrDummy::unmarshallFromDbus(argument);
|
||||
DBusPolicy::unmarshallImpl(argument, *derived());
|
||||
}
|
||||
//! \copydoc BlackMisc::Mixin::DBusByTuple::unmarshallFromDbus
|
||||
using Mixin::DBusByTuple<Derived, Policy::DBus::IsMetaTuple<Derived, Base>::value>::unmarshallFromDbus;
|
||||
|
||||
private:
|
||||
const Derived *derived() const { return static_cast<const Derived *>(this); }
|
||||
|
||||
@@ -339,6 +339,11 @@ namespace BlackMisc
|
||||
template <class T, class...>
|
||||
static void unmarshallImpl(const QDBusArgument &, T &) {}
|
||||
};
|
||||
|
||||
//! \private Detect the policy of T, following inheritance.
|
||||
template <class T, class B, class P = typename CValueObjectPolicy<T>::DBus> struct IsMetaTuple : public std::false_type {};
|
||||
template <class T, class B> struct IsMetaTuple<T, B, MetaTuple> : public std::true_type {};
|
||||
template <class T, class B> struct IsMetaTuple<T, B, Inherit> : public IsMetaTuple<B, typename B::base_type> {};
|
||||
}
|
||||
|
||||
namespace Json
|
||||
|
||||
@@ -185,10 +185,10 @@ namespace BlackMisc
|
||||
virtual void convertFromJson(const QJsonObject &json) override;
|
||||
|
||||
//! \copydoc CValueObject::marshallToDbus
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const override;
|
||||
void marshallToDbus(QDBusArgument &argument) const;
|
||||
|
||||
//! \copydoc CValueObject::unmarshallFromDbus
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
|
||||
void unmarshallFromDbus(const QDBusArgument &argument);
|
||||
|
||||
//! Equal operator.
|
||||
friend bool operator ==(const CVariant &a, const CVariant &b) { return compare(a, b) == 0; }
|
||||
|
||||
Reference in New Issue
Block a user