Debian Codegraph @

src/internal/types-model.h

raw symbols SCIP
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 "implemented-by-mapping.h"
27 #include "internal.h"
28 #include "types-by-name.h"
29 #include "types-dependencies.h"
30
31 /**
32 * @file
33 * @brief Contains classes and functions for representing model of Injeqt types.
34 */
35
36 namespace injeqt { namespace internal {
37
38 /**
39 * @brief Model of all types, their dependencies and relations.
40 *
41 * This class is used to represent model of all types, their dependencies and relations.
42 * Basically it consists of implemented_by_mapping and types_dependencies build from
43 * the same set of types.
44 *
45 * Use make_types_model(const std::vector<type> &) to create valid instance of this type
46 * and be informed of any errors in form of exceptions.
47 */
48 class INJEQT_INTERNAL_API types_model
49 {
50
51 public:
52 /**
53 * @brief Create empty instance of types_model.
54 */
55 types_model();
56
57 /**
58 * @brief Create new instance of types_model.
59 * @param available_types set of all interfaces in model mapped to implementation types
60 * @param mapped_dependencies set of all dependencies of implementation types
61 *
62 * Both @p available_types and @p mapped_dependencies should be created from the same set of
63 * types for types_model to be usefull.
64 */
65 explicit types_model(implemented_by_mapping available_types, types_dependencies mapped_dependencies);
66
67 /**
68 * @return set of all interfaces in model mapped to implementation types.
69 */
70 const implemented_by_mapping & available_types() const;
71
72 /**
73 * @return set of all dependencies of implementation types
74 */
75 const types_dependencies & mapped_dependencies() const;
76
77 /**
78 * @return true if model contains @p interface_type
79 */
80 bool contains(const type &interface_type) const;
81
82 /**
83 * @brief Return all unresolvable dependencies
84 */
85 std::vector<dependency> get_unresolvable_dependencies() const;
86
87 private:
88 implemented_by_mapping _available_types;
89 types_dependencies _mapped_dependencies;
90
91 };
92
93 /**
94 * @brief Create types_model from given set of types.
95 * @param known_types list of all known types
96 * @param all_types set of types to make model from, all types must be valid.
97 * @param need_dependencies list of types that will have dependencies extracted
98 * @post result.get_unresolvable_dependencies().empty()
99 * @throw ambiguous_types if one or more types is ambiguous (@see make_type_relations)
100 * @throw unresolvable_dependencies if a type has a dependency type not in @p all_types set
101 * @throw dependency_on_self when type depends on self
102 * @throw dependency_on_subtype when type depends on own supertype
103 * @throw dependency_on_subtype when type depends on own subtype
104 * @throw invalid_setter if any tagged setter has parameter that is not a QObject-derived pointer
105 * @throw invalid_setter if any tagged setter has parameter that is a QObject pointer
106 * @throw invalid_setter if any tagged setter has other number of parameters than one
107 */
108 INJEQT_INTERNAL_API types_model make_types_model(const types_by_name &known_types, const std::vector<type> &all_types, const std::vector<type> &need_dependencies);
109
110 /**
111 * @brief Check if types model do not have unresolvable types.
112 * @param model model to check
113 * @throw unresolvable_dependencies if @p model contains unresolvable types
114 */
115 INJEQT_INTERNAL_API void validate_non_unresolvable(const types_model &model);
116
117 }}