mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
Ref T709, in order to use BLACK_METAMEMBER(dBusServer) with std::string added all opertors
This commit is contained in:
committed by
Mat Sutcliffe
parent
81c832457e
commit
246ed0d955
@@ -31,3 +31,21 @@ void preventQtDBusDllUnload()
|
||||
void preventQtDBusDllUnload()
|
||||
{ }
|
||||
#endif
|
||||
|
||||
QDBusArgument &operator <<(QDBusArgument &arg, const std::string &s)
|
||||
{
|
||||
arg.beginStructure();
|
||||
arg << QString::fromStdString(s);
|
||||
arg.endStructure();
|
||||
return arg;
|
||||
}
|
||||
|
||||
const QDBusArgument &operator >>(const QDBusArgument &arg, std::string &s)
|
||||
{
|
||||
QString qs;
|
||||
arg.beginStructure();
|
||||
arg >> qs;
|
||||
arg.endStructure();
|
||||
s = qs.toStdString();
|
||||
return arg;
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
#ifndef BLACKMISC_DBUS_H
|
||||
#define BLACKMISC_DBUS_H
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/metaclass.h"
|
||||
#include "blackmisc/inheritancetraits.h"
|
||||
#include "blackmisc/typetraits.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include <QDBusArgument>
|
||||
#include <type_traits>
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace BlackMisc
|
||||
*/
|
||||
class LosslessTag {};
|
||||
|
||||
// *INDENT-OFF*
|
||||
namespace Private
|
||||
{
|
||||
//! \cond PRIVATE
|
||||
@@ -45,6 +46,7 @@ namespace BlackMisc
|
||||
void unmarshallMember(const QDBusArgument &arg, T &value, std::false_type) { arg >> value; }
|
||||
//! \endcond
|
||||
}
|
||||
// *INDENT-ON*
|
||||
|
||||
namespace Mixin
|
||||
{
|
||||
@@ -123,6 +125,7 @@ namespace BlackMisc
|
||||
static void baseUnmarshall(CEmpty *, const QDBusArgument &) {}
|
||||
};
|
||||
|
||||
// *INDENT-OFF*
|
||||
/*!
|
||||
* When a derived class and a base class both inherit from Mixin::DBusByTuple,
|
||||
* the derived class uses this macro to disambiguate the inherited members.
|
||||
@@ -130,10 +133,22 @@ namespace BlackMisc
|
||||
# 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;
|
||||
// *INDENT-ON*
|
||||
|
||||
} // Mixin
|
||||
} // BlackMisc
|
||||
|
||||
/*!
|
||||
* Non member non-friend streaming for std::string
|
||||
*/
|
||||
QDBusArgument &operator <<(QDBusArgument &arg, const std::string &s);
|
||||
|
||||
/*!
|
||||
* Operator for std::string from QDBusArgument.
|
||||
*/
|
||||
const QDBusArgument &operator >>(const QDBusArgument &arg, std::string &s);
|
||||
|
||||
// *INDENT-OFF*
|
||||
/*!
|
||||
* Operator for streaming enums to QDBusArgument.
|
||||
*/
|
||||
@@ -209,16 +224,13 @@ const QDBusArgument &operator >>(const QDBusArgument &arg, std::pair<A, B> &pair
|
||||
arg.endStructure();
|
||||
return arg;
|
||||
}
|
||||
// *INDENT-ON*
|
||||
|
||||
/*!
|
||||
* Non member non-friend streaming for QPixmap
|
||||
*/
|
||||
const QDBusArgument &operator>>(const QDBusArgument &argument, QPixmap &pixmap);
|
||||
|
||||
/*!
|
||||
* Non member non-friend streaming for QPixmap
|
||||
*/
|
||||
QDBusArgument &operator<<(QDBusArgument &argument, const QPixmap &pixmap);
|
||||
// const QDBusArgument &operator>>(const QDBusArgument &argument, QPixmap &pixmap);
|
||||
// QDBusArgument &operator<<(QDBusArgument &argument, const QPixmap &pixmap);
|
||||
|
||||
//! Windows: prevents unloading of QtDBus shared library until the process is terminated.
|
||||
//! QtDBus must have been loaded already by the calling process.
|
||||
|
||||
@@ -55,6 +55,12 @@ const QJsonValue &operator >>(const QJsonValue &json, QString &value)
|
||||
return json;
|
||||
}
|
||||
|
||||
const QJsonValue &operator >>(const QJsonValue &json, std::string &value)
|
||||
{
|
||||
value = json.toString().toStdString();
|
||||
return json;
|
||||
}
|
||||
|
||||
const QJsonValue &operator >>(const QJsonValue &json, QStringList &value)
|
||||
{
|
||||
for (auto &&element : json.toArray()) { value << element.toString(); }
|
||||
@@ -129,6 +135,12 @@ QJsonValueRef operator >>(QJsonValueRef json, QString &value)
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonValueRef operator >>(QJsonValueRef json, std::string &value)
|
||||
{
|
||||
value = json.toString().toStdString();
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonValueRef operator >>(QJsonValueRef json, QStringList &value)
|
||||
{
|
||||
for (auto &&element : json.toArray()) { value << element.toString(); }
|
||||
@@ -203,6 +215,12 @@ QJsonArray &operator<<(QJsonArray &json, const QString &value)
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonArray &operator<<(QJsonArray &json, const std::string &value)
|
||||
{
|
||||
json.append(QJsonValue(QString::fromStdString(value)));
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonArray &operator<<(QJsonArray &json, const double value)
|
||||
{
|
||||
json.append(QJsonValue(value));
|
||||
@@ -271,6 +289,12 @@ QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const QStrin
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const std::string &> &value)
|
||||
{
|
||||
json[value.first] = QJsonValue(QString::fromStdString(value.second));
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const QStringList &> &value)
|
||||
{
|
||||
json.insert(value.first, QJsonValue(QJsonArray::fromStringList(value.second)));
|
||||
@@ -345,6 +369,12 @@ QJsonObject &operator<<(QJsonObject &json, const std::pair<CExplicitLatin1String
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<CExplicitLatin1String, const std::string &> &value)
|
||||
{
|
||||
json[value.first] = QJsonValue(QString::fromStdString(value.second));
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<CExplicitLatin1String, const QStringList &> &value)
|
||||
{
|
||||
json[value.first] = QJsonValue(QJsonArray::fromStringList(value.second));
|
||||
@@ -635,3 +665,6 @@ namespace BlackMisc
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
QDataStream &operator<<(QDataStream &s, const std::string &v) { s << QString::fromStdString(v); return s; }
|
||||
QDataStream &operator>>(QDataStream &s, std::string &v) { QString vs; s >> vs; v = vs.toStdString(); return s; }
|
||||
|
||||
@@ -67,6 +67,7 @@ BLACKMISC_EXPORT const QJsonValue &operator >>(const QJsonValue &json, uint &val
|
||||
BLACKMISC_EXPORT const QJsonValue &operator >>(const QJsonValue &json, qint16 &value);
|
||||
BLACKMISC_EXPORT const QJsonValue &operator >>(const QJsonValue &json, QString &value);
|
||||
BLACKMISC_EXPORT const QJsonValue &operator >>(const QJsonValue &json, QStringList &value);
|
||||
BLACKMISC_EXPORT const QJsonValue &operator >>(const QJsonValue &json, std::string &value);
|
||||
BLACKMISC_EXPORT const QJsonValue &operator >>(const QJsonValue &json, double &value);
|
||||
BLACKMISC_EXPORT const QJsonValue &operator >>(const QJsonValue &json, bool &value);
|
||||
BLACKMISC_EXPORT const QJsonValue &operator >>(const QJsonValue &json, QDateTime &value);
|
||||
@@ -78,6 +79,7 @@ BLACKMISC_EXPORT QJsonValueRef operator >>(QJsonValueRef json, qulonglong &value
|
||||
BLACKMISC_EXPORT QJsonValueRef operator >>(QJsonValueRef json, uint &value);
|
||||
BLACKMISC_EXPORT QJsonValueRef operator >>(QJsonValueRef json, qint16 &value);
|
||||
BLACKMISC_EXPORT QJsonValueRef operator >>(QJsonValueRef json, QString &value);
|
||||
BLACKMISC_EXPORT QJsonValueRef operator >>(QJsonValueRef json, std::string &value);
|
||||
BLACKMISC_EXPORT QJsonValueRef operator >>(QJsonValueRef json, QStringList &value);
|
||||
BLACKMISC_EXPORT QJsonValueRef operator >>(QJsonValueRef json, double &value);
|
||||
BLACKMISC_EXPORT QJsonValueRef operator >>(QJsonValueRef json, bool &value);
|
||||
@@ -188,6 +190,7 @@ BLACKMISC_EXPORT QJsonArray &operator<<(QJsonArray &json, const qlonglong value)
|
||||
BLACKMISC_EXPORT QJsonArray &operator<<(QJsonArray &json, const uint value);
|
||||
BLACKMISC_EXPORT QJsonArray &operator<<(QJsonArray &json, const qulonglong value);
|
||||
BLACKMISC_EXPORT QJsonArray &operator<<(QJsonArray &json, const QString &value);
|
||||
BLACKMISC_EXPORT QJsonArray &operator<<(QJsonArray &json, const std::string &value);
|
||||
BLACKMISC_EXPORT QJsonArray &operator<<(QJsonArray &json, const double value);
|
||||
BLACKMISC_EXPORT QJsonArray &operator<<(QJsonArray &json, const bool value);
|
||||
BLACKMISC_EXPORT QJsonArray &operator<<(QJsonArray &json, const QDateTime &value);
|
||||
@@ -204,6 +207,7 @@ BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<QStr
|
||||
BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const uint &> &value);
|
||||
BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const qulonglong &> &value);
|
||||
BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const QString &> &value);
|
||||
BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const std::string &> &value);
|
||||
BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const QStringList &> &value);
|
||||
BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const double &> &value);
|
||||
BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const bool &> &value);
|
||||
@@ -216,6 +220,7 @@ BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<Blac
|
||||
BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<BlackMisc::CExplicitLatin1String, const uint &> &value);
|
||||
BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<BlackMisc::CExplicitLatin1String, const qulonglong &> &value);
|
||||
BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<BlackMisc::CExplicitLatin1String, const QString &> &value);
|
||||
BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<BlackMisc::CExplicitLatin1String, const std::string &> &value);
|
||||
BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<BlackMisc::CExplicitLatin1String, const QStringList &> &value);
|
||||
BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<BlackMisc::CExplicitLatin1String, const double &> &value);
|
||||
BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<BlackMisc::CExplicitLatin1String, const bool &> &value);
|
||||
@@ -224,6 +229,13 @@ BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<Blac
|
||||
BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<BlackMisc::CExplicitLatin1String, const QByteArray &> &value);
|
||||
//! @}
|
||||
|
||||
//! \name Streaming operators for QDataStream
|
||||
//! \ingroup JSON
|
||||
//! @{
|
||||
QDataStream &operator<<(QDataStream &s, const std::string &v);
|
||||
QDataStream &operator>>(QDataStream &s, std::string &v);
|
||||
//! @}
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
class CEmpty;
|
||||
|
||||
@@ -13,9 +13,10 @@
|
||||
|
||||
#include "blackmisc/invoke.h"
|
||||
#include "blackmisc/integersequence.h"
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
#include <type_traits>
|
||||
#include <functional>
|
||||
#include <QString>
|
||||
|
||||
/*!
|
||||
* \defgroup MetaClass Metaclass system
|
||||
@@ -42,6 +43,7 @@
|
||||
|
||||
//! \endcond
|
||||
|
||||
// *INDENT-OFF*
|
||||
/*!
|
||||
* Macro to define a nested metaclass that describes the attributes of its
|
||||
* enclosing class. Use in the private section of the class.
|
||||
@@ -88,12 +90,19 @@
|
||||
makeMetaMember( \
|
||||
&Class::m_##MEMBER, NAME BLACK_TRAILING_VA_ARGS(__VA_ARGS__) \
|
||||
)
|
||||
// *INDENT-ON*
|
||||
|
||||
//! std::string qHash
|
||||
//! @{
|
||||
inline uint qHash(const std::string &key, uint seed) { return qHash(QString::fromStdString(key), seed); }
|
||||
inline uint qHash(const std::string &key) { return qHash(QString::fromStdString(key)); }
|
||||
//! @}
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
class CVariant;
|
||||
|
||||
// *INDENT-OFF*
|
||||
/*!
|
||||
* Type wrapper for passing MetaFlag to CMetaClassIntrospector::with and CMetaClassIntrospector::without.
|
||||
* \ingroup MetaClass
|
||||
@@ -174,6 +183,7 @@ namespace BlackMisc
|
||||
return std::get<I>(m_members);
|
||||
}
|
||||
};
|
||||
// *INDENT-ON*
|
||||
|
||||
/*!
|
||||
* Metadata flags attached to members of a meta class.
|
||||
@@ -181,13 +191,13 @@ namespace BlackMisc
|
||||
*/
|
||||
enum MetaFlag
|
||||
{
|
||||
DisabledForComparison = 1 << 0, //!< Element will be ignored by compare() and comparison operators
|
||||
DisabledForMarshalling = 1 << 1, //!< Element will be ignored during DBus and QDataStream marshalling
|
||||
DisabledForDebugging = 1 << 2, //!< Element will be ignored when streaming to QDebug
|
||||
DisabledForHashing = 1 << 3, //!< Element will be ignored by qHash()
|
||||
DisabledForJson = 1 << 4, //!< Element will be ignored during JSON serialization
|
||||
DisabledForComparison = 1 << 0, //!< Element will be ignored by compare() and comparison operators
|
||||
DisabledForMarshalling = 1 << 1, //!< Element will be ignored during DBus and QDataStream marshalling
|
||||
DisabledForDebugging = 1 << 2, //!< Element will be ignored when streaming to QDebug
|
||||
DisabledForHashing = 1 << 3, //!< Element will be ignored by qHash()
|
||||
DisabledForJson = 1 << 4, //!< Element will be ignored during JSON serialization
|
||||
CaseInsensitiveComparison = 1 << 5, //!< Element will be compared case insensitively (must be a QString)
|
||||
LosslessMarshalling = 1 << 6 //!< Element marshalling will preserve data at the expense of size
|
||||
LosslessMarshalling = 1 << 6 //!< Element marshalling will preserve data at the expense of size
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -227,6 +237,7 @@ namespace BlackMisc
|
||||
}
|
||||
};
|
||||
|
||||
// *INDENT-OFF*
|
||||
/*!
|
||||
* Implementation of an introspector for the metaclass of T.
|
||||
* Obtain an instance of this class via BlackMisc::introspect.
|
||||
@@ -271,6 +282,7 @@ namespace BlackMisc
|
||||
// Trailing return type needed to work around MSVC "function returning auto can not be used before it has been defined" with /permissive-
|
||||
constexpr static auto members() -> decltype(MetaClass::getMemberList()) { return MetaClass::getMemberList(); }
|
||||
};
|
||||
// *INDENT-ON*
|
||||
|
||||
namespace Private
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user