GCC Code Coverage Report


Directory: ./
File: lib/configserializer_p.h
Date: 2023-04-20 22:59:23
Exec Total Coverage
Lines: 5 14 35.7%
Branches: 0 4 0.0%

Line Branch Exec Source
1 /*
2 * Copyright (C) 2014 Daniel Vratil <dvratil@redhat.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 *
18 */
19
20 #ifndef CONFIGSERIALIZER_H
21 #define CONFIGSERIALIZER_H
22
23 #include <QDBusArgument>
24 #include <QJsonArray>
25 #include <QJsonObject>
26 #include <QVariant>
27
28 #include "disman_export.h"
29 #include "output.h"
30 #include "types.h"
31
32 namespace Disman
33 {
34
35 namespace ConfigSerializer
36 {
37
38 DISMAN_EXPORT QJsonObject serialize_point(const QPointF& point);
39 DISMAN_EXPORT QJsonObject serialize_size(const QSize& size);
40 DISMAN_EXPORT QJsonObject serialize_sizef(const QSizeF& size);
41 template<typename T>
42 4 DISMAN_EXPORT QJsonArray serialize_list(const QList<T>& list)
43 {
44 4 QJsonArray arr;
45
0/2
✗ Branch 3 not taken.
✗ Branch 4 not taken.
14 Q_FOREACH (const T& t, list) {
46 10 arr.append(t);
47 }
48 4 return arr;
49 }
50
51 DISMAN_EXPORT QJsonObject serialize_config(const Disman::ConfigPtr& config);
52 DISMAN_EXPORT QJsonObject serialize_output(const Disman::OutputPtr& output);
53 DISMAN_EXPORT QJsonObject serialize_mode(const Disman::ModePtr& mode);
54 DISMAN_EXPORT QJsonObject serialize_screen(const Disman::ScreenPtr& screen);
55
56 DISMAN_EXPORT QPointF deserialize_point(const QDBusArgument& map);
57 DISMAN_EXPORT QSize deserialize_size(const QDBusArgument& map);
58 DISMAN_EXPORT QSizeF deserialize_sizef(const QDBusArgument& map);
59 template<typename T>
60 DISMAN_EXPORT QList<T> deserialize_list(const QDBusArgument& arg)
61 {
62 QList<T> list;
63 arg.beginArray();
64 while (!arg.atEnd()) {
65 QVariant v;
66 arg >> v;
67 list.append(v.value<T>());
68 }
69 arg.endArray();
70 return list;
71 }
72 DISMAN_EXPORT Disman::ConfigPtr deserialize_config(const QVariantMap& map);
73 DISMAN_EXPORT Disman::OutputPtr deserialize_output(const QDBusArgument& output);
74 DISMAN_EXPORT Disman::ModePtr deserialize_mode(const QDBusArgument& mode);
75 DISMAN_EXPORT Disman::ScreenPtr deserialize_screen(const QDBusArgument& screen);
76 DISMAN_EXPORT Disman::Output::Retention deserialize_retention(QVariant const& var);
77
78 }
79
80 }
81
82 #endif
83