| 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 "dependencies.h" |
| 26 | #include "implementations.h" |
| 27 | #include "internal.h" |
| 28 | |
| 29 | #include <vector> |
| 30 | |
| 31 | /** |
| 32 | * @file |
| 33 | * @brief Contains classes and functions for resolving dependencies. |
| 34 | */ |
| 35 | |
| 36 | namespace injeqt { namespace internal { |
| 37 | |
| 38 | class resolved_dependency; |
| 39 | |
| 40 | /** |
| 41 | * @brief Structure for holding result of resolving dependencies. * |
| 42 | */ |
| 43 | struct resolve_dependencies_result |
| 44 | { |
| 45 | /** |
| 46 | * @brief All dependencies that were not resolved. |
| 47 | */ |
| 48 | dependencies unresolved; |
| 49 | |
| 50 | /** |
| 51 | * @brief All dependencies that were resolved. |
| 52 | * |
| 53 | * There is no need to keep the result in sorted_unique_vector based class - resolve_dependencies |
| 54 | * function is guaranteed to return only unique result and that field is not matched against any |
| 55 | * other collection. If that condition changes this can be easily turned into sorted_unique_vector. |
| 56 | */ |
| 57 | std::vector<resolved_dependency> resolved; |
| 58 | }; |
| 59 | |
| 60 | /** |
| 61 | * @brief Resolve set of dependencies with set of implementations objects. |
| 62 | * |
| 63 | * This function matches each dependency with implementation with the same same type. If any dependency does not |
| 64 | * have corresponding object - it is added to resolve_dependencies_result::unresolved field. All matching dependency - |
| 65 | * implementation pairs are added to resolve_dependencies_result::resolved field. |
| 66 | * |
| 67 | * This function requires that all items in both sets are valid. In other case its behavior is undefined. |
| 68 | * This function returns only valid objects. |
| 69 | */ |
| 70 | INJEQT_INTERNAL_API resolve_dependencies_result resolve_dependencies(const dependencies &to_resolve, const implementations &resolve_with); |
| 71 | |
| 72 | }} |