Debian Codegraph @

src/internal/factory-method.cpp

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 #include "factory-method.h"cxx . . $ `<file>/src/internal/factory-method.h`/
22
23 #include "interfaces-utils.h"cxx . . $ `<file>/src/internal/interfaces-utils.h`/
24
25 #include <cassert>
26
27 namespace injeqtcxx . . $ injeqt/ { namespace internalcxx . . $ injeqt/internal/ {
28
29 factory_methodcxx . . $ injeqt/internal/factory_method#::factory_methodcxx . . $ injeqt/internal/factory_method#factory_method(49f6e7a06ebc5aa8).()
30 {
31 }
32
33 factory_methodcxx . . $ injeqt/internal/factory_method#::factory_methodcxx . . $ injeqt/internal/factory_method#factory_method(88aafc8b4e97b263).(typecxx . . $ injeqt/v1/type# result_type, QMetaMethodcxx . . $ QMetaMethod# meta_method) :
34 _object_typecxx . . $ injeqt/internal/factory_method#_object_type.{meta_method.enclosingMetaObjectcxx . . $ QMetaMethod#enclosingMetaObject(216d4151dd9c9333).()},
35 _result_typecxx . . $ injeqt/internal/factory_method#_result_type.{stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(result_type)},
36 _meta_methodcxx . . $ injeqt/internal/factory_method#_meta_method.{stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(meta_method)}
37 {
38 assertcxx . . $ `/usr/include/assert.h:102:11`!(meta_method.methodType() == QMetaMethod::Method || meta_method.methodType() == QMetaMethod::Slot);
39 assertcxx . . $ `/usr/include/assert.h:102:11`!(meta_method.parameterCount() == 0);
40 assertcxx . . $ `/usr/include/assert.h:102:11`!(meta_method.enclosingMetaObject() != nullptr);
41 assertcxx . . $ `/usr/include/assert.h:102:11`!(!_result_type.is_empty());
42 assertcxx . . $ `/usr/include/assert.h:102:11`!(_result_type.name() + "*" == std::string{meta_method.typeName()});
43 }
44
45 bool factory_methodcxx . . $ injeqt/internal/factory_method#::is_emptycxx . . $ injeqt/internal/factory_method#is_empty(50ce9a9e25b4a850).() const
46 {
47 return !_meta_methodcxx . . $ injeqt/internal/factory_method#_meta_method..isValidcxx . . $ QMetaMethod#isValid(50ce9a9e25b4a850).();
48 }
49
50 const typecxx . . $ injeqt/v1/type# & factory_methodcxx . . $ injeqt/internal/factory_method#::object_typecxx . . $ injeqt/internal/factory_method#object_type(7e9f7f4e42b3414e).() const
51 {
52 return _object_typecxx . . $ injeqt/internal/factory_method#_object_type.;
53 }
54
55 const typecxx . . $ injeqt/v1/type# & factory_methodcxx . . $ injeqt/internal/factory_method#::result_typecxx . . $ injeqt/internal/factory_method#result_type(7e9f7f4e42b3414e).() const
56 {
57 return _result_typecxx . . $ injeqt/internal/factory_method#_result_type.;
58 }
59
60 const QMetaMethodcxx . . $ QMetaMethod# & factory_methodcxx . . $ injeqt/internal/factory_method#::meta_methodcxx . . $ injeqt/internal/factory_method#meta_method(9ea3a8eb2e51c72d).() const
61 {
62 return _meta_methodcxx . . $ injeqt/internal/factory_method#_meta_method.;
63 }
64
65 stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<QObjectcxx . . $ QObject#> factory_methodcxx . . $ injeqt/internal/factory_method#::invokecxx . . $ injeqt/internal/factory_method#invoke(a7ea179cf2951a58).(QObjectcxx . . $ QObject# *on) const
66 {
67 assertcxx . . $ `/usr/include/assert.h:102:11`!(!is_empty());
68 assertcxx . . $ `/usr/include/assert.h:102:11`!(on != nullptr);
69 assertcxx . . $ `/usr/include/assert.h:102:11`!(meta_method().enclosingMetaObject() == on->metaObject());
70
71 QObjectcxx . . $ QObject# *result = nullptr;
72 _meta_methodcxx . . $ injeqt/internal/factory_method#_meta_method..invokecxx . . $ QMetaMethod#invoke(54e01b8e39c3e246).(on, QReturnArgumentcxx . . $ QReturnArgument#QReturnArgument(ba6ffee53a50e91a).<QObjectcxx . . $ QObject# *>((_result_typecxx . . $ injeqt/internal/factory_method#_result_type..namecxx . . $ injeqt/v1/type#name(219584694fe2b248).() +cxx . . $ std/operator+(900ec9581c410ad9). "*").c_strcxx . . $ std/__cxx11/basic_string#c_str(1016ee5406d91ab9).(), result)); // TODO: check for false result
73 return stdcxx . . $ std/unique_ptr#unique_ptr(d6762fce684538e4).::unique_ptrcxx . . $ std/unique_ptr#<QObjectcxx . . $ QObject#>{result};
74 }
75
76 bool operatorcxx . . $ injeqt/internal/`operator==`(7ed92f845ff84f32). == (const factory_methodcxx . . $ injeqt/internal/factory_method# &x, const factory_methodcxx . . $ injeqt/internal/factory_method# &y)
77 {
78 if (x.object_typecxx . . $ injeqt/internal/factory_method#object_type(7e9f7f4e42b3414e).() !=cxx . . $ injeqt/v1/`operator!=`(24fd26303071bddf). y.object_typecxx . . $ injeqt/internal/factory_method#object_type(7e9f7f4e42b3414e).())
79 return false;
80
81 if (x.result_typecxx . . $ injeqt/internal/factory_method#result_type(7e9f7f4e42b3414e).() !=cxx . . $ injeqt/v1/`operator!=`(24fd26303071bddf). y.result_typecxx . . $ injeqt/internal/factory_method#result_type(7e9f7f4e42b3414e).())
82 return false;
83
84 return true;
85 }
86
87 bool operatorcxx . . $ injeqt/internal/`operator!=`(7ed92f845ff84f32). != (const factory_methodcxx . . $ injeqt/internal/factory_method# &x, const factory_methodcxx . . $ injeqt/internal/factory_method# &y)
88 {
89 return !(x ==cxx . . $ injeqt/internal/`operator==`(7ed92f845ff84f32). y);
90 }
91
92 factory_methodcxx . . $ injeqt/internal/factory_method# make_factory_methodcxx . . $ injeqt/internal/make_factory_method(de794affec8a70ca).(const types_by_namecxx . . $ injeqt/internal/types_by_name# &known_types, const typecxx . . $ injeqt/v1/type# &t, const typecxx . . $ injeqt/v1/type# &f)
93 {
94 assertcxx . . $ `/usr/include/assert.h:102:11`!(!t.is_empty());
95 assertcxx . . $ `/usr/include/assert.h:102:11`!(!t.is_qobject());
96 assertcxx . . $ `/usr/include/assert.h:102:11`!(!f.is_empty());
97 assertcxx . . $ `/usr/include/assert.h:102:11`!(!f.is_qobject());
98
99 auto meta_object = f.meta_objectcxx . . $ injeqt/v1/type#meta_object(216d4151dd9c9333).();
100 auto method_count = meta_object->methodCountcxx . . $ QMetaObject#methodCount(455f465bc33b4cdf).();
101 auto factory_methods = stdcxx . . $ std/vector#vector(b1ea180184b47f03).::vectorcxx . . $ std/vector#<factory_methodcxx . . $ injeqt/internal/factory_method#>{};
102
103 for (decltype(method_count) i = 0; i < method_count; i++)
104 {
105 auto method = meta_object->methodcxx . . $ QMetaObject#method(964508606e32bda3).(i);
106 if (method.parameterCountcxx . . $ QMetaMethod#parameterCount(455f465bc33b4cdf).() != 0)
107 continue;
108 auto return_type = type_by_pointercxx . . $ injeqt/internal/type_by_pointer(d5fc4731e87e33af).(known_types, methodcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)..typeNamecxx . . $ QMetaMethod#typeName(a9f41ea0e82d88cf).());
109 if (return_type.is_emptycxx . . $ injeqt/v1/type#is_empty(50ce9a9e25b4a850).())
110 continue;
111 auto interfaces = extract_interfacescxx . . $ injeqt/internal/extract_interfaces(859a62e7a8dc5225).(return_type);
112 if (interfaces.containscxx . . $ injeqt/internal/sorted_unique_vector#contains(83b2481dfe9844ed).(t))
113 factory_methods.emplace_backcxx . . $ std/vector#emplace_back(b3d147e3bb711c35).(return_type, method);
114 }
115
116 if (factory_methods.sizecxx . . $ std/vector#size(fe4d2d262d4164a8).() == 1)
117 return factory_methods.frontcxx . . $ std/vector#front(feee51535944b307).();
118 else
119 return factory_methodcxx . . $ injeqt/internal/factory_method#factory_method(49f6e7a06ebc5aa8).{};
120 }
121
122 }}