Debian Codegraph @

src/internal/injector-impl.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>cxx . . $ `<file>/include/injeqt/injeqt.h`/
24 #include <injeqt/type.h>cxx . . $ `<file>/include/injeqt/type.h`/
25
26 #include "implementations.h"cxx . . $ `<file>/src/internal/implementations.h`/
27 #include "injector-core.h"cxx . . $ `<file>/src/internal/injector-core.h`/
28 #include "providers.h"cxx . . $ `<file>/src/internal/providers.h`/
29 #include "types-by-name.h"cxx . . $ `<file>/src/internal/types-by-name.h`/
30
31 #include <vector>
32 #include <QtCore/QObject>
33
34 /**
35 * @file
36 * @brief Contains classes and functions for implementation of injector.
37 */
38
39 namespace injeqtcxx . . $ injeqt/ { namespace v1cxx . . $ injeqt/v1/ {
40 class modulecxx . . $ injeqt/v1/module#;
41 }}
42
43 namespace injeqtcxx . . $ injeqt/ { namespace internalcxx . . $ injeqt/internal/ {
44
45 /**
46 * @brief Implementation of injector class.
47 * @see injector
48 * @see injector_core
49 *
50 * Its main purpose is to own all modules passed to injector constructor and to pass everthing else
51 * to injector_core class.
52 */
53 class INJEQT_APIcxx . . $ `include/injeqt/injeqt.h:26:9`! injector_implcxx . . $ injeqt/internal/injector_impl# final
54 {
55
56 public:
57 /**
58 * @brief Create empty injector_impl with no configuration.
59 *
60 * Injector with empty configuration will not be able to return any objects. Each call
61 * to get(const type &) will result in type_not_configured
62 */
63 injector_implcxx . . $ injeqt/internal/injector_impl#injector_impl(49f6e7a06ebc5aa8).();
64
65 /**
66 * @brief Create injector configured with set of modules.
67 * @param modules set of modules containing configuration of injector
68 * @see injector::injector(std::vector<std::unique_ptr<module>>)
69 * @throw ambiguous_types if one or more types in @p modules is ambiguous
70 * @throw unresolvable_dependencies if a type with unresolvable dependency is found in @p modules
71 * @throw dependency_on_self when type depends on self
72 * @throw dependency_on_subtype when type depends on own supertype
73 * @throw dependency_on_subtype when type depends on own subtype
74 * @throw invalid_setter if any tagged setter has parameter that is not a QObject-derived pointer
75 * @throw invalid_setter if any tagged setter has parameter that is a QObject pointer
76 * @throw invalid_setter if any tagged setter has parameter that is a QObject-derived pointer of not configured type
77 * @throw invalid_setter if any tagged setter has other number of parameters than one
78 *
79 * This constructor extract all providers from all modules and creates injector_core object
80 * with these providers.
81 */
82 explicit injector_implcxx . . $ injeqt/internal/injector_impl#injector_impl(282309f3f315010d).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<::injeqtcxx . . $ injeqt/::v1cxx . . $ injeqt/v1/::modulecxx . . $ injeqt/v1/module#>> modules);
83
84 /**
85 * @brief Create injector configured with set of modules.
86 * @param super_injectors list of injectors providing types for this one to use
87 * @param modules set of modules containing configuration of injector
88 * @see injector::injector(std::vector<std::unique_ptr<module>>)
89 * @throw ambiguous_types if one or more types in @p modules is ambiguous
90 * @throw unresolvable_dependencies if a type with unresolvable dependency is found in @p modules
91 * @throw dependency_on_self when type depends on self
92 * @throw dependency_on_subtype when type depends on own supertype
93 * @throw dependency_on_subtype when type depends on own subtype
94 * @throw invalid_setter if any tagged setter has parameter that is not a QObject-derived pointer
95 * @throw invalid_setter if any tagged setter has parameter that is a QObject pointer
96 * @throw invalid_setter if any tagged setter has parameter that is a QObject-derived pointer of not configured type
97 * @throw invalid_setter if any tagged setter has other number of parameters than one
98 *
99 * This constructor extract all providers from all modules and creates injector_core object
100 * with these providers.
101 */
102 explicit injector_implcxx . . $ injeqt/internal/injector_impl#injector_impl(92da87cfcc494a27).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<injector_implcxx . . $ injeqt/internal/injector_impl# *> super_injectors, stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<::injeqtcxx . . $ injeqt/::v1cxx . . $ injeqt/v1/::modulecxx . . $ injeqt/v1/module#>> modules);
103
104 /**
105 * @brief Returns list of all configured types.
106 *
107 * Result contians only types explicitely configured in modules, not supertypes of these. It also includes
108 * results of provided_types() calls from all added parent injectors.
109 */
110 stdcxx . . $ std/::vectorcxx . . $ std/vector#<typecxx . . $ injeqt/v1/type#> provided_typescxx . . $ injeqt/internal/injector_impl#provided_types(cf3a392ed5d6b92b).() const;
111
112 /**
113 * @brief Instantiates object of given type @p interface_type
114 * @param interface_type type of object to instantiate.
115 * @throw unknown_type if @p interface_type was not configured in instantiate
116 * @throw instantiation_failed if instantiation of one of required types failed
117 * @pre !interface_type.is_empty()
118 * @pre !interface_type.is_qobject()
119 * @see injector::get<T>()
120 */
121 void instantiatecxx . . $ injeqt/internal/injector_impl#instantiate(ebaf86d70144d0a8).(const typecxx . . $ injeqt/v1/type# &interface_type);
122
123 /**
124 * @brief Instantiate all objects with given @p type_role.
125 * @throw instantiation_failed if instantiation of one of found types failed
126 */
127 void instantiate_all_with_type_rolecxx . . $ injeqt/internal/injector_impl#instantiate_all_with_type_role(9c546c94e5fcce4e).(const stdcxx . . $ std/::stringcxx . . $ std/string# &type_role);
128
129 /**
130 * @brief Returns pointer to object of given type @p interface_type
131 * @param interface_type type of object to return.
132 * @throw unknown_type if @p interface_type was not configured in injector
133 * @throw instantiation_failed if instantiation of one of required types failed
134 * @pre !interface_type.is_empty()
135 * @pre !interface_type.is_qobject()
136 * @see injector::get<T>()
137 */
138 QObjectcxx . . $ QObject# * getcxx . . $ injeqt/internal/injector_impl#get(e1ed43d1af855660).(const typecxx . . $ injeqt/v1/type# &interface_type);
139
140 /**
141 * @brief Returns all objects with given @p type_role.
142 * @throw instantiation_failed if instantiation of one of found types failed
143 */
144 stdcxx . . $ std/::vectorcxx . . $ std/vector#<QObjectcxx . . $ QObject# *> get_all_with_type_rolecxx . . $ injeqt/internal/injector_impl#get_all_with_type_role(60702980c580d8f6).(const stdcxx . . $ std/::stringcxx . . $ std/string# &type_role);
145
146 /**
147 * @brief Inject dependencies into @p object.
148 * @param object object to inject dependencies into.
149 * @throw invalid_setter if any tagged setter has parameter that is not a QObject-derived pointer
150 * @throw invalid_setter if any tagged setter has parameter that is a QObject pointer
151 * @throw invalid_setter if any tagged setter has parameter that is a QObject-derived pointer of not configured type
152 * @throw invalid_setter if any tagged setter has other number of parameters than one
153 * @pre object != nullptr
154 *
155 * This method looks for invokable setters tagged with INJEQT_SET in @p object. If any of setter is not valid
156 * dependency injector setter or its parameter is of type not configured in injector an exception is thrown.
157 * If all setters are valid, they are called with proper objects (which may be already available in injector
158 * or created on demand).
159 */
160 void inject_intocxx . . $ injeqt/internal/injector_impl#inject_into(749de1b6ae65bddd).(QObjectcxx . . $ QObject# *object);
161
162 private:
163 stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<modulecxx . . $ injeqt/v1/module#>> _modulescxx . . $ injeqt/internal/injector_impl#_modules.;
164 injector_corecxx . . $ injeqt/internal/injector_core# _corecxx . . $ injeqt/internal/injector_impl#_core.;
165
166 void initcxx . . $ injeqt/internal/injector_impl#init(861e78c7efa03789).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<injector_implcxx . . $ injeqt/internal/injector_impl# *> super_injectors);
167
168 };
169
170 }}