| 1 | /* |
| 2 | * %injeqt copyright begin% |
| 3 | * Copyright 2015 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 | |
| 25 | #include "injector-impl.h"cxx . . $ `<file>/src/internal/injector-impl.h`/ |
| 26 | #include "provider.h"cxx . . $ `<file>/src/internal/provider.h`/ |
| 27 | |
| 28 | /** |
| 29 | * @file |
| 30 | * @brief Contains classes and functions for representing provider that uses different injector. |
| 31 | */ |
| 32 | |
| 33 | namespace injeqtcxx . . $ injeqt/ { namespace internalcxx . . $ injeqt/internal/ { |
| 34 | |
| 35 | /** |
| 36 | * @brief Provider that returns object from other (parent) injector. |
| 37 | * |
| 38 | * This provider implementation will return object from different (parent) injector. |
| 39 | * It is basically a proxy. It can be used to implement injectors inside plugins that |
| 40 | * use main application injector for getting global services. It can be also used to manager |
| 41 | * scopes of object - by creating separate subinjectors for each context. |
| 42 | */ |
| 43 | class provider_by_parent_injectorcxx . . $ injeqt/internal/provider_by_parent_injector# final : public providercxx . . $ injeqt/internal/provider# |
| 44 | { |
| 45 | |
| 46 | public: |
| 47 | /** |
| 48 | * @param parent_injector injector used to get object |
| 49 | * @param provided_type type to provide |
| 50 | * @pre parent_injector != nullptr |
| 51 | */ |
| 52 | explicit provider_by_parent_injectorcxx . . $ injeqt/internal/provider_by_parent_injector#provider_by_parent_injector(224c0e358b759e38).(injector_implcxx . . $ injeqt/internal/injector_impl# *parent_injector, typecxx . . $ injeqt/v1/type# provided_type); |
| 53 | virtual ~cxx . . $ injeqt/internal/provider_by_parent_injector#`~provider_by_parent_injector`(49f6e7a06ebc5aa8).provider_by_parent_injectorcxx . . $ injeqt/internal/provider_by_parent_injector#() {} |
| 54 | |
| 55 | /** |
| 56 | * @return provided_type value passed to constructor |
| 57 | */ |
| 58 | virtual const typecxx . . $ injeqt/v1/type# & provided_typecxx . . $ injeqt/internal/provider_by_parent_injector#provided_type(7e9f7f4e42b3414e).() const override; |
| 59 | |
| 60 | /** |
| 61 | * @return object returned by parent_injector |
| 62 | * @post result != nullptr |
| 63 | * @post implements(type{result->metaObject()}, provided_type()) |
| 64 | * @throw instantiation_failed if instantiation of provided type failed |
| 65 | * |
| 66 | * If object was not yet created the constructor() method is called and object is stored |
| 67 | * in internal cache. Then object from cache is returned. |
| 68 | */ |
| 69 | virtual QObjectcxx . . $ QObject# * providecxx . . $ injeqt/internal/provider_by_parent_injector#provide(51123600412ca135).(injector_corecxx . . $ injeqt/internal/injector_core# &i) override; |
| 70 | |
| 71 | /** |
| 72 | * @return empty set of object - this provider does not require another object to instantiate |
| 73 | */ |
| 74 | virtual typescxx . . $ injeqt/internal/types# required_typescxx . . $ injeqt/internal/provider_by_parent_injector#required_types(6f3e1a4b3e1e60c4).() const override { return typescxx . . $ injeqt/internal/sorted_unique_vector#sorted_unique_vector(49f6e7a06ebc5aa8).{}; } |
| 75 | |
| 76 | /** |
| 77 | * @return false |
| 78 | * |
| 79 | * Parent injector takes care of it. |
| 80 | */ |
| 81 | virtual bool require_resolvingcxx . . $ injeqt/internal/provider_by_parent_injector#require_resolving(50ce9a9e25b4a850).() const override; |
| 82 | |
| 83 | private: |
| 84 | injector_implcxx . . $ injeqt/internal/injector_impl# *_parent_injectorcxx . . $ injeqt/internal/provider_by_parent_injector#_parent_injector.; |
| 85 | typecxx . . $ injeqt/v1/type# _provided_typecxx . . $ injeqt/internal/provider_by_parent_injector#_provided_type.; |
| 86 | |
| 87 | }; |
| 88 | |
| 89 | }} |