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 
28 template <class E, std::enable_if_t<std::is_enum_v<E>, int> = 0>
29 QDBusArgument &operator<<(QDBusArgument &arg, const E &value)
30 {
31  arg.beginStructure();
32  arg << static_cast<int>(value);
33  arg.endStructure();
34  return arg;
35 }
36 
40 template <class E, std::enable_if_t<std::is_enum_v<E>, int> = 0>
41 const QDBusArgument &operator>>(const QDBusArgument &arg, E &value)
42 {
43  int temp;
44  arg.beginStructure();
45  arg >> temp;
46  arg.endStructure();
47  value = static_cast<E>(temp);
48  return arg;
49 }
50 
54 template <class T>
56 {
57  arg.beginStructure();
58  arg << static_cast<typename QFlags<T>::Int>(value);
59  arg.endStructure();
60  return arg;
61 }
62 
66 template <class T>
67 const QDBusArgument &operator>>(const QDBusArgument &arg, QFlags<T> &value)
68 {
69  typename QFlags<T>::Int temp = 0;
70  arg.beginStructure();
71  arg >> temp;
72  arg.endStructure();
73  value = static_cast<QFlags<T>>(temp);
74  return arg;
75 }
76 
77 #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