| 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 "dependency.h" |
| 27 | #include "internal.h" |
| 28 | #include "types-by-name.h" |
| 29 | |
| 30 | /** |
| 31 | * @file |
| 32 | * @brief Contains classes and functions for representing set of Injeqt dependencies. |
| 33 | */ |
| 34 | |
| 35 | namespace injeqt { namespace internal { |
| 36 | |
| 37 | /** |
| 38 | * @brief Extract type from dependency for storting purposes. |
| 39 | * @brief Identity function. |
| 40 | */ |
| 41 | inline type type_from_dependency(const dependency &d) |
| 42 | { |
| 43 | return d.required_type(); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @brief Identity function. |
| 48 | */ |
| 49 | inline dependency dependency_from_dependency(const dependency &d) |
| 50 | { |
| 51 | return d; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * @brief Abstraction of Injeqt set of dependencies. |
| 56 | * |
| 57 | * This set is used to represent all dependencies of one class. It is not possible |
| 58 | * to store two dependnecies with the same dependency::required_type() values in it. |
| 59 | * Set is sorted by dependency::required_type() and it can be matched with other |
| 60 | * type based sets (like implementations) using match() function. |
| 61 | * |
| 62 | * The best way to create instance of this type is to call make_validated_dependencies(const type &). |
| 63 | */ |
| 64 | using dependencies = sorted_unique_vector<dependency, dependency, dependency_from_dependency>; |
| 65 | |
| 66 | /** |
| 67 | * @brief Extract set of dependencies from type. |
| 68 | * @param for_type type to extract dependencies from. |
| 69 | * @pre !for_type.is_empty() |
| 70 | * @throw dependency_on_self when type depends on self. |
| 71 | * @throw dependency_on_subtype when type depends on own supertype. |
| 72 | * @throw dependency_on_subtype when type depends on own subtype. |
| 73 | * @throw invalid_setter if any tagged setter has parameter that is not a QObject-derived pointer |
| 74 | * @throw invalid_setter if any tagged setter has parameter that is a QObject pointer |
| 75 | * @throw invalid_setter if any tagged setter has other number of parameters than one |
| 76 | * |
| 77 | * This function computes and returns set of all dependencies of a given type. All slots methods tagged |
| 78 | * with INJEQT_SET are describing dependnecies. If all dependnecies are valid, there is no duplication, |
| 79 | * and type does not depends on self, subtype or supertype, a result is returned. Otherwise one of many |
| 80 | * exceptions can be thrown. |
| 81 | */ |
| 82 | INJEQT_INTERNAL_API dependencies extract_dependencies(const types_by_name &known_types, const type &for_type); |
| 83 | |
| 84 | }} |