| 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 "injector-impl.h"cxx . . $ `<file>/src/internal/injector-impl.h`/ |
| 22 | |
| 23 | #include <injeqt/exception/unknown-type.h>cxx . . $ `<file>/include/injeqt/exception/unknown-type.h`/ |
| 24 | #include <injeqt/module.h>cxx . . $ `<file>/include/injeqt/module.h`/ |
| 25 | |
| 26 | #include "containers.h"cxx . . $ `<file>/src/internal/containers.h`/ |
| 27 | #include "interfaces-utils.h"cxx . . $ `<file>/src/internal/interfaces-utils.h`/ |
| 28 | #include "provider-by-default-constructor.h"cxx . . $ `<file>/src/internal/provider-by-default-constructor.h`/ |
| 29 | #include "provider-by-parent-injector-configuration.h"cxx . . $ `<file>/src/internal/provider-by-parent-injector-configuration.h`/ |
| 30 | #include "provider-ready.h"cxx . . $ `<file>/src/internal/provider-ready.h`/ |
| 31 | #include "provider.h"cxx . . $ `<file>/src/internal/provider.h`/ |
| 32 | #include "module-impl.h"cxx . . $ `<file>/src/internal/module-impl.h`/ |
| 33 | #include "required-to-satisfy.h"cxx . . $ `<file>/src/internal/required-to-satisfy.h`/ |
| 34 | #include "resolve-dependencies.h"cxx . . $ `<file>/src/internal/resolve-dependencies.h`/ |
| 35 | #include "resolved-dependency.h"cxx . . $ `<file>/src/internal/resolved-dependency.h`/ |
| 36 | |
| 37 | #include <cassert> |
| 38 | |
| 39 | namespace injeqtcxx . . $ injeqt/ { namespace internalcxx . . $ injeqt/internal/ { |
| 40 | |
| 41 | injector_implcxx . . $ injeqt/internal/injector_impl#::injector_implcxx . . $ injeqt/internal/injector_impl#injector_impl(49f6e7a06ebc5aa8).() |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | injector_implcxx . . $ injeqt/internal/injector_impl#::injector_implcxx . . $ injeqt/internal/injector_impl#injector_impl(282309f3f315010d).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<modulecxx . . $ injeqt/v1/module#>> modules) : |
| 46 | // modules are only stored because these can own objects used by injector |
| 47 | _modulescxx . . $ injeqt/internal/injector_impl#_modules.{stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(modules)} |
| 48 | { |
| 49 | initcxx . . $ injeqt/internal/injector_impl#init(861e78c7efa03789).(stdcxx . . $ std/vector#vector(b1ea180184b47f03).::vectorcxx . . $ std/vector#<injector_implcxx . . $ injeqt/internal/injector_impl# *>{}); |
| 50 | } |
| 51 | |
| 52 | injector_implcxx . . $ injeqt/internal/injector_impl#::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#<modulecxx . . $ injeqt/v1/module#>> modules) : |
| 53 | // modules are only stored because these can own objects used by injector |
| 54 | _modulescxx . . $ injeqt/internal/injector_impl#_modules.{stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(modules)} |
| 55 | { |
| 56 | initcxx . . $ injeqt/internal/injector_impl#init(861e78c7efa03789).(super_injectorscxx . . $ std/vector#vector(a1201200cf0efa42).); |
| 57 | } |
| 58 | |
| 59 | void injector_implcxx . . $ injeqt/internal/injector_impl#::initcxx . . $ injeqt/internal/injector_impl#init(861e78c7efa03789).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<injector_implcxx . . $ injeqt/internal/injector_impl# *> super_injectors) |
| 60 | { |
| 61 | auto extract_provider_configurations_lambda = [](const stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<modulecxx . . $ injeqt/v1/module#> &m){ return mcxx . . $ std/vector#vector(a1201200cf0efa42).->cxx . . $ std/unique_ptr#`operator->`(ca399b2b6292c808)._pimplcxx . . $ injeqt/v1/module#_pimpl.->cxx . . $ std/unique_ptr#`operator->`(ca399b2b6292c808).provider_configurationscxx . . $ injeqt/internal/module_impl#provider_configurations(d95024f3d0a9d250).(); }; |
| 62 | auto extract_provider_configurations = stdcxx . . $ std/function#function(a4b4b0c4acad1616).::functioncxx . . $ std/function#<stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::shared_ptrcxx . . $ std/shared_ptr#<provider_configurationcxx . . $ injeqt/internal/provider_configuration#>>(const stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<modulecxx . . $ injeqt/v1/module#> &)>{extract_provider_configurations_lambda}; |
| 63 | auto provider_configurations = extractcxx . . $ std/vector#vector(b1ea180184b47f03).(_modulescxx . . $ injeqt/internal/injector_impl#_modules., extract_provider_configurationscxx . . $ std/function#function(ec20bd20f4acba43).); |
| 64 | |
| 65 | for (auto &&super_injector : super_injectors) |
| 66 | for (auto &&provided_type : super_injector->provided_typescxx . . $ injeqt/internal/injector_impl#provided_types(cf3a392ed5d6b92b).()) |
| 67 | provider_configurations.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(stdcxx . . $ std/shared_ptr#shared_ptr(367bdfadb5bc8b96).::make_sharedcxx . . $ std/make_shared(ffca0f3977536948).<provider_by_parent_injector_configurationcxx . . $ injeqt/internal/provider_by_parent_injector_configuration#>(super_injector, provided_type)); |
| 68 | |
| 69 | auto extract_types_lamdba = [](const stdcxx . . $ std/::shared_ptrcxx . . $ std/shared_ptr#<provider_configurationcxx . . $ injeqt/internal/provider_configuration#> &pc){ |
| 70 | auto result = stdcxx . . $ std/vector#vector(b1ea180184b47f03).::vectorcxx . . $ std/vector#<typecxx . . $ injeqt/v1/type#>{}; |
| 71 | for (auto &&t : pc->cxx . . $ std/__shared_ptr_access#`operator->`(5a2a78a048fb49a8).typescxx . . $ injeqt/internal/provider_configuration#types(cf3a392ed5d6b92b).()) |
| 72 | { |
| 73 | auto interfaces = extract_interfacescxx . . $ injeqt/internal/extract_interfaces(859a62e7a8dc5225).(t); |
| 74 | stdcxx . . $ std/::copycxx . . $ std/copy(88304b602929f6f4).(stdcxx . . $ std/::begincxx . . $ std/begin(8c94f1ffb8cd32fc).(interfaces), stdcxx . . $ std/::endcxx . . $ std/end(898c3e9f99adb426).(interfaces), stdcxx . . $ std/::back_insertercxx . . $ std/back_inserter(7b559d6bdd90ff74).(result)); |
| 75 | } |
| 76 | return resultcxx . . $ std/vector#vector(b1ea180184b47f03).; |
| 77 | }; |
| 78 | auto extract_types = stdcxx . . $ std/function#function(a4b4b0c4acad1616).::functioncxx . . $ std/function#<stdcxx . . $ std/::vectorcxx . . $ std/vector#<typecxx . . $ injeqt/v1/type#>(const stdcxx . . $ std/::shared_ptrcxx . . $ std/shared_ptr#<provider_configurationcxx . . $ injeqt/internal/provider_configuration#> &)>{extract_types_lamdba}; |
| 79 | auto known_types = types_by_namecxx . . $ injeqt/internal/sorted_unique_vector#sorted_unique_vector(26e8deb829554aa).{extractcxx . . $ std/vector#vector(b1ea180184b47f03).(provider_configurations, extract_typescxx . . $ std/function#function(ec20bd20f4acba43).)}; |
| 80 | |
| 81 | auto create_provider_lambda = [&known_types](const stdcxx . . $ std/::shared_ptrcxx . . $ std/shared_ptr#<provider_configurationcxx . . $ injeqt/internal/provider_configuration#> &pc){ return pccxx . . $ std/unique_ptr#unique_ptr(d6762fce684538e4).->cxx . . $ std/__shared_ptr_access#`operator->`(5a2a78a048fb49a8).create_providercxx . . $ injeqt/internal/provider_configuration#create_provider(2c251cf15db9f22d).(known_types); }; |
| 82 | auto create_provider = stdcxx . . $ std/function#function(a4b4b0c4acad1616).::functioncxx . . $ std/function#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<providercxx . . $ injeqt/internal/provider#>(stdcxx . . $ std/::shared_ptrcxx . . $ std/shared_ptr#<provider_configurationcxx . . $ injeqt/internal/provider_configuration#>)>{create_provider_lambda}; |
| 83 | auto providers = transformcxx . . $ std/vector#vector(b1ea180184b47f03).(provider_configurations, create_providercxx . . $ std/function#function(ec20bd20f4acba43).); |
| 84 | |
| 85 | _corecxx . . $ injeqt/internal/injector_impl#_core. =cxx . . $ injeqt/internal/injector_core#`operator=`(b162674904b101d8). injector_corecxx . . $ injeqt/internal/injector_core#injector_core(a8e0597472603795).{known_types, stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(providers)}; |
| 86 | } |
| 87 | |
| 88 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<typecxx . . $ injeqt/v1/type#> injector_implcxx . . $ injeqt/internal/injector_impl#::provided_typescxx . . $ injeqt/internal/injector_impl#provided_types(cf3a392ed5d6b92b).() const |
| 89 | { |
| 90 | return _corecxx . . $ std/vector#vector(b1ea180184b47f03)..provided_typescxx . . $ injeqt/internal/injector_core#provided_types(cf3a392ed5d6b92b).(); |
| 91 | } |
| 92 | |
| 93 | void injector_implcxx . . $ injeqt/internal/injector_impl#::instantiatecxx . . $ injeqt/internal/injector_impl#instantiate(ebaf86d70144d0a8).(const typecxx . . $ injeqt/v1/type# &interface_type) |
| 94 | { |
| 95 | assertcxx . . $ `/usr/include/assert.h:102:11`!(!interface_type.is_empty()); |
| 96 | assertcxx . . $ `/usr/include/assert.h:102:11`!(!interface_type.is_qobject()); |
| 97 | |
| 98 | _corecxx . . $ injeqt/internal/injector_impl#_core..instantiatecxx . . $ injeqt/internal/injector_core#instantiate(ebaf86d70144d0a8).(interface_type); |
| 99 | } |
| 100 | |
| 101 | void injector_implcxx . . $ injeqt/internal/injector_impl#::instantiate_all_with_type_rolecxx . . $ injeqt/internal/injector_impl#instantiate_all_with_type_role(9c546c94e5fcce4e).(const stdcxx . . $ std/::stringcxx . . $ std/string# &type_role) |
| 102 | { |
| 103 | _corecxx . . $ injeqt/internal/injector_impl#_core..instantiate_all_with_type_rolecxx . . $ injeqt/internal/injector_core#instantiate_all_with_type_role(9c546c94e5fcce4e).(type_role); |
| 104 | } |
| 105 | |
| 106 | QObjectcxx . . $ QObject# * injector_implcxx . . $ injeqt/internal/injector_impl#::getcxx . . $ injeqt/internal/injector_impl#get(e1ed43d1af855660).(const typecxx . . $ injeqt/v1/type# &interface_type) |
| 107 | { |
| 108 | assertcxx . . $ `/usr/include/assert.h:102:11`!(!interface_type.is_empty()); |
| 109 | assertcxx . . $ `/usr/include/assert.h:102:11`!(!interface_type.is_qobject()); |
| 110 | |
| 111 | return _corecxx . . $ injeqt/internal/injector_impl#_core..getcxx . . $ injeqt/internal/injector_core#get(e1ed43d1af855660).(interface_type); |
| 112 | } |
| 113 | |
| 114 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<QObjectcxx . . $ QObject# *> injector_implcxx . . $ injeqt/internal/injector_impl#::get_all_with_type_rolecxx . . $ injeqt/internal/injector_impl#get_all_with_type_role(60702980c580d8f6).(const stdcxx . . $ std/::stringcxx . . $ std/string# &type_role) |
| 115 | { |
| 116 | return _corecxx . . $ std/vector#vector(b1ea180184b47f03)..get_all_with_type_rolecxx . . $ injeqt/internal/injector_core#get_all_with_type_role(60702980c580d8f6).(type_role); |
| 117 | } |
| 118 | |
| 119 | void injector_implcxx . . $ injeqt/internal/injector_impl#::inject_intocxx . . $ injeqt/internal/injector_impl#inject_into(749de1b6ae65bddd).(QObjectcxx . . $ QObject# *object) |
| 120 | { |
| 121 | assertcxx . . $ `/usr/include/assert.h:102:11`!(object); |
| 122 | |
| 123 | _corecxx . . $ injeqt/internal/injector_impl#_core..inject_intocxx . . $ injeqt/internal/injector_core#inject_into(749de1b6ae65bddd).(object); |
| 124 | } |
| 125 | |
| 126 | }} |