swift
dbus.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2014 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_MISC_DBUS_H
7 #define SWIFT_MISC_DBUS_H
8 
9 #include <string>
10 #include <type_traits>
11 
12 #include <QDBusArgument>
13 #include <QFlags>
14 
18 QDBusArgument &operator<<(QDBusArgument &arg, const std::string &s);
19 
23 const QDBusArgument &operator>>(const QDBusArgument &arg, std::string &s);
24 
25 // *INDENT-OFF*
29 template <class E, std::enable_if_t<std::is_enum_v<E>, int> = 0>
30 QDBusArgument &operator<<(QDBusArgument &arg, const E &value)
31 {
32  arg.beginStructure();
33  arg << static_cast<int>(value);
34  arg.endStructure();
35  return arg;
36 }
37 
41 template <class E, std::enable_if_t<std::is_enum_v<E>, int> = 0>
42 const QDBusArgument &operator>>(const QDBusArgument &arg, E &value)
43 {
44  int temp;
45  arg.beginStructure();
46  arg >> temp;
47  arg.endStructure();
48  value = static_cast<E>(temp);
49  return arg;
50 }
51 
55 template <class T>
56 QDBusArgument &operator<<(QDBusArgument &arg, const QFlags<T> &value)
57 {
58  arg.beginStructure();
59  arg << static_cast<typename QFlags<T>::Int>(value);
60  arg.endStructure();
61  return arg;
62 }
63 
67 template <class T>
68 const QDBusArgument &operator>>(const QDBusArgument &arg, QFlags<T> &value)
69 {
70  typename QFlags<T>::Int temp = 0;
71  arg.beginStructure();
72  arg >> temp;
73  arg.endStructure();
74  value = static_cast<QFlags<T>>(temp);
75  return arg;
76 }
77 
78 #endif // SWIFT_MISC_DBUS_H
QDBusArgument & operator<<(QDBusArgument &arg, const std::string &s)
Non member non-friend streaming for std::string.
Definition: dbus.cpp:6
const QDBusArgument & operator>>(const QDBusArgument &arg, std::string &s)
Operator for std::string from QDBusArgument.
Definition: dbus.cpp:14