summaryrefslogtreecommitdiff
path: root/qt_helpers.hpp
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2020-11-16 21:54:50 +0100
committerChristoph Berg <myon@debian.org>2020-11-16 21:54:50 +0100
commit77922fa33547ce24535f2e514c9a112dcb496f18 (patch)
tree9f82b0ee01281b315f43a4c60d678927b4c6ca59 /qt_helpers.hpp
parent7aa3c56b01768ba7d38fccedc17b30a4046b3fbb (diff)
New upstream version 2.3.0~rc2+repackupstream/2.3.0_rc2+repack
Diffstat (limited to 'qt_helpers.hpp')
-rw-r--r--qt_helpers.hpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/qt_helpers.hpp b/qt_helpers.hpp
index aae8c5f0..974cc22e 100644
--- a/qt_helpers.hpp
+++ b/qt_helpers.hpp
@@ -2,6 +2,7 @@
#define QT_HELPERS_HPP_
#include <stdexcept>
+#include <ostream>
#include <QString>
#include <QChar>
@@ -58,6 +59,18 @@ QString::SplitBehavior const SkipEmptyParts = QString::SkipEmptyParts;
#endif
inline
+std::ostream& operator << (std::ostream& os, QByteArray const& b)
+{
+ return os << b.constData ();
+}
+
+inline
+std::ostream& operator << (std::ostream& os, QString const& s)
+{
+ return os << s.toStdString ();
+}
+
+inline
void throw_qstring (QString const& qs)
{
throw std::runtime_error {qs.toLocal8Bit ().constData ()};
@@ -117,6 +130,42 @@ namespace std
}
#endif
+inline
+bool is_broadcast_address (QHostAddress const& host_addr)
+{
+#if QT_VERSION >= QT_VERSION_CHECK (5, 11, 0)
+ return host_addr.isBroadcast ();
+#else
+ bool ok;
+ return host_addr.toIPv4Address (&ok) == 0xffffffffu && ok;
+#endif
+}
+
+inline
+bool is_multicast_address (QHostAddress const& host_addr)
+{
+#if QT_VERSION >= QT_VERSION_CHECK (5, 6, 0)
+ return host_addr.isMulticast ();
+#else
+ bool ok;
+ return (((host_addr.toIPv4Address (&ok) & 0xf0000000u) == 0xe0000000u) && ok)
+ || host_addr.toIPv6Address ()[0] == 0xff;
+#endif
+}
+
+inline
+bool is_MAC_ambiguous_multicast_address (QHostAddress const& host_addr)
+{
+ // sub-ranges 224.128.0.0/24, 225.0.0.0/24, 225.128.0.0/24,
+ // 226.0.0.0/24, 226.128.0.0/24, ..., 239.0.0.0/24, 239.128.0.0/24
+ // are not supported as they are inefficient due to ambiguous
+ // mappings to Ethernet MAC addresses. 224.0.0.0/24 alone is allowed
+ // from these ranges
+ bool ok;
+ auto ipv4 = host_addr.toIPv4Address (&ok);
+ return ok && !((ipv4 & 0xffffff00u) == 0xe0000000) && (ipv4 & 0xf07fff00) == 0xe0000000;
+}
+
// Register some useful Qt types with QMetaType
Q_DECLARE_METATYPE (QHostAddress);