| 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 "setter-method.h" |
| 28 | |
| 29 | /** |
| 30 | * @file |
| 31 | * @brief Contains classes and functions for abstractions of Injeqt dependencies. |
| 32 | */ |
| 33 | |
| 34 | namespace injeqt { namespace internal { |
| 35 | |
| 36 | /** |
| 37 | * @brief Abstraction of Injeqt dependency. |
| 38 | * |
| 39 | * Current version of Injeqt supports only setter-based dependencies between classes. |
| 40 | * Dependency is based on setter_method class - it contains one object of setter_method |
| 41 | * type to represent method used to resolve dependency. It also has helper function |
| 42 | * required_type() to get a type that of object can be accepted as a dependency. |
| 43 | * |
| 44 | * Objects of this type are valid only when backing setter_method is valid. |
| 45 | */ |
| 46 | class INJEQT_INTERNAL_API dependency final |
| 47 | { |
| 48 | |
| 49 | public: |
| 50 | /** |
| 51 | * @brief Create dependency instance that uses setter method to be resolved. |
| 52 | * @param setter setter method used to resolve dependency |
| 53 | * @pre !setter.is_empty() |
| 54 | */ |
| 55 | explicit dependency(setter_method setter); |
| 56 | |
| 57 | /** |
| 58 | * @return type that is required to resolve dependency |
| 59 | * |
| 60 | * Objects that resolve must be either of type returned by this method or |
| 61 | * of type that derives from it. This type is the same as setter().parameter_type(). |
| 62 | */ |
| 63 | const type & required_type() const; |
| 64 | |
| 65 | /** |
| 66 | * @return setter method that must be used to resolve dependency |
| 67 | * |
| 68 | * Returned method can be invoked on object that is of type that contains this |
| 69 | * dependency to resolve it. |
| 70 | */ |
| 71 | const setter_method & setter() const; |
| 72 | |
| 73 | private: |
| 74 | setter_method _setter; |
| 75 | |
| 76 | }; |
| 77 | |
| 78 | INJEQT_INTERNAL_API bool operator == (const dependency &x, const dependency &y); |
| 79 | INJEQT_INTERNAL_API bool operator != (const dependency &x, const dependency &y); |
| 80 | INJEQT_INTERNAL_API bool operator < (const dependency &x, const dependency &y); |
| 81 | INJEQT_INTERNAL_API bool operator > (const dependency &x, const dependency &y); |
| 82 | INJEQT_INTERNAL_API bool operator <= (const dependency &x, const dependency &y); |
| 83 | INJEQT_INTERNAL_API bool operator >= (const dependency &x, const dependency &y); |
| 84 | |
| 85 | }} |