mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-28 20:25:34 +08:00
Ref T557 Metaclass flag to preserve measurement unit when marshalling PQ's in flight plans.
This commit is contained in:
@@ -22,20 +22,27 @@ namespace BlackMisc
|
||||
{
|
||||
class CEmpty;
|
||||
|
||||
/*!
|
||||
* Tag type signifying overloaded marshalling methods that preserve data at the expense of size.
|
||||
*/
|
||||
class LosslessTag {};
|
||||
|
||||
namespace Private
|
||||
{
|
||||
//! \cond PRIVATE
|
||||
template <class T, std::enable_if_t<THasMarshallMethods<T>::value, int> = 0>
|
||||
void marshallMember(QDBusArgument &arg, const T &value) { value.marshallToDbus(arg); }
|
||||
|
||||
void marshallMember(QDBusArgument &arg, const T &value, std::false_type) { value.marshallToDbus(arg); }
|
||||
template <class T, std::enable_if_t<THasMarshallMethods<T>::value, int> = 0>
|
||||
void marshallMember(QDBusArgument &arg, const T &value, std::true_type) { value.marshallToDbus(arg, LosslessTag()); }
|
||||
template <class T, std::enable_if_t<!THasMarshallMethods<T>::value, int> = 0>
|
||||
void marshallMember(QDBusArgument &arg, const T &value) { arg << value; }
|
||||
void marshallMember(QDBusArgument &arg, const T &value, std::false_type) { arg << value; }
|
||||
|
||||
template <class T, std::enable_if_t<THasMarshallMethods<T>::value, int> = 0>
|
||||
void unmarshallMember(const QDBusArgument &arg, T &value) { value.unmarshallFromDbus(arg); }
|
||||
|
||||
void unmarshallMember(const QDBusArgument &arg, T &value, std::false_type) { value.unmarshallFromDbus(arg); }
|
||||
template <class T, std::enable_if_t<THasMarshallMethods<T>::value, int> = 0>
|
||||
void unmarshallMember(const QDBusArgument &arg, T &value, std::true_type) { value.unmarshallFromDbus(arg, LosslessTag()); }
|
||||
template <class T, std::enable_if_t<!THasMarshallMethods<T>::value, int> = 0>
|
||||
void unmarshallMember(const QDBusArgument &arg, T &value) { arg >> value; }
|
||||
void unmarshallMember(const QDBusArgument &arg, T &value, std::false_type) { arg >> value; }
|
||||
//! \endcond
|
||||
}
|
||||
|
||||
@@ -46,7 +53,7 @@ namespace BlackMisc
|
||||
*
|
||||
* \tparam Derived Must implement public methods void marshallToDbus(QDBusArgument &arg) const and void unmarshallFromDbus(const QDBusArgument &arg).
|
||||
*/
|
||||
template <class Derived>
|
||||
template <class Derived, class...>
|
||||
class DBusOperators
|
||||
{
|
||||
public:
|
||||
@@ -68,38 +75,48 @@ namespace BlackMisc
|
||||
return arg;
|
||||
}
|
||||
};
|
||||
template <class Derived>
|
||||
class DBusOperators<Derived, LosslessTag> {};
|
||||
|
||||
/*!
|
||||
* CRTP class template from which a derived class can inherit common methods dealing with marshalling instances by metaclass.
|
||||
*
|
||||
* \see BLACKMISC_DECLARE_USING_MIXIN_DBUS
|
||||
*/
|
||||
template <class Derived>
|
||||
class DBusByMetaClass : public DBusOperators<Derived>
|
||||
template <class Derived, class... Tags>
|
||||
class DBusByMetaClass : public DBusOperators<Derived, Tags...>
|
||||
{
|
||||
public:
|
||||
//! Marshall without begin/endStructure, for when composed within another object
|
||||
void marshallToDbus(QDBusArgument &arg) const
|
||||
void marshallToDbus(QDBusArgument &arg, Tags...) const
|
||||
{
|
||||
baseMarshall(static_cast<const TBaseOfT<Derived> *>(derived()), arg);
|
||||
auto meta = introspect<Derived>().without(MetaFlags<DisabledForMarshalling>());
|
||||
meta.forEachMember([ &, this ](auto member) { Private::marshallMember(arg, member.in(*this->derived())); });
|
||||
meta.forEachMember([ &, this ](auto member)
|
||||
{
|
||||
using lossless = std::integral_constant<bool, member.has(MetaFlags<LosslessMarshalling>())>;
|
||||
Private::marshallMember(arg, member.in(*this->derived()), lossless());
|
||||
});
|
||||
}
|
||||
|
||||
//! Unmarshall without begin/endStructure, for when composed within another object
|
||||
void unmarshallFromDbus(const QDBusArgument &arg)
|
||||
void unmarshallFromDbus(const QDBusArgument &arg, Tags...)
|
||||
{
|
||||
baseUnmarshall(static_cast<TBaseOfT<Derived> *>(derived()), arg);
|
||||
auto meta = introspect<Derived>().without(MetaFlags<DisabledForMarshalling>());
|
||||
meta.forEachMember([ &, this ](auto member) { Private::unmarshallMember(arg, member.in(*this->derived())); });
|
||||
meta.forEachMember([ &, this ](auto member)
|
||||
{
|
||||
using lossless = std::integral_constant<bool, member.has(MetaFlags<LosslessMarshalling>())>;
|
||||
Private::unmarshallMember(arg, member.in(*this->derived()), lossless());
|
||||
});
|
||||
}
|
||||
|
||||
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); }
|
||||
template <typename T> static void baseMarshall(const T *base, QDBusArgument &arg) { base->marshallToDbus(arg, Tags()...); }
|
||||
template <typename T> static void baseUnmarshall(T *base, const QDBusArgument &arg) { base->unmarshallFromDbus(arg, Tags()...); }
|
||||
static void baseMarshall(const void *, QDBusArgument &) {}
|
||||
static void baseUnmarshall(void *, const QDBusArgument &) {}
|
||||
static void baseMarshall(const CEmpty *, QDBusArgument &) {}
|
||||
@@ -110,9 +127,9 @@ namespace BlackMisc
|
||||
* When a derived class and a base class both inherit from Mixin::DBusByTuple,
|
||||
* the derived class uses this macro to disambiguate the inherited members.
|
||||
*/
|
||||
# define BLACKMISC_DECLARE_USING_MIXIN_DBUS(DERIVED) \
|
||||
using ::BlackMisc::Mixin::DBusByMetaClass<DERIVED>::marshallToDbus; \
|
||||
using ::BlackMisc::Mixin::DBusByMetaClass<DERIVED>::unmarshallFromDbus;
|
||||
# define BLACKMISC_DECLARE_USING_MIXIN_DBUS(DERIVED, ...) \
|
||||
using ::BlackMisc::Mixin::DBusByMetaClass<DERIVED BLACK_TRAILING_VA_ARGS(__VA_ARGS__)>::marshallToDbus; \
|
||||
using ::BlackMisc::Mixin::DBusByMetaClass<DERIVED BLACK_TRAILING_VA_ARGS(__VA_ARGS__)>::unmarshallFromDbus;
|
||||
|
||||
} // Mixin
|
||||
} // BlackMisc
|
||||
|
||||
Reference in New Issue
Block a user