| 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 "setter-method.h"cxx . . $ `<file>/src/internal/setter-method.h`/ |
| 22 | |
| 23 | #include <injeqt/exception/invalid-setter.h>cxx . . $ `<file>/include/injeqt/exception/invalid-setter.h`/ |
| 24 | #include <injeqt/type.h>cxx . . $ `<file>/include/injeqt/type.h`/ |
| 25 | |
| 26 | #include "interfaces-utils.h"cxx . . $ `<file>/src/internal/interfaces-utils.h`/ |
| 27 | |
| 28 | #include <cassert> |
| 29 | |
| 30 | namespace injeqtcxx . . $ injeqt/ { namespace internalcxx . . $ injeqt/internal/ { |
| 31 | |
| 32 | bool setter_methodcxx . . $ injeqt/internal/setter_method#::is_setter_tagcxx . . $ injeqt/internal/setter_method#is_setter_tag(7c222eea44a24d43).(const stdcxx . . $ std/::stringcxx . . $ std/string# &tag) |
| 33 | { |
| 34 | return tag ==cxx . . $ std/`operator==`(4b17aa87c9f300c6). "INJEQT_SET" || tag ==cxx . . $ std/`operator==`(4b17aa87c9f300c6). "INJEQT_SETTER"; |
| 35 | } |
| 36 | |
| 37 | bool setter_methodcxx . . $ injeqt/internal/setter_method#::validate_setter_methodcxx . . $ injeqt/internal/setter_method#validate_setter_method(8a206fd587b7d7a4).(typecxx . . $ injeqt/v1/type# parameter_type, const QMetaMethodcxx . . $ QMetaMethod# &meta_method) |
| 38 | { |
| 39 | auto meta_object = meta_method.enclosingMetaObjectcxx . . $ QMetaMethod#enclosingMetaObject(216d4151dd9c9333).(); |
| 40 | if (!meta_object) |
| 41 | throw exceptioncxx . . $ injeqt/v1/exception/invalid_setter#invalid_setter(8d4ab0a187bf9331).::invalid_settercxx . . $ injeqt/v1/exception/invalid_setter#{stdcxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f).::stringcxx . . $ std/string#{"setter does not have enclosing meta object: "} +cxx . . $ std/operator+(900ec9581c410ad9). "?::" +cxx . . $ std/operator+(900ec9581c410ad9). meta_method.methodSignaturecxx . . $ QMetaMethod#methodSignature(a96750bfbcb1fbe9).().datacxx . . $ QByteArray#data(41208ce6ca65dd58).()}; |
| 42 | if (meta_method.methodTypecxx . . $ QMetaMethod#methodType(3a13d453cc434175).() == QMetaMethodcxx . . $ QMetaMethod#::Signalcxx . . $ QMetaMethod#Signal.) |
| 43 | throw exceptioncxx . . $ injeqt/v1/exception/invalid_setter#invalid_setter(8d4ab0a187bf9331).::invalid_settercxx . . $ injeqt/v1/exception/invalid_setter#{stdcxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f).::stringcxx . . $ std/string#{"setter is signal: "} +cxx . . $ std/operator+(900ec9581c410ad9). meta_object->classNamecxx . . $ QMetaObject#className(a9f41ea0e82d88cf).() +cxx . . $ std/operator+(900ec9581c410ad9). "::" +cxx . . $ std/operator+(900ec9581c410ad9). meta_method.methodSignaturecxx . . $ QMetaMethod#methodSignature(a96750bfbcb1fbe9).().datacxx . . $ QByteArray#data(41208ce6ca65dd58).()}; |
| 44 | if (meta_method.methodTypecxx . . $ QMetaMethod#methodType(3a13d453cc434175).() == QMetaMethodcxx . . $ QMetaMethod#::Constructorcxx . . $ QMetaMethod#Constructor.) |
| 45 | throw exceptioncxx . . $ injeqt/v1/exception/invalid_setter#invalid_setter(8d4ab0a187bf9331).::invalid_settercxx . . $ injeqt/v1/exception/invalid_setter#{stdcxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f).::stringcxx . . $ std/string#{"setter is constructor: "} +cxx . . $ std/operator+(900ec9581c410ad9). meta_object->classNamecxx . . $ QMetaObject#className(a9f41ea0e82d88cf).() +cxx . . $ std/operator+(900ec9581c410ad9). "::" +cxx . . $ std/operator+(900ec9581c410ad9). meta_method.methodSignaturecxx . . $ QMetaMethod#methodSignature(a96750bfbcb1fbe9).().datacxx . . $ QByteArray#data(41208ce6ca65dd58).()}; |
| 46 | if (!is_setter_tagcxx . . $ injeqt/internal/setter_method#is_setter_tag(7c222eea44a24d43).(meta_methodcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)..tagcxx . . $ QMetaMethod#tag(a9f41ea0e82d88cf).())) |
| 47 | throw exceptioncxx . . $ injeqt/v1/exception/invalid_setter#invalid_setter(8d4ab0a187bf9331).::invalid_settercxx . . $ injeqt/v1/exception/invalid_setter#{stdcxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f).::stringcxx . . $ std/string#{"setter does not have valid tag: "} +cxx . . $ std/operator+(900ec9581c410ad9). meta_object->classNamecxx . . $ QMetaObject#className(a9f41ea0e82d88cf).() +cxx . . $ std/operator+(900ec9581c410ad9). "::" +cxx . . $ std/operator+(900ec9581c410ad9). meta_method.methodSignaturecxx . . $ QMetaMethod#methodSignature(a96750bfbcb1fbe9).().datacxx . . $ QByteArray#data(41208ce6ca65dd58).()}; |
| 48 | if (meta_method.parameterCountcxx . . $ QMetaMethod#parameterCount(455f465bc33b4cdf).() != 1) |
| 49 | throw exceptioncxx . . $ injeqt/v1/exception/invalid_setter#invalid_setter(8d4ab0a187bf9331).::invalid_settercxx . . $ injeqt/v1/exception/invalid_setter#{stdcxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f).::stringcxx . . $ std/string#{"invalid parameter count: "} +cxx . . $ std/operator+(900ec9581c410ad9). meta_object->classNamecxx . . $ QMetaObject#className(a9f41ea0e82d88cf).() +cxx . . $ std/operator+(900ec9581c410ad9). "::" +cxx . . $ std/operator+(900ec9581c410ad9). meta_method.methodSignaturecxx . . $ QMetaMethod#methodSignature(a96750bfbcb1fbe9).().datacxx . . $ QByteArray#data(41208ce6ca65dd58).()}; |
| 50 | if (parameter_type.is_emptycxx . . $ injeqt/v1/type#is_empty(50ce9a9e25b4a850).() || parameter_type.is_qobjectcxx . . $ injeqt/v1/type#is_qobject(50ce9a9e25b4a850).()) |
| 51 | throw exceptioncxx . . $ injeqt/v1/exception/invalid_setter#invalid_setter(8d4ab0a187bf9331).::invalid_settercxx . . $ injeqt/v1/exception/invalid_setter#{stdcxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f).::stringcxx . . $ std/string#{"invalid parameter (empty): "} +cxx . . $ std/operator+(900ec9581c410ad9). meta_object->classNamecxx . . $ QMetaObject#className(a9f41ea0e82d88cf).() +cxx . . $ std/operator+(900ec9581c410ad9). "::" +cxx . . $ std/operator+(900ec9581c410ad9). meta_method.methodSignaturecxx . . $ QMetaMethod#methodSignature(a96750bfbcb1fbe9).().datacxx . . $ QByteArray#data(41208ce6ca65dd58).()}; |
| 52 | if (parameter_type.is_emptycxx . . $ injeqt/v1/type#is_empty(50ce9a9e25b4a850).()) |
| 53 | throw exceptioncxx . . $ injeqt/v1/exception/invalid_setter#invalid_setter(8d4ab0a187bf9331).::invalid_settercxx . . $ injeqt/v1/exception/invalid_setter#{stdcxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f).::stringcxx . . $ std/string#{"invalid parameter (qobject): "} +cxx . . $ std/operator+(900ec9581c410ad9). meta_object->classNamecxx . . $ QMetaObject#className(a9f41ea0e82d88cf).() +cxx . . $ std/operator+(900ec9581c410ad9). "::" +cxx . . $ std/operator+(900ec9581c410ad9). meta_method.methodSignaturecxx . . $ QMetaMethod#methodSignature(a96750bfbcb1fbe9).().datacxx . . $ QByteArray#data(41208ce6ca65dd58).()}; |
| 54 | if (parameter_type.namecxx . . $ injeqt/v1/type#name(219584694fe2b248).() +cxx . . $ std/operator+(900ec9581c410ad9). "*" !=cxx . . $ std/`operator!=`(2965e344aacb545b). stdcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).::stringcxx . . $ std/string#{meta_method.parameterTypescxx . . $ QMetaMethod#parameterTypes(28ffaf7c70e71a05).()[cxx . . $ QList#`operator[]`(7a0ef1c7079e8533).0].datacxx . . $ QByteArray#data(41208ce6ca65dd58).()}) |
| 55 | throw exceptioncxx . . $ injeqt/v1/exception/invalid_setter#invalid_setter(8d4ab0a187bf9331).::invalid_settercxx . . $ injeqt/v1/exception/invalid_setter#{stdcxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f).::stringcxx . . $ std/string#{"invalid parameter (type): "} +cxx . . $ std/operator+(900ec9581c410ad9). meta_object->classNamecxx . . $ QMetaObject#className(a9f41ea0e82d88cf).() +cxx . . $ std/operator+(900ec9581c410ad9). "::" +cxx . . $ std/operator+(900ec9581c410ad9). meta_method.methodSignaturecxx . . $ QMetaMethod#methodSignature(a96750bfbcb1fbe9).().datacxx . . $ QByteArray#data(41208ce6ca65dd58).()}; |
| 56 | return true; |
| 57 | } |
| 58 | |
| 59 | setter_methodcxx . . $ injeqt/internal/setter_method#::setter_methodcxx . . $ injeqt/internal/setter_method#setter_method(49f6e7a06ebc5aa8).() |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | setter_methodcxx . . $ injeqt/internal/setter_method#::setter_methodcxx . . $ injeqt/internal/setter_method#setter_method(88aafc8b4e97b263).(typecxx . . $ injeqt/v1/type# parameter_type, QMetaMethodcxx . . $ QMetaMethod# meta_method) : |
| 64 | _object_typecxx . . $ injeqt/internal/setter_method#_object_type.{meta_method.enclosingMetaObjectcxx . . $ QMetaMethod#enclosingMetaObject(216d4151dd9c9333).()}, |
| 65 | _parameter_typecxx . . $ injeqt/internal/setter_method#_parameter_type.{stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(parameter_type)}, |
| 66 | _meta_methodcxx . . $ injeqt/internal/setter_method#_meta_method.{stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(meta_method)} |
| 67 | { |
| 68 | assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`!(validate_setter_method(parameter_type, meta_method)); |
| 69 | } |
| 70 | |
| 71 | bool setter_methodcxx . . $ injeqt/internal/setter_method#::is_emptycxx . . $ injeqt/internal/setter_method#is_empty(50ce9a9e25b4a850).() const |
| 72 | { |
| 73 | return !_meta_methodcxx . . $ injeqt/internal/setter_method#_meta_method..isValidcxx . . $ QMetaMethod#isValid(50ce9a9e25b4a850).(); |
| 74 | } |
| 75 | |
| 76 | const typecxx . . $ injeqt/v1/type# & setter_methodcxx . . $ injeqt/internal/setter_method#::object_typecxx . . $ injeqt/internal/setter_method#object_type(7e9f7f4e42b3414e).() const |
| 77 | { |
| 78 | return _object_typecxx . . $ injeqt/internal/setter_method#_object_type.; |
| 79 | } |
| 80 | |
| 81 | const typecxx . . $ injeqt/v1/type# & setter_methodcxx . . $ injeqt/internal/setter_method#::parameter_typecxx . . $ injeqt/internal/setter_method#parameter_type(7e9f7f4e42b3414e).() const |
| 82 | { |
| 83 | return _parameter_typecxx . . $ injeqt/internal/setter_method#_parameter_type.; |
| 84 | } |
| 85 | |
| 86 | const QMetaMethodcxx . . $ QMetaMethod# & setter_methodcxx . . $ injeqt/internal/setter_method#::meta_methodcxx . . $ injeqt/internal/setter_method#meta_method(9ea3a8eb2e51c72d).() const |
| 87 | { |
| 88 | return _meta_methodcxx . . $ injeqt/internal/setter_method#_meta_method.; |
| 89 | } |
| 90 | |
| 91 | stdcxx . . $ std/::stringcxx . . $ std/string# setter_methodcxx . . $ injeqt/internal/setter_method#::signaturecxx . . $ injeqt/internal/setter_method#signature(219584694fe2b248).() const |
| 92 | { |
| 93 | returncxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). _meta_methodcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)..methodSignaturecxx . . $ QMetaMethod#methodSignature(a96750bfbcb1fbe9).().datacxx . . $ QByteArray#data(41208ce6ca65dd58).(); |
| 94 | } |
| 95 | |
| 96 | bool setter_methodcxx . . $ injeqt/internal/setter_method#::invokecxx . . $ injeqt/internal/setter_method#invoke(77edfd4708c3eca3).(QObjectcxx . . $ QObject# *on, QObjectcxx . . $ QObject# *parameter) const |
| 97 | { |
| 98 | assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`!(!is_empty()); |
| 99 | assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`!(on != nullptr); |
| 100 | assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`!(implements(type{on->metaObject()}, _object_type)); |
| 101 | assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`!(parameter != nullptr); |
| 102 | assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`!(!type{parameter->metaObject()}.is_empty()); |
| 103 | assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`!(implements(type{parameter->metaObject()}, _parameter_type)); |
| 104 | |
| 105 | return _meta_methodcxx . . $ injeqt/internal/setter_method#_meta_method..invokecxx . . $ QMetaMethod#invoke(de6e418c71b84c23).(on, Q_ARGcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:279:9`!(QObject *, parameter)); |
| 106 | } |
| 107 | |
| 108 | bool operatorcxx . . $ injeqt/internal/`operator==`(7f5d6930c12df87c). == (const setter_methodcxx . . $ injeqt/internal/setter_method# &x, const setter_methodcxx . . $ injeqt/internal/setter_method# &y) |
| 109 | { |
| 110 | if (x.object_typecxx . . $ injeqt/internal/setter_method#object_type(7e9f7f4e42b3414e).() !=cxx . . $ injeqt/v1/`operator!=`(24fd26303071bddf). y.object_typecxx . . $ injeqt/internal/setter_method#object_type(7e9f7f4e42b3414e).()) |
| 111 | return false; |
| 112 | |
| 113 | if (x.parameter_typecxx . . $ injeqt/internal/setter_method#parameter_type(7e9f7f4e42b3414e).() !=cxx . . $ injeqt/v1/`operator!=`(24fd26303071bddf). y.parameter_typecxx . . $ injeqt/internal/setter_method#parameter_type(7e9f7f4e42b3414e).()) |
| 114 | return false; |
| 115 | |
| 116 | if (x.meta_methodcxx . . $ injeqt/internal/setter_method#meta_method(9ea3a8eb2e51c72d).() !=cxx . . $ `operator!=`(f3156cea159acecb). y.meta_methodcxx . . $ injeqt/internal/setter_method#meta_method(9ea3a8eb2e51c72d).()) |
| 117 | return false; |
| 118 | |
| 119 | return true; |
| 120 | } |
| 121 | |
| 122 | bool operatorcxx . . $ injeqt/internal/`operator!=`(7f5d6930c12df87c). != (const setter_methodcxx . . $ injeqt/internal/setter_method# &x, const setter_methodcxx . . $ injeqt/internal/setter_method# &y) |
| 123 | { |
| 124 | return !(x ==cxx . . $ injeqt/internal/`operator==`(7f5d6930c12df87c). y); |
| 125 | } |
| 126 | |
| 127 | bool operatorcxx . . $ injeqt/internal/`operator<`(7f5d6930c12df87c). < (const setter_methodcxx . . $ injeqt/internal/setter_method# &x, const setter_methodcxx . . $ injeqt/internal/setter_method# &y) |
| 128 | { |
| 129 | if (x.object_typecxx . . $ injeqt/internal/setter_method#object_type(7e9f7f4e42b3414e).() <cxx . . $ injeqt/v1/`operator<`(24fd26303071bddf). y.object_typecxx . . $ injeqt/internal/setter_method#object_type(7e9f7f4e42b3414e).()) |
| 130 | return true; |
| 131 | |
| 132 | if (x.object_typecxx . . $ injeqt/internal/setter_method#object_type(7e9f7f4e42b3414e).() >cxx . . $ injeqt/v1/`operator>`(24fd26303071bddf). y.object_typecxx . . $ injeqt/internal/setter_method#object_type(7e9f7f4e42b3414e).()) |
| 133 | return false; |
| 134 | |
| 135 | if (x.parameter_typecxx . . $ injeqt/internal/setter_method#parameter_type(7e9f7f4e42b3414e).() <cxx . . $ injeqt/v1/`operator<`(24fd26303071bddf). y.parameter_typecxx . . $ injeqt/internal/setter_method#parameter_type(7e9f7f4e42b3414e).()) |
| 136 | return true; |
| 137 | |
| 138 | if (x.parameter_typecxx . . $ injeqt/internal/setter_method#parameter_type(7e9f7f4e42b3414e).() >cxx . . $ injeqt/v1/`operator>`(24fd26303071bddf). y.parameter_typecxx . . $ injeqt/internal/setter_method#parameter_type(7e9f7f4e42b3414e).()) |
| 139 | return false; |
| 140 | |
| 141 | return x.meta_methodcxx . . $ injeqt/internal/setter_method#meta_method(9ea3a8eb2e51c72d).().methodSignaturecxx . . $ QMetaMethod#methodSignature(a96750bfbcb1fbe9).() <cxx . . $ `operator<`(5ad6b2491b335728). y.meta_methodcxx . . $ injeqt/internal/setter_method#meta_method(9ea3a8eb2e51c72d).().methodSignaturecxx . . $ QMetaMethod#methodSignature(a96750bfbcb1fbe9).(); |
| 142 | } |
| 143 | |
| 144 | bool operatorcxx . . $ injeqt/internal/`operator>`(7f5d6930c12df87c). > (const setter_methodcxx . . $ injeqt/internal/setter_method# &x, const setter_methodcxx . . $ injeqt/internal/setter_method# &y) |
| 145 | { |
| 146 | return y <cxx . . $ injeqt/internal/`operator<`(7f5d6930c12df87c). x; |
| 147 | } |
| 148 | |
| 149 | bool operatorcxx . . $ injeqt/internal/`operator<=`(7f5d6930c12df87c). <= (const setter_methodcxx . . $ injeqt/internal/setter_method# &x, const setter_methodcxx . . $ injeqt/internal/setter_method# &y) |
| 150 | { |
| 151 | return !(y <cxx . . $ injeqt/internal/`operator<`(7f5d6930c12df87c). x); |
| 152 | } |
| 153 | |
| 154 | bool operatorcxx . . $ injeqt/internal/`operator>=`(7f5d6930c12df87c). >= (const setter_methodcxx . . $ injeqt/internal/setter_method# &x, const setter_methodcxx . . $ injeqt/internal/setter_method# &y) |
| 155 | { |
| 156 | return !(x <cxx . . $ injeqt/internal/`operator<`(7f5d6930c12df87c). y); |
| 157 | } |
| 158 | |
| 159 | setter_methodcxx . . $ injeqt/internal/setter_method# make_setter_methodcxx . . $ injeqt/internal/make_setter_method(5a3e1df2da4658bb).(const types_by_namecxx . . $ injeqt/internal/types_by_name# &known_types, const QMetaMethodcxx . . $ QMetaMethod# &meta_method) |
| 160 | { |
| 161 | auto parameter_type = meta_method.parameterCountcxx . . $ QMetaMethod#parameterCount(455f465bc33b4cdf).() == 1 |
| 162 | ? type_by_pointercxx . . $ injeqt/internal/type_by_pointer(d5fc4731e87e33af).(known_types, meta_methodcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)..parameterTypescxx . . $ QMetaMethod#parameterTypes(28ffaf7c70e71a05).()[cxx . . $ QList#`operator[]`(7a0ef1c7079e8533).0].datacxx . . $ QByteArray#data(41208ce6ca65dd58).()) |
| 163 | : typecxx . . $ injeqt/v1/type#type(f870fe3066718694).{nullptr}; |
| 164 | setter_methodcxx . . $ injeqt/internal/setter_method#::validate_setter_methodcxx . . $ injeqt/internal/setter_method#validate_setter_method(8a206fd587b7d7a4).(parameter_type, meta_method); |
| 165 | |
| 166 | return setter_methodcxx . . $ injeqt/internal/setter_method#setter_method(88aafc8b4e97b263).{parameter_type, meta_method}; |
| 167 | } |
| 168 | |
| 169 | }} |