| 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 "implementation.h"cxx . . $ `<file>/src/internal/implementation.h`/ |
| 22 | |
| 23 | #include <injeqt/exception/empty-type.h>cxx . . $ `<file>/include/injeqt/exception/empty-type.h`/ |
| 24 | #include <injeqt/exception/interface-not-implemented.h>cxx . . $ `<file>/include/injeqt/exception/interface-not-implemented.h`/ |
| 25 | #include <injeqt/exception/invalid-qobject.h>cxx . . $ `<file>/include/injeqt/exception/invalid-qobject.h`/ |
| 26 | #include <injeqt/exception/qobject-type.h>cxx . . $ `<file>/include/injeqt/exception/qobject-type.h`/ |
| 27 | |
| 28 | #include "interfaces-utils.h"cxx . . $ `<file>/src/internal/interfaces-utils.h`/ |
| 29 | |
| 30 | #include <QtCore/QObject> |
| 31 | #include <cassert> |
| 32 | |
| 33 | namespace injeqtcxx . . $ injeqt/ { namespace internalcxx . . $ injeqt/internal/ { |
| 34 | |
| 35 | implementationcxx . . $ injeqt/internal/implementation#::implementationcxx . . $ injeqt/internal/implementation#implementation(9ea1470f0de69db5).(typecxx . . $ injeqt/v1/type# interface_type, QObjectcxx . . $ QObject# *object) : |
| 36 | _interface_typecxx . . $ injeqt/internal/implementation#_interface_type.{stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(interface_type)}, |
| 37 | _objectcxx . . $ injeqt/internal/implementation#_object.{object} |
| 38 | { |
| 39 | assertcxx . . $ `/usr/include/assert.h:102:11`!(!_interface_type.is_empty()); |
| 40 | assertcxx . . $ `/usr/include/assert.h:102:11`!(!_interface_type.is_qobject()); |
| 41 | assertcxx . . $ `/usr/include/assert.h:102:11`!(_object != nullptr); |
| 42 | assertcxx . . $ `/usr/include/assert.h:102:11`!(_object->metaObject() != nullptr); |
| 43 | assertcxx . . $ `/usr/include/assert.h:102:11`!(extract_interfaces(type{_object->metaObject()}).contains(_interface_type)); |
| 44 | } |
| 45 | |
| 46 | const typecxx . . $ injeqt/v1/type# & implementationcxx . . $ injeqt/internal/implementation#::interface_typecxx . . $ injeqt/internal/implementation#interface_type(7e9f7f4e42b3414e).() const |
| 47 | { |
| 48 | return _interface_typecxx . . $ injeqt/internal/implementation#_interface_type.; |
| 49 | } |
| 50 | |
| 51 | QObjectcxx . . $ QObject# * implementationcxx . . $ injeqt/internal/implementation#::objectcxx . . $ injeqt/internal/implementation#object(2dbb680a34285c44).() const |
| 52 | { |
| 53 | return _objectcxx . . $ injeqt/internal/implementation#_object.; |
| 54 | } |
| 55 | |
| 56 | bool operatorcxx . . $ injeqt/internal/`operator==`(a47c5f57c455a7c1). == (const implementationcxx . . $ injeqt/internal/implementation# &x, const implementationcxx . . $ injeqt/internal/implementation# &y) |
| 57 | { |
| 58 | if (x.interface_typecxx . . $ injeqt/internal/implementation#interface_type(7e9f7f4e42b3414e).() !=cxx . . $ injeqt/v1/`operator!=`(24fd26303071bddf). y.interface_typecxx . . $ injeqt/internal/implementation#interface_type(7e9f7f4e42b3414e).()) |
| 59 | return false; |
| 60 | |
| 61 | if (x.objectcxx . . $ injeqt/internal/implementation#object(2dbb680a34285c44).() != y.objectcxx . . $ injeqt/internal/implementation#object(2dbb680a34285c44).()) |
| 62 | return false; |
| 63 | |
| 64 | return true; |
| 65 | } |
| 66 | |
| 67 | bool operatorcxx . . $ injeqt/internal/`operator!=`(a47c5f57c455a7c1). != (const implementationcxx . . $ injeqt/internal/implementation# &x, const implementationcxx . . $ injeqt/internal/implementation# &y) |
| 68 | { |
| 69 | return !(x ==cxx . . $ injeqt/internal/`operator==`(a47c5f57c455a7c1). y); |
| 70 | } |
| 71 | |
| 72 | bool operatorcxx . . $ injeqt/internal/`operator<`(a47c5f57c455a7c1). < (const implementationcxx . . $ injeqt/internal/implementation# &x, const implementationcxx . . $ injeqt/internal/implementation# &y) |
| 73 | { |
| 74 | if (x.interface_typecxx . . $ injeqt/internal/implementation#interface_type(7e9f7f4e42b3414e).() <cxx . . $ injeqt/v1/`operator<`(24fd26303071bddf). y.interface_typecxx . . $ injeqt/internal/implementation#interface_type(7e9f7f4e42b3414e).()) |
| 75 | return true; |
| 76 | if (x.interface_typecxx . . $ injeqt/internal/implementation#interface_type(7e9f7f4e42b3414e).() >cxx . . $ injeqt/v1/`operator>`(24fd26303071bddf). y.interface_typecxx . . $ injeqt/internal/implementation#interface_type(7e9f7f4e42b3414e).()) |
| 77 | return false; |
| 78 | |
| 79 | return x.objectcxx . . $ injeqt/internal/implementation#object(2dbb680a34285c44).() < y.objectcxx . . $ injeqt/internal/implementation#object(2dbb680a34285c44).(); |
| 80 | } |
| 81 | |
| 82 | bool operatorcxx . . $ injeqt/internal/`operator>`(a47c5f57c455a7c1). > (const implementationcxx . . $ injeqt/internal/implementation# &x, const implementationcxx . . $ injeqt/internal/implementation# &y) |
| 83 | { |
| 84 | return y <cxx . . $ injeqt/internal/`operator<`(a47c5f57c455a7c1). x; |
| 85 | } |
| 86 | |
| 87 | bool operatorcxx . . $ injeqt/internal/`operator<=`(a47c5f57c455a7c1). <= (const implementationcxx . . $ injeqt/internal/implementation# &x, const implementationcxx . . $ injeqt/internal/implementation# &y) |
| 88 | { |
| 89 | return !(y <cxx . . $ injeqt/internal/`operator<`(a47c5f57c455a7c1). x); |
| 90 | } |
| 91 | |
| 92 | bool operatorcxx . . $ injeqt/internal/`operator>=`(a47c5f57c455a7c1). >= (const implementationcxx . . $ injeqt/internal/implementation# &x, const implementationcxx . . $ injeqt/internal/implementation# &y) |
| 93 | { |
| 94 | return !(x <cxx . . $ injeqt/internal/`operator<`(a47c5f57c455a7c1). y); |
| 95 | } |
| 96 | |
| 97 | implementationcxx . . $ injeqt/internal/implementation# make_implementationcxx . . $ injeqt/internal/make_implementation(2322beed4ceffcb6).(typecxx . . $ injeqt/v1/type# interface_type, QObjectcxx . . $ QObject# *object) |
| 98 | { |
| 99 | if (interface_type.is_emptycxx . . $ injeqt/v1/type#is_empty(50ce9a9e25b4a850).()) |
| 100 | throw exceptioncxx . . $ injeqt/v1/exception/empty_type#empty_type(8d4ab0a187bf9331).::empty_typecxx . . $ injeqt/v1/exception/empty_type#{}; |
| 101 | if (interface_type.is_qobjectcxx . . $ injeqt/v1/type#is_qobject(50ce9a9e25b4a850).()) |
| 102 | throw exceptioncxx . . $ injeqt/v1/exception/qobject_type#qobject_type(8d4ab0a187bf9331).::qobject_typecxx . . $ injeqt/v1/exception/qobject_type#(); |
| 103 | if (!object || !object->metaObjectcxx . . $ QObject#metaObject(216d4151dd9c9333).()) |
| 104 | throw exceptioncxx . . $ injeqt/v1/exception/invalid_qobject#invalid_qobject(8d4ab0a187bf9331).::invalid_qobjectcxx . . $ injeqt/v1/exception/invalid_qobject#{}; |
| 105 | if (!implementscxx . . $ injeqt/internal/implements(24fd26303071bddf).(typecxx . . $ injeqt/v1/type#type(f870fe3066718694).{object->metaObjectcxx . . $ QObject#metaObject(216d4151dd9c9333).()}, interface_type)) |
| 106 | throw exceptioncxx . . $ injeqt/v1/exception/interface_not_implemented#interface_not_implemented(8d4ab0a187bf9331).::interface_not_implementedcxx . . $ injeqt/v1/exception/interface_not_implemented#{typecxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f).{object->metaObjectcxx . . $ QObject#metaObject(216d4151dd9c9333).()}.namecxx . . $ injeqt/v1/type#name(219584694fe2b248).() +cxx . . $ std/operator+(900ec9581c410ad9). ": " +cxx . . $ std/operator+(aa1c00e85b87da6b). interface_type.namecxx . . $ injeqt/v1/type#name(219584694fe2b248).()}; |
| 107 | |
| 108 | return implementationcxx . . $ injeqt/internal/implementation#implementation(9ea1470f0de69db5).{interface_type, object}; |
| 109 | } |
| 110 | |
| 111 | }} |