mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-27 19:25:49 +08:00
refs #413 Stream operator template of CLogPattern supports any class with a toQString method, not just CValueObject subclasses.
This commit is contained in:
@@ -24,6 +24,25 @@
|
|||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
|
/*!
|
||||||
|
* Trait to detect whether T contains a member toQString.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
class HasToQString
|
||||||
|
{
|
||||||
|
// http://en.wikibooks.org/wiki/More_C++_Idioms/Member_Detector
|
||||||
|
struct Fallback { int toQString; };
|
||||||
|
template <int Fallback:: *> struct int_t { typedef int type; };
|
||||||
|
template <typename U, bool = std::is_class<U>::value> struct Derived : public U, public Fallback {};
|
||||||
|
template <typename U> struct Derived<U, false> : public Fallback {};
|
||||||
|
template <typename U> static char test(typename int_t<&Derived<U>::toQString>::type);
|
||||||
|
template <typename U> static int test(...);
|
||||||
|
|
||||||
|
public:
|
||||||
|
//! True if T contains a member toQString.
|
||||||
|
static const bool value = sizeof(test<T>(0)) > 1;
|
||||||
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Helper with static methods for dealing with metadata embedded in log message category strings.
|
* Helper with static methods for dealing with metadata embedded in log message category strings.
|
||||||
*
|
*
|
||||||
@@ -138,7 +157,7 @@ namespace BlackMisc
|
|||||||
CLogMessage &operator <<(QChar v) { return arg(v); }
|
CLogMessage &operator <<(QChar v) { return arg(v); }
|
||||||
CLogMessage &operator <<(char v) { return arg(QChar(v)); }
|
CLogMessage &operator <<(char v) { return arg(QChar(v)); }
|
||||||
CLogMessage &operator <<(double v) { return arg(QString::number(v)); }
|
CLogMessage &operator <<(double v) { return arg(QString::number(v)); }
|
||||||
template <class T, class = typename std::enable_if<IsValueObject<T>::value>::type>
|
template <class T, class = typename std::enable_if<HasToQString<T>::value>::type>
|
||||||
CLogMessage &operator <<(const T &v) { return arg(v.toQString()); }
|
CLogMessage &operator <<(const T &v) { return arg(v.toQString()); }
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user