| 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 "provider.h"cxx . . $ `<file>/src/internal/provider.h`/ |
| 24 | |
| 25 | #include <functional> |
| 26 | #include <memory> |
| 27 | |
| 28 | using namespace injeqtcxx . . $ injeqt/::internal; |
| 29 | using namespace injeqtcxx . . $ injeqt/::v1; |
| 30 | |
| 31 | class mocked_providercxx . . $ mocked_provider# : public providercxx . . $ injeqt/internal/provider# |
| 32 | { |
| 33 | |
| 34 | public: |
| 35 | explicit mocked_providercxx . . $ mocked_provider#mocked_provider(d22659d133abbd6c).(typecxx . . $ injeqt/v1/type# provided_type, typescxx . . $ injeqt/internal/types# required_types, stdcxx . . $ std/::functioncxx . . $ std/function#<QObjectcxx . . $ QObject# *()> provide = [cxx . . $ std/function#function(a4b4b0c4acad1616).](){ return nullptr; }) : |
| 36 | _provided_typecxx . . $ mocked_provider#_provided_type.{stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(provided_type)}, |
| 37 | _required_typescxx . . $ mocked_provider#_required_types.{stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(required_types)}, |
| 38 | _providecxx . . $ mocked_provider#_provide.{stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(provide)}, |
| 39 | _objectcxx . . $ mocked_provider#_object.{nullptr} |
| 40 | {} |
| 41 | virtual ~cxx . . $ mocked_provider#`~mocked_provider`(49f6e7a06ebc5aa8).mocked_providercxx . . $ mocked_provider#() {} |
| 42 | |
| 43 | virtual const typecxx . . $ injeqt/v1/type# & provided_typecxx . . $ mocked_provider#provided_type(7e9f7f4e42b3414e).() const override { return _provided_typecxx . . $ mocked_provider#_provided_type.; }; |
| 44 | |
| 45 | virtual QObjectcxx . . $ QObject# * providecxx . . $ mocked_provider#provide(51123600412ca135).(injector_corecxx . . $ injeqt/internal/injector_core# &) override |
| 46 | { |
| 47 | if (!_objectcxx . . $ mocked_provider#_object.) |
| 48 | _objectcxx . . $ mocked_provider#_object. = _providecxx . . $ mocked_provider#_provide.(cxx . . $ std/function#`operator()`(39e0826ffb540481).); |
| 49 | return _objectcxx . . $ mocked_provider#_object.; |
| 50 | }; |
| 51 | |
| 52 | virtual typescxx . . $ injeqt/internal/types# required_typescxx . . $ mocked_provider#required_types(6f3e1a4b3e1e60c4).() const override { return _required_typescxx . . $ mocked_provider#_required_types.; }; |
| 53 | |
| 54 | virtual bool require_resolvingcxx . . $ mocked_provider#require_resolving(50ce9a9e25b4a850).() const override { return true; } |
| 55 | |
| 56 | QObjectcxx . . $ QObject# * objectcxx . . $ mocked_provider#object(2dbb680a34285c44).() const { return _objectcxx . . $ mocked_provider#_object.; } |
| 57 | |
| 58 | private: |
| 59 | typecxx . . $ injeqt/v1/type# _provided_typecxx . . $ mocked_provider#_provided_type.; |
| 60 | typescxx . . $ injeqt/internal/types# _required_typescxx . . $ mocked_provider#_required_types.; |
| 61 | stdcxx . . $ std/::functioncxx . . $ std/function#<QObjectcxx . . $ QObject# *()> _providecxx . . $ mocked_provider#_provide.; |
| 62 | QObjectcxx . . $ QObject# *_objectcxx . . $ mocked_provider#_object.; |
| 63 | |
| 64 | }; |
| 65 | |
| 66 | template<typename T, typename... R> |
| 67 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<mocked_providercxx . . $ mocked_provider#> make_mocked_providercxx . . $ make_mocked_provider(da0c43ecb02744cf).() |
| 68 | { |
| 69 | return stdcxx . . $ std/unique_ptr#unique_ptr(d6762fce684538e4).::unique_ptrcxx . . $ std/unique_ptr#<mocked_providercxx . . $ mocked_provider#>(new mocked_providercxx . . $ mocked_provider#{make_typecxx . . $ injeqt/v1/make_type(10a1ed948a80d481).<T>(), typescxx . . $ injeqt/internal/types#{make_typecxx . . $ injeqt/v1/make_type(10a1ed948a80d481).<R>()...}, [](){ return new T(); }}); |
| 70 | } |