mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 19:05:31 +08:00
Ref T725 Extend CLogMessage to allow ICoordinateGeodetic arguments,
using a system of traits to select the stringifier corresponding to the argument type.
This commit is contained in:
committed by
Klaus Basan
parent
b569040492
commit
07e64099b1
@@ -20,6 +20,7 @@
|
|||||||
#include "blackmisc/math/mathutils.h"
|
#include "blackmisc/math/mathutils.h"
|
||||||
#include "blackmisc/metaclass.h"
|
#include "blackmisc/metaclass.h"
|
||||||
#include "blackmisc/propertyindex.h"
|
#include "blackmisc/propertyindex.h"
|
||||||
|
#include "blackmisc/stringutils.h"
|
||||||
#include "blackmisc/valueobject.h"
|
#include "blackmisc/valueobject.h"
|
||||||
#include "blackmisc/variant.h"
|
#include "blackmisc/variant.h"
|
||||||
#include "blackmisc/blackmiscexport.h"
|
#include "blackmisc/blackmiscexport.h"
|
||||||
@@ -135,9 +136,6 @@ namespace BlackMisc
|
|||||||
//! \copydoc Mixin::String::toQString
|
//! \copydoc Mixin::String::toQString
|
||||||
QString convertToQString(bool i18n = false) const;
|
QString convertToQString(bool i18n = false) const;
|
||||||
|
|
||||||
//! \copydoc Mixin::String::toQString
|
|
||||||
// QString toQString(bool i18n = false) const { return this->convertToQString(i18n); }
|
|
||||||
|
|
||||||
//! Check values @{
|
//! Check values @{
|
||||||
bool isNaNVector() const;
|
bool isNaNVector() const;
|
||||||
bool isNaNVectorDouble() const;
|
bool isNaNVectorDouble() const;
|
||||||
@@ -353,6 +351,14 @@ namespace BlackMisc
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
//! \cond
|
||||||
|
template <>
|
||||||
|
struct TString<Geo::ICoordinateGeodetic>
|
||||||
|
{
|
||||||
|
static QString toQString(const Geo::ICoordinateGeodetic &coord) { return coord.convertToQString(); }
|
||||||
|
};
|
||||||
|
//! \endcond
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(BlackMisc::Geo::CCoordinateGeodetic)
|
Q_DECLARE_METATYPE(BlackMisc::Geo::CCoordinateGeodetic)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "orderable.h"
|
#include "orderable.h"
|
||||||
#include "icon.h"
|
#include "icon.h"
|
||||||
#include "propertyindex.h"
|
#include "propertyindex.h"
|
||||||
|
#include "stringutils.h"
|
||||||
#include "typetraits.h"
|
#include "typetraits.h"
|
||||||
#include "blackmiscexport.h"
|
#include "blackmiscexport.h"
|
||||||
|
|
||||||
@@ -234,22 +235,10 @@ namespace BlackMisc
|
|||||||
//! Otherwise, the streamed values will replace the place markers %1, %2, %3... in the format string.
|
//! Otherwise, the streamed values will replace the place markers %1, %2, %3... in the format string.
|
||||||
//! \see QString::arg
|
//! \see QString::arg
|
||||||
//! @{
|
//! @{
|
||||||
Derived &operator <<(const QString &v) { return arg(v); }
|
template <class T, std::enable_if_t<TParameter<std::decay_t<T>>::passBy == ParameterPassBy::Value, int> = 0>
|
||||||
Derived &operator <<(const QStringRef &v) { return arg(v.toString()); }
|
Derived &operator <<(T v) { return arg(TString<T>::toQString(v)); }
|
||||||
Derived &operator <<(QStringView v) { return arg(v.toString()); }
|
template <class T, std::enable_if_t<TParameter<std::decay_t<T>>::passBy == ParameterPassBy::ConstRef, int> = 0>
|
||||||
Derived &operator <<(int v) { return arg(QString::number(v)); }
|
Derived &operator <<(const T &v) { return arg(TString<T>::toQString(v)); }
|
||||||
Derived &operator <<(uint v) { return arg(QString::number(v)); }
|
|
||||||
Derived &operator <<(long v) { return arg(QString::number(v)); }
|
|
||||||
Derived &operator <<(ulong v) { return arg(QString::number(v)); }
|
|
||||||
Derived &operator <<(qlonglong v) { return arg(QString::number(v)); }
|
|
||||||
Derived &operator <<(qulonglong v) { return arg(QString::number(v)); }
|
|
||||||
Derived &operator <<(short v) { return arg(QString::number(v)); }
|
|
||||||
Derived &operator <<(ushort v) { return arg(QString::number(v)); }
|
|
||||||
Derived &operator <<(QChar v) { return arg(v); }
|
|
||||||
Derived &operator <<(char v) { return arg(QChar(v)); }
|
|
||||||
Derived &operator <<(double v) { return arg(QString::number(v)); }
|
|
||||||
template <class T, class = std::enable_if_t<THasToQString<T>::value>>
|
|
||||||
Derived & operator <<(const T &v) { return arg(v.toQString()); }
|
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
//! Message empty
|
//! Message empty
|
||||||
|
|||||||
@@ -13,19 +13,23 @@
|
|||||||
|
|
||||||
#include "blackmisc/blackmiscexport.h"
|
#include "blackmisc/blackmiscexport.h"
|
||||||
#include "blackmisc/range.h"
|
#include "blackmisc/range.h"
|
||||||
|
#include "blackmisc/typetraits.h"
|
||||||
|
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QFlags>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QMapIterator>
|
#include <QMapIterator>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringRef>
|
#include <QStringRef>
|
||||||
|
#include <QStringView>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
#include <atomic>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -372,6 +376,99 @@ namespace BlackMisc
|
|||||||
using ::BlackMisc::Mixin::String<DERIVED>::stringForStreaming;
|
using ::BlackMisc::Mixin::String<DERIVED>::stringForStreaming;
|
||||||
// *INDENT-ON*
|
// *INDENT-ON*
|
||||||
} // ns
|
} // ns
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Stringification traits class.
|
||||||
|
*/
|
||||||
|
template <typename T, typename = void> struct TString;
|
||||||
|
|
||||||
|
// Stringification traits specializations.
|
||||||
|
//! \cond
|
||||||
|
template <> struct TString<QString>
|
||||||
|
{
|
||||||
|
static QString toQString(const QString &s) { return s; }
|
||||||
|
};
|
||||||
|
template <> struct TString<QStringRef>
|
||||||
|
{
|
||||||
|
static QString toQString(const QStringRef &sr) { return sr.toString(); }
|
||||||
|
};
|
||||||
|
template <> struct TString<QStringView>
|
||||||
|
{
|
||||||
|
static QString toQString(QStringView sv) { return sv.toString(); }
|
||||||
|
};
|
||||||
|
template <> struct TString<QChar>
|
||||||
|
{
|
||||||
|
static QString toQString(QChar c) { return c; }
|
||||||
|
};
|
||||||
|
template <> struct TString<char>
|
||||||
|
{
|
||||||
|
static QString toQString(char c) { return QChar(c); }
|
||||||
|
};
|
||||||
|
template <> struct TString<bool>
|
||||||
|
{
|
||||||
|
static QString toQString(bool n) { return QString::number(n); }
|
||||||
|
};
|
||||||
|
template <> struct TString<int>
|
||||||
|
{
|
||||||
|
static QString toQString(int n) { return QString::number(n); }
|
||||||
|
};
|
||||||
|
template <> struct TString<uint>
|
||||||
|
{
|
||||||
|
static QString toQString(uint n) { return QString::number(n); }
|
||||||
|
};
|
||||||
|
template <> struct TString<long>
|
||||||
|
{
|
||||||
|
static QString toQString(long n) { return QString::number(n); }
|
||||||
|
};
|
||||||
|
template <> struct TString<ulong>
|
||||||
|
{
|
||||||
|
static QString toQString(ulong n) { return QString::number(n); }
|
||||||
|
};
|
||||||
|
template <> struct TString<qlonglong>
|
||||||
|
{
|
||||||
|
static QString toQString(qlonglong n) { return QString::number(n); }
|
||||||
|
};
|
||||||
|
template <> struct TString<qulonglong>
|
||||||
|
{
|
||||||
|
static QString toQString(qulonglong n) { return QString::number(n); }
|
||||||
|
};
|
||||||
|
template <> struct TString<short>
|
||||||
|
{
|
||||||
|
static QString toQString(short n) { return QString::number(n); }
|
||||||
|
};
|
||||||
|
template <> struct TString<ushort>
|
||||||
|
{
|
||||||
|
static QString toQString(ushort n) { return QString::number(n); }
|
||||||
|
};
|
||||||
|
template <> struct TString<float>
|
||||||
|
{
|
||||||
|
static QString toQString(float n) { return QString::number(n); }
|
||||||
|
};
|
||||||
|
template <> struct TString<double>
|
||||||
|
{
|
||||||
|
static QString toQString(double n) { return QString::number(n); }
|
||||||
|
};
|
||||||
|
template <typename T> struct TString<T, std::enable_if_t<std::is_enum<T>::value>>
|
||||||
|
{
|
||||||
|
static QString toQString(T e) { return QString::number(e); }
|
||||||
|
};
|
||||||
|
template <typename T> struct TString<T, std::enable_if_t<std::is_convertible<T, QString>::value>>
|
||||||
|
{
|
||||||
|
static QString toQString(const T &v) { return v; }
|
||||||
|
};
|
||||||
|
template <typename T> struct TString<T, std::enable_if_t<THasToQString<T>::value>>
|
||||||
|
{
|
||||||
|
static QString toQString(const T &v) { return v.toQString(); }
|
||||||
|
};
|
||||||
|
template <typename T> struct TString<QFlags<T>>
|
||||||
|
{
|
||||||
|
static QString toQString(QFlags<T> n) { return TString<typename QFlags<T>::Int>::toQString(n); }
|
||||||
|
};
|
||||||
|
template <typename T> struct TString<std::atomic<T>>
|
||||||
|
{
|
||||||
|
static QString toQString(const std::atomic<T> &n) { return TString<T>::toQString(n); }
|
||||||
|
};
|
||||||
|
//! \endcond
|
||||||
} // ns
|
} // ns
|
||||||
|
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
@@ -52,6 +52,25 @@ namespace BlackMisc
|
|||||||
//! \endcond
|
//! \endcond
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Whether an input parameter type should be passed by value or by const reference.
|
||||||
|
*/
|
||||||
|
enum class ParameterPassBy
|
||||||
|
{
|
||||||
|
Value,
|
||||||
|
ConstRef
|
||||||
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Trait to detect properties of function parameter types.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
struct TParameter
|
||||||
|
{
|
||||||
|
//! Whether the input parameter type T should be passed by value or by const reference.
|
||||||
|
static constexpr ParameterPassBy passBy = (sizeof(T) <= 16 && std::is_trivially_copy_constructible<T>::value && std::is_trivially_destructible<T>::value) ? ParameterPassBy::Value : ParameterPassBy::ConstRef;
|
||||||
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Trait to detect whether T contains a member function toQString.
|
* Trait to detect whether T contains a member function toQString.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user