Debian Codegraph @

src/internal/resolved-dependency.h

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 #pragma once
22
23 #include <injeqt/injeqt.h>
24
25 #include "implementation.h"
26 #include "internal.h"
27 #include "setter-method.h"
28
29 /**
30 * @file
31 * @brief Contains classes and functions for resolved dependencies.
32 */
33
34 namespace injeqt { namespace internal {
35
36 /**
37 * @brief Abstraction of Injeqt resolved dependency.
38 *
39 * Resolved dependency consists of implementation and a setter_method. To resolve dependency
40 * on an object call apply_on(QObject *) method. To get instances of resolved_dependency call
41 * resolve_dependencies(const dependencies &, const implementations &). This class is currently
42 * only used in injector_core.
43 */
44 class INJEQT_INTERNAL_API resolved_dependency final
45 {
46
47 public:
48 /**
49 * @brief Create new resolved_dependency object.
50 * @param resolved_with object that resolve dependency
51 * @param setter setter_method that can be used to resolve dependency on an object instance
52 * @pre !setter.is_empty()
53 * @pre resolved_with.interface_type() == setter.parameter_type()
54 */
55 explicit resolved_dependency(implementation resolved_with, setter_method setter);
56
57 /**
58 * @return object that resolve dependency.
59 */
60 const implementation & resolved_with() const;
61
62 /**
63 * @return setter method used to resolve dependency on an object instance.
64 */
65 const setter_method & setter() const;
66
67 /**
68 * @brief Apply resolved dependency on an object instance.
69 * @param on object to apply dependency on
70 * @pre on != nullptr
71 * @pre type{on->metaObject()} == setter().object_type()
72 *
73 * This method can only be called on valid resolved_dependency object.
74 */
75 bool apply_on(QObject *on);
76
77 private:
78 implementation _resolved_with;
79 setter_method _setter;
80
81 };
82
83 INJEQT_INTERNAL_API bool operator == (const resolved_dependency &x, const resolved_dependency &y);
84 INJEQT_INTERNAL_API bool operator != (const resolved_dependency &x, const resolved_dependency &y);
85 INJEQT_INTERNAL_API bool operator < (const resolved_dependency &x, const resolved_dependency &y);
86 INJEQT_INTERNAL_API bool operator > (const resolved_dependency &x, const resolved_dependency &y);
87 INJEQT_INTERNAL_API bool operator <= (const resolved_dependency &x, const resolved_dependency &y);
88 INJEQT_INTERNAL_API bool operator >= (const resolved_dependency &x, const resolved_dependency &y);
89
90 }}