mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 09:15:34 +08:00
@@ -15,6 +15,7 @@
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/metaclass.h"
|
||||
#include "blackmisc/inheritancetraits.h"
|
||||
#include "blackmisc/typetraits.h"
|
||||
#include <QDBusArgument>
|
||||
#include <type_traits>
|
||||
|
||||
@@ -22,6 +23,23 @@ namespace BlackMisc
|
||||
{
|
||||
class CEmpty;
|
||||
|
||||
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); }
|
||||
|
||||
template <class T, std::enable_if_t<!THasMarshallMethods<T>::value, int> = 0>
|
||||
void marshallMember(QDBusArgument &arg, const T &value) { arg << value; }
|
||||
|
||||
template <class T, std::enable_if_t<THasMarshallMethods<T>::value, int> = 0>
|
||||
void unmarshallMember(const QDBusArgument &arg, T &value) { value.unmarshallFromDbus(arg); }
|
||||
|
||||
template <class T, std::enable_if_t<!THasMarshallMethods<T>::value, int> = 0>
|
||||
void unmarshallMember(const QDBusArgument &arg, T &value) { arg >> value; }
|
||||
//! \endcond
|
||||
}
|
||||
|
||||
namespace Mixin
|
||||
{
|
||||
/*!
|
||||
@@ -66,7 +84,7 @@ namespace BlackMisc
|
||||
{
|
||||
baseMarshall(static_cast<const TBaseOfT<Derived> *>(derived()), arg);
|
||||
auto meta = introspect<Derived>().without(MetaFlags<DisabledForMarshalling>());
|
||||
meta.forEachMember(*derived(), [ & ](const auto &member) { arg << member; });
|
||||
meta.forEachMember(*derived(), [ & ](const auto &member) { Private::marshallMember(arg, member); });
|
||||
}
|
||||
|
||||
//! Unmarshall without begin/endStructure, for when composed within another object
|
||||
@@ -74,7 +92,7 @@ namespace BlackMisc
|
||||
{
|
||||
baseUnmarshall(static_cast<TBaseOfT<Derived> *>(derived()), arg);
|
||||
auto meta = introspect<Derived>().without(MetaFlags<DisabledForMarshalling>());
|
||||
meta.forEachMember(*derived(), [ & ](auto &member) { arg >> member; });
|
||||
meta.forEachMember(*derived(), [ & ](auto &member) { Private::unmarshallMember(arg, member); });
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#define BLACK_HAS_FIXED_CWG1558
|
||||
#endif
|
||||
|
||||
class QDBusArgument;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
@@ -181,6 +183,17 @@ namespace BlackMisc
|
||||
struct TIsEqualityComparable<T, U, void_t<decltype(std::declval<T>() == std::declval<U>())>> : public std::true_type {};
|
||||
//! \endcond
|
||||
|
||||
/*!
|
||||
* Trait which is true if T has methods marshallToDbus and unmarshallFromDbus.
|
||||
*/
|
||||
template <typename T, typename = void_t<>>
|
||||
struct THasMarshallMethods : public std::false_type {};
|
||||
//! \cond
|
||||
template <typename T>
|
||||
struct THasMarshallMethods<T, void_t<decltype(std::declval<const T &>().marshallToDbus(std::declval<QDBusArgument &>()),
|
||||
std::declval<T &>().unmarshallFromDbus(std::declval<const QDBusArgument &>()))>> : public std::true_type {};
|
||||
//! \endcond
|
||||
|
||||
/*!
|
||||
* Trait that detects if a type is a member of a parameter pack.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user