| 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 | #include <injeqt/type.h> |
| 25 | |
| 26 | #include "internal.h" |
| 27 | #include "provider-configuration.h" |
| 28 | |
| 29 | /** |
| 30 | * @file |
| 31 | * @brief Contains classes and functions for representing configuration of provider working on ready object. |
| 32 | */ |
| 33 | |
| 34 | namespace injeqt { namespace internal { |
| 35 | |
| 36 | /** |
| 37 | * @brief Configuration of provider that always returns the same object. |
| 38 | * |
| 39 | * This provider configuration object will return provider implementation that will always return the same object. |
| 40 | */ |
| 41 | class INJEQT_INTERNAL_API provider_ready_configuration : public provider_configuration |
| 42 | { |
| 43 | |
| 44 | public: |
| 45 | /** |
| 46 | * @brief Create provider configuration instance. |
| 47 | * @param object_type type of object that this provider will always return |
| 48 | * @param object object that this provider will always return |
| 49 | * @pre !object_type.is_empty() |
| 50 | * |
| 51 | * This constructor does not throw even when @p object_type and @p object combination is invalid. |
| 52 | * Factory method create_provider(const types_by_name &) will throw in that case. |
| 53 | */ |
| 54 | explicit provider_ready_configuration(type object_type, QObject *object); |
| 55 | virtual ~provider_ready_configuration(); |
| 56 | |
| 57 | /** |
| 58 | * @return list consisting of object_type param passed to constructor |
| 59 | */ |
| 60 | virtual std::vector<type> types() const override; |
| 61 | |
| 62 | /** |
| 63 | * @param known_types list of all types known to injector, not used |
| 64 | * @return pointer to new @see provider_ready object |
| 65 | * @throw exception::empty_type if object_type passed to constructor was empty |
| 66 | * @throw exception::qobject_type if object_type passed to constructor was QObject |
| 67 | * @throw exception::invalid_qobject if object passed to constructor was nullptr |
| 68 | * @throw exception::invalid_qobject if object passed to constructor was nullptr does not have a valid metaObject() |
| 69 | * @throw exception::interface_not_implemented if object passed to constructor does not implement object_type interface |
| 70 | */ |
| 71 | virtual std::unique_ptr<provider> create_provider(const types_by_name &known_types) const override; |
| 72 | |
| 73 | private: |
| 74 | type _object_type; |
| 75 | QObject *_object; |
| 76 | |
| 77 | }; |
| 78 | |
| 79 | }} |