6 #ifndef SWIFT_MISC_MIXIN_MIXINSTRING_H
7 #define SWIFT_MISC_MIXIN_MIXINSTRING_H
16 #include <QStringView>
17 #include <QTextStream>
29 template <
class Derived>
34 friend QDebug
operator<<(QDebug debug,
const Derived &obj)
36 debug << obj.stringForStreaming();
41 friend QNoDebug
operator<<(QNoDebug nodebug,
const Derived &obj)
48 friend QTextStream &
operator<<(QTextStream &stream,
const Derived &obj)
50 stream << obj.stringForStreaming();
55 friend std::ostream &
operator<<(std::ostream &ostr,
const Derived &obj)
57 ostr << obj.stringForStreaming().toStdString();
71 const Derived *derived()
const;
75 template <
class Derived>
78 return derived()->convertToQString(i18n);
81 template <
class Derived>
84 return derived()->convertToQString(i18n).toStdString();
87 template <
class Derived>
90 return derived()->convertToQString();
93 template <
class Derived>
96 return static_cast<const Derived *
>(
this);
99 template <
class Derived>
100 Derived *String<Derived>::derived()
102 return static_cast<Derived *
>(
this);
110 #define SWIFT_MISC_DECLARE_USING_MIXIN_STRING(DERIVED) \
111 using ::swift::misc::mixin::String<DERIVED>::toQString; \
112 using ::swift::misc::mixin::String<DERIVED>::toStdString; \
113 using ::swift::misc::mixin::String<DERIVED>::stringForStreaming;
CRTP class template from which a derived class can inherit string streaming operations.
friend std::ostream & operator<<(std::ostream &ostr, const Derived &obj)
Stream operator << for std::cout.
QString stringForStreaming() const
String for streaming operators.
QString toQString(bool i18n=false) const
Cast as QString.
friend QNoDebug operator<<(QNoDebug nodebug, const Derived &obj)
Operator << when there is no debug stream.
friend QTextStream & operator<<(QTextStream &stream, const Derived &obj)
Operator << based on text stream.
std::string toStdString(bool i18n=false) const
To std string.
friend QDebug operator<<(QDebug debug, const Derived &obj)
Stream << overload to be used in debugging messages.
Mixin classes which implement common operations for value classes.