| 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 "provider.h" |
| 26 | #include "implementation.h" |
| 27 | #include "internal.h" |
| 28 | |
| 29 | /** |
| 30 | * @file |
| 31 | * @brief Contains classes and functions for representing provider working on ready object. |
| 32 | */ |
| 33 | |
| 34 | namespace injeqt { namespace internal { |
| 35 | |
| 36 | /** |
| 37 | * @brief Provider that always returns the same object. |
| 38 | * |
| 39 | * This provider implementation will always return the same object. Its provided_type() |
| 40 | * returns type of object passed to it in constructor. Its required_types() returns |
| 41 | * empty set of types. |
| 42 | */ |
| 43 | class INJEQT_INTERNAL_API provider_ready final : public provider |
| 44 | { |
| 45 | |
| 46 | public: |
| 47 | /** |
| 48 | * @brief Create provider instance with object to return. |
| 49 | * @param ready_implementation object that this provider will always return |
| 50 | */ |
| 51 | explicit provider_ready(implementation ready_implementation); |
| 52 | virtual ~provider_ready() {} |
| 53 | |
| 54 | /** |
| 55 | * @return implementation::interface_type() of object passed to construtor |
| 56 | */ |
| 57 | virtual const type & provided_type() const override; |
| 58 | |
| 59 | /** |
| 60 | * @return object passed in constructor |
| 61 | * @post result != nullptr |
| 62 | * @post implements(type{result->metaObject()}, provided_type()) |
| 63 | */ |
| 64 | virtual QObject * provide(injector_core &i) override; |
| 65 | |
| 66 | /** |
| 67 | * @return empty set of object - this provider already has instance of a type |
| 68 | */ |
| 69 | virtual types required_types() const override { return types{}; } |
| 70 | |
| 71 | /** |
| 72 | * @return false |
| 73 | * |
| 74 | * Object should be ready to use and do not require dependency resolving. |
| 75 | */ |
| 76 | virtual bool require_resolving() const override; |
| 77 | |
| 78 | /** |
| 79 | * @return implementation object passed in constructor |
| 80 | */ |
| 81 | const implementation & ready_implementation() const; |
| 82 | |
| 83 | private: |
| 84 | implementation _ready_implementation; |
| 85 | |
| 86 | }; |
| 87 | |
| 88 | }} |