Debian Codegraph @

src/internal/type-dependencies.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 "dependencies.h"
27 #include "internal.h"
28
29 #include <cassert>
30
31 /**
32 * @file
33 * @brief Contains classes and functions for representing type and its dependencies.
34 */
35
36 namespace injeqt { namespace internal {
37
38 /**
39 * @brief Type and its dependencies.
40 *
41 * This class is used to represent type with connection of all its dependencies. Instances created
42 * with make_type_dependencies(type) function are guaranteed to be valid.
43 *
44 * Used in model class to store all dependnecies and in injector_core to resolve them.
45 */
46 class INJEQT_INTERNAL_API type_dependencies final
47 {
48
49 public:
50 /**
51 * @brief Create new instance of type_dependencies.
52 * @param dependent_type type that contains dependencies described with dependency_list
53 * @param dependency_list list of dependencies of dependent_type
54 */
55 explicit type_dependencies(type dependent_type, dependencies dependency_list);
56
57 /**
58 * @return type that contains dependencies described with dependency_list
59 */
60 const type & dependent_type() const;
61
62 /**
63 * @return list of dependencies of dependent_type()
64 */
65 const dependencies & dependency_list() const;
66
67 private:
68 type _dependent_type;
69 dependencies _dependency_list;
70
71 };
72
73 INJEQT_INTERNAL_API bool operator == (const type_dependencies &x, const type_dependencies &y);
74 INJEQT_INTERNAL_API bool operator != (const type_dependencies &x, const type_dependencies &y);
75
76 /**
77 * @brief Create valid type_dependencies from given type.
78 * @param dependent_type type to get dependecies from.
79 * @pre !dependent_type.is_empty()
80 * @throw dependency_on_self when type depends on self
81 * @throw dependency_on_subtype when type depends on own supertype
82 * @throw dependency_on_subtype when type depends on own subtype
83 * @throw invalid_setter if any tagged setter has parameter that is not a QObject-derived pointer
84 * @throw invalid_setter if any tagged setter has parameter that is a QObject pointer
85 * @throw invalid_setter if any tagged setter has other number of parameters than one
86 */
87 inline type_dependencies make_type_dependencies(const types_by_name &known_types, type dependent_type)
88 {
89 assert(!dependent_type.is_empty());
90
91 return type_dependencies{dependent_type, extract_dependencies(known_types, dependent_type)};
92 }
93
94 }}