6 #ifndef SWIFT_MISC_MIXIN_MIXINSTRING_H
7 #define SWIFT_MISC_MIXIN_MIXINSTRING_H
15 #include <QTextStream>
27 template <
class Derived>
32 friend QDebug
operator<<(QDebug debug,
const Derived &obj)
34 debug << obj.stringForStreaming();
39 friend QNoDebug
operator<<(QNoDebug nodebug,
const Derived &obj)
46 friend QTextStream &
operator<<(QTextStream &stream,
const Derived &obj)
48 stream << obj.stringForStreaming();
53 friend std::ostream &
operator<<(std::ostream &ostr,
const Derived &obj)
55 ostr << obj.stringForStreaming().toStdString();
69 const Derived *derived()
const;
73 template <
class Derived>
76 return derived()->convertToQString(i18n);
79 template <
class Derived>
82 return derived()->convertToQString(i18n).toStdString();
85 template <
class Derived>
88 return derived()->convertToQString();
91 template <
class Derived>
94 return static_cast<const Derived *
>(
this);
97 template <
class Derived>
98 Derived *String<Derived>::derived()
100 return static_cast<Derived *
>(
this);
108 #define SWIFT_MISC_DECLARE_USING_MIXIN_STRING(DERIVED) \
109 using ::swift::misc::mixin::String<DERIVED>::toQString; \
110 using ::swift::misc::mixin::String<DERIVED>::toStdString; \
111 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.