| 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 "action-method.h"cxx . . $ `<file>/src/internal/action-method.h`/ |
| 22 | |
| 23 | #include <injeqt/exception/invalid-action.h>cxx . . $ `<file>/include/injeqt/exception/invalid-action.h`/ |
| 24 | #include <injeqt/type.h>cxx . . $ `<file>/include/injeqt/type.h`/ |
| 25 | |
| 26 | #include "internal/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 action_methodcxx . . $ injeqt/internal/action_method#::is_action_init_tagcxx . . $ injeqt/internal/action_method#is_action_init_tag(7c222eea44a24d43).(const stdcxx . . $ std/::stringcxx . . $ std/string#& tag) |
| 33 | { |
| 34 | return tag ==cxx . . $ std/`operator==`(4b17aa87c9f300c6). "INJEQT_INIT"; |
| 35 | } |
| 36 | |
| 37 | bool action_methodcxx . . $ injeqt/internal/action_method#::is_action_done_tagcxx . . $ injeqt/internal/action_method#is_action_done_tag(7c222eea44a24d43).(const stdcxx . . $ std/::stringcxx . . $ std/string#& tag) |
| 38 | { |
| 39 | return tag ==cxx . . $ std/`operator==`(4b17aa87c9f300c6). "INJEQT_DONE"; |
| 40 | } |
| 41 | |
| 42 | bool action_methodcxx . . $ injeqt/internal/action_method#::validate_action_methodcxx . . $ injeqt/internal/action_method#validate_action_method(16241d0ce7586d0b).(const QMetaMethodcxx . . $ QMetaMethod# &meta_method) |
| 43 | { |
| 44 | auto meta_object = meta_method.enclosingMetaObjectcxx . . $ QMetaMethod#enclosingMetaObject(216d4151dd9c9333).(); |
| 45 | if (!meta_object) |
| 46 | throw exceptioncxx . . $ injeqt/v1/exception/invalid_action#invalid_action(8d4ab0a187bf9331).::invalid_actioncxx . . $ injeqt/v1/exception/invalid_action#{stdcxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f).::stringcxx . . $ std/string#{"action does not have enclosing meta object: "} +cxx . . $ std/operator+(900ec9581c410ad9). "?::" +cxx . . $ std/operator+(900ec9581c410ad9). meta_method.methodSignaturecxx . . $ QMetaMethod#methodSignature(a96750bfbcb1fbe9).().datacxx . . $ QByteArray#data(41208ce6ca65dd58).()}; |
| 47 | if (meta_method.methodTypecxx . . $ QMetaMethod#methodType(3a13d453cc434175).() == QMetaMethodcxx . . $ QMetaMethod#::Signalcxx . . $ QMetaMethod#Signal.) |
| 48 | throw exceptioncxx . . $ injeqt/v1/exception/invalid_action#invalid_action(8d4ab0a187bf9331).::invalid_actioncxx . . $ injeqt/v1/exception/invalid_action#{stdcxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f).::stringcxx . . $ std/string#{"action 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).()}; |
| 49 | if (meta_method.methodTypecxx . . $ QMetaMethod#methodType(3a13d453cc434175).() == QMetaMethodcxx . . $ QMetaMethod#::Constructorcxx . . $ QMetaMethod#Constructor.) |
| 50 | throw exceptioncxx . . $ injeqt/v1/exception/invalid_action#invalid_action(8d4ab0a187bf9331).::invalid_actioncxx . . $ injeqt/v1/exception/invalid_action#{stdcxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f).::stringcxx . . $ std/string#{"action 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).()}; |
| 51 | if (!is_action_init_tagcxx . . $ injeqt/internal/action_method#is_action_init_tag(7c222eea44a24d43).(meta_methodcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)..tagcxx . . $ QMetaMethod#tag(a9f41ea0e82d88cf).()) && !is_action_done_tagcxx . . $ injeqt/internal/action_method#is_action_done_tag(7c222eea44a24d43).(meta_methodcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)..tagcxx . . $ QMetaMethod#tag(a9f41ea0e82d88cf).())) |
| 52 | throw exceptioncxx . . $ injeqt/v1/exception/invalid_action#invalid_action(8d4ab0a187bf9331).::invalid_actioncxx . . $ injeqt/v1/exception/invalid_action#{stdcxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f).::stringcxx . . $ std/string#{"action 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).()}; |
| 53 | if (meta_method.parameterCountcxx . . $ QMetaMethod#parameterCount(455f465bc33b4cdf).() != 0) |
| 54 | throw exceptioncxx . . $ injeqt/v1/exception/invalid_action#invalid_action(8d4ab0a187bf9331).::invalid_actioncxx . . $ injeqt/v1/exception/invalid_action#{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).()}; |
| 55 | |
| 56 | return true; |
| 57 | } |
| 58 | |
| 59 | action_methodcxx . . $ injeqt/internal/action_method#::action_methodcxx . . $ injeqt/internal/action_method#action_method(49f6e7a06ebc5aa8).() |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | action_methodcxx . . $ injeqt/internal/action_method#::action_methodcxx . . $ injeqt/internal/action_method#action_method(77ddf0810175a47c).(QMetaMethodcxx . . $ QMetaMethod# meta_method) : |
| 64 | _object_typecxx . . $ injeqt/internal/action_method#_object_type.{meta_method.enclosingMetaObjectcxx . . $ QMetaMethod#enclosingMetaObject(216d4151dd9c9333).()}, |
| 65 | _meta_methodcxx . . $ injeqt/internal/action_method#_meta_method.{stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(meta_method)} |
| 66 | { |
| 67 | assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`!(validate_action_method(meta_method)); |
| 68 | } |
| 69 | |
| 70 | bool action_methodcxx . . $ injeqt/internal/action_method#::is_emptycxx . . $ injeqt/internal/action_method#is_empty(50ce9a9e25b4a850).() const |
| 71 | { |
| 72 | return !_meta_methodcxx . . $ injeqt/internal/action_method#_meta_method..isValidcxx . . $ QMetaMethod#isValid(50ce9a9e25b4a850).(); |
| 73 | } |
| 74 | |
| 75 | const typecxx . . $ injeqt/v1/type# & action_methodcxx . . $ injeqt/internal/action_method#::object_typecxx . . $ injeqt/internal/action_method#object_type(7e9f7f4e42b3414e).() const |
| 76 | { |
| 77 | return _object_typecxx . . $ injeqt/internal/action_method#_object_type.; |
| 78 | } |
| 79 | |
| 80 | bool action_methodcxx . . $ injeqt/internal/action_method#::invokecxx . . $ injeqt/internal/action_method#invoke(a7755beb02b388f3).(QObjectcxx . . $ QObject# *on) const |
| 81 | { |
| 82 | assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`!(!is_empty()); |
| 83 | assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`!(on != nullptr); |
| 84 | assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`!(implements(type{on->metaObject()}, _object_type)); |
| 85 | |
| 86 | return _meta_methodcxx . . $ injeqt/internal/action_method#_meta_method..invokecxx . . $ QMetaMethod#invoke(de6e418c71b84c23).(on); |
| 87 | } |
| 88 | |
| 89 | action_methodcxx . . $ injeqt/internal/action_method# make_action_methodcxx . . $ injeqt/internal/make_action_method(91c31e8fb4d6933).(const QMetaMethodcxx . . $ QMetaMethod# &meta_method) |
| 90 | { |
| 91 | action_methodcxx . . $ injeqt/internal/action_method#::validate_action_methodcxx . . $ injeqt/internal/action_method#validate_action_method(16241d0ce7586d0b).(meta_method); |
| 92 | |
| 93 | return action_methodcxx . . $ injeqt/internal/action_method#action_method(77ddf0810175a47c).{meta_method}; |
| 94 | } |
| 95 | |
| 96 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<action_methodcxx . . $ injeqt/internal/action_method#> extract_actionscxx . . $ injeqt/internal/extract_actions(e128403a847e2c67).(const stdcxx . . $ std/::stringcxx . . $ std/string# &action_tag, const typecxx . . $ injeqt/v1/type# &for_type) |
| 97 | { |
| 98 | assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`!(!for_type.is_empty()); |
| 99 | |
| 100 | auto result = stdcxx . . $ std/vector#vector(b1ea180184b47f03).::vectorcxx . . $ std/vector#<action_methodcxx . . $ injeqt/internal/action_method#>{}; |
| 101 | |
| 102 | auto meta_object = for_type.meta_objectcxx . . $ injeqt/v1/type#meta_object(216d4151dd9c9333).(); |
| 103 | auto method_count = meta_object->methodCountcxx . . $ QMetaObject#methodCount(455f465bc33b4cdf).(); |
| 104 | for (decltype(method_count) i = 0; i < method_count; i++) |
| 105 | { |
| 106 | auto probably_action = meta_object->methodcxx . . $ QMetaObject#method(964508606e32bda3).(i); |
| 107 | auto method_tag = stdcxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f).::stringcxx . . $ std/string#{probably_action.tagcxx . . $ QMetaMethod#tag(a9f41ea0e82d88cf).()}; |
| 108 | if (action_tag ==cxx . . $ std/`operator==`(2965e344aacb545b). method_tag) |
| 109 | result.emplace_backcxx . . $ std/vector#emplace_back(b3d147e3bb711c35).(make_action_methodcxx . . $ injeqt/internal/make_action_method(91c31e8fb4d6933).(probably_action)); |
| 110 | } |
| 111 | |
| 112 | return resultcxx . . $ std/vector#vector(b1ea180184b47f03).; |
| 113 | } |
| 114 | |
| 115 | }} |