Debian Codegraph @

src/internal/default-constructor-method.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 "internal.h"cxx . . $ `<file>/src/internal/internal.h`/
24
25 #include <injeqt/exception/exception.h>cxx . . $ `<file>/include/injeqt/exception/exception.h`/
26 #include <injeqt/injeqt.h>cxx . . $ `<file>/include/injeqt/injeqt.h`/
27 #include <injeqt/type.h>cxx . . $ `<file>/include/injeqt/type.h`/
28
29 #include <memory>
30 #include <QtCore/QMetaMethod>
31
32 /**
33 * @file
34 * @brief Contains classes and functions for representing default constructors.
35 */
36
37 class QObjectcxx . . $ QObject#;
38
39 namespace injeqtcxx . . $ injeqt/ { namespace internalcxx . . $ injeqt/internal/ {
40
41 /**
42 * @brief Abstraction of default constructor.
43 *
44 * This class is used for creating objects of types configured with module::add_type<T>().
45 * Default constructor is crated from Qt type QMetaMethod. As Qt only creates QMetaMethod
46 * objects for slots, signals and all methods marked with Q_INVOKABLE tag - Injeqt
47 * requires that default constructor is also marked with that tag. It is also not allowed
48 * to have any parameters without default values.
49 *
50 * Example of valid default constructor:
51 *
52 * class with_default_constructor : public QObject
53 * {
54 * Q_OBJECT
55 * public:
56 * Q_INVOKABLE with_default_constructor(QObject * parent = nullptr) {}
57 * };
58 *
59 * To extract constructor from a type call make_default_constructor_method<T>().
60 */
61 class INJEQT_INTERNAL_APIcxx . . $ `src/internal/internal.h:24:9`! default_constructor_methodcxx . . $ injeqt/internal/default_constructor_method# final
62 {
63
64 public:
65 /**
66 * @brief Create empty default_constructor_method.
67 */
68 default_constructor_methodcxx . . $ injeqt/internal/default_constructor_method#default_constructor_method(49f6e7a06ebc5aa8).();
69
70 /**
71 * @brief Create object from QMetaMethod definition.
72 * @param meta_method Qt meta method that should be a default constructor
73 * @pre meta_method.methodType() == QMetaMethod::Constructor
74 * @pre meta_method.parameterCount() == 0
75 * @pre meta_method.enclosingMetaObject() != nullptr
76 */
77 explicit default_constructor_methodcxx . . $ injeqt/internal/default_constructor_method#default_constructor_method(77ddf0810175a47c).(QMetaMethodcxx . . $ QMetaMethod# meta_method);
78
79 /**
80 * @return true if default_constructor_method is empty and does not represent constructor
81 */
82 bool is_emptycxx . . $ injeqt/internal/default_constructor_method#is_empty(50ce9a9e25b4a850).() const;
83
84 /**
85 * @return Type of objects created by default constructor.
86 */
87 const typecxx . . $ injeqt/v1/type# & object_typecxx . . $ injeqt/internal/default_constructor_method#object_type(7e9f7f4e42b3414e).() const;
88
89 /**
90 * @return Qt representation of default constructor.
91 *
92 * May return empty value if object is empty.
93 */
94 const QMetaMethodcxx . . $ QMetaMethod# & meta_methodcxx . . $ injeqt/internal/default_constructor_method#meta_method(9ea3a8eb2e51c72d).() const;
95
96 /**
97 * @return New instance of type of default constructor.
98 * @pre !is_empty()
99 */
100 stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<QObjectcxx . . $ QObject#> invokecxx . . $ injeqt/internal/default_constructor_method#invoke(5b92897074bb3200).() const;
101
102 private:
103 typecxx . . $ injeqt/v1/type# _object_typecxx . . $ injeqt/internal/default_constructor_method#_object_type.;
104 QMetaMethodcxx . . $ QMetaMethod# _meta_methodcxx . . $ injeqt/internal/default_constructor_method#_meta_method.;
105
106 };
107
108 INJEQT_INTERNAL_APIcxx . . $ `src/internal/internal.h:24:9`! bool operatorcxx . . $ injeqt/internal/`operator==`(4e0dc7aefa17b10b). == (const default_constructor_methodcxx . . $ injeqt/internal/default_constructor_method# &x, const default_constructor_methodcxx . . $ injeqt/internal/default_constructor_method# &y);
109 INJEQT_INTERNAL_APIcxx . . $ `src/internal/internal.h:24:9`! bool operatorcxx . . $ injeqt/internal/`operator!=`(4e0dc7aefa17b10b). != (const default_constructor_methodcxx . . $ injeqt/internal/default_constructor_method# &x, const default_constructor_methodcxx . . $ injeqt/internal/default_constructor_method# &y);
110
111 /**
112 * @brief Extract default constructor method from given type T.
113 * @tparam t type to extract constructor from
114 * @pre !t.is_empty() && !t.is_qobject()
115 *
116 * This method looks for all constructors of type t tagged with Q_INVOKABLE and returns
117 * default_constructor_method based on one without any parameters or with all parameters
118 * with default values. If no such constructor is found - empty default_constructor_method
119 * is returned.
120 */
121 INJEQT_INTERNAL_APIcxx . . $ `src/internal/internal.h:24:9`! default_constructor_methodcxx . . $ injeqt/internal/default_constructor_method# make_default_constructor_methodcxx . . $ injeqt/internal/make_default_constructor_method(84114e33f83ca37c).(const typecxx . . $ injeqt/v1/type# &t);
122
123 }}