Debian Codegraph @

src/internal/resolved-dependency.cpp

raw symbols SCIP
1 /*
2 * %injeqt copyright begin%
3 * Copyright 2014 Rafał Malinowski ([email protected])
4 * %injeqt copyright end%
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "resolved-dependency.h"
22
23 #include "internal/interfaces-utils.h"
24
25 #include <cassert>
26
27 namespace injeqt { namespace internal {
28
29 resolved_dependency::resolved_dependency(implementation resolved_with, setter_method setter) :
30 _resolved_with{std::move(resolved_with)},
31 _setter{std::move(setter)}
32 {
33 assert(!_setter.is_empty());
34 assert(_resolved_with.interface_type() == _setter.parameter_type());
35 }
36
37 const implementation & resolved_dependency::resolved_with() const
38 {
39 return _resolved_with;
40 }
41
42 const setter_method & resolved_dependency::setter() const
43 {
44 return _setter;
45 }
46
47 bool resolved_dependency::apply_on(QObject *on)
48 {
49 assert(on != nullptr);
50 assert(implements(type{on->metaObject()}, _setter.object_type()));
51
52 return _setter.invoke(on, _resolved_with.object());
53 }
54
55 bool operator == (const resolved_dependency &x, const resolved_dependency &y)
56 {
57 if (x.resolved_with() != y.resolved_with())
58 return false;
59
60 if (x.setter() != y.setter())
61 return false;
62
63 return true;
64 }
65
66 bool operator != (const resolved_dependency &x, const resolved_dependency &y)
67 {
68 return !(x == y);
69 }
70
71 bool operator < (const resolved_dependency &x, const resolved_dependency &y)
72 {
73 if (x.resolved_with() < y.resolved_with())
74 return true;
75 if (x.resolved_with() > y.resolved_with())
76 return false;
77
78 return x.setter() < y.setter();
79 }
80
81 bool operator > (const resolved_dependency &x, const resolved_dependency &y)
82 {
83 return y < x;
84 }
85
86 bool operator <= (const resolved_dependency &x, const resolved_dependency &y)
87 {
88 return !(y < x);
89 }
90
91 bool operator >= (const resolved_dependency &x, const resolved_dependency &y)
92 {
93 return !(x < y);
94 }
95
96 }}