Debian Codegraph @

src/injector.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 <injeqt/injector.h>
22
23 #include <injeqt/exception/empty-type.h>
24 #include <injeqt/exception/qobject-type.h>
25 #include <injeqt/module.h>
26
27 #include "containers.h"
28 #include "injector-impl.h"
29 #include "module-impl.h"
30 #include "provider.h"
31
32 #include <cassert>
33
34 using namespace injeqt::internal;
35
36 namespace injeqt { namespace v1 {
37
38 injector::injector() :
39 _pimpl{new ::injeqt::internal::injector_impl{}}
40 {
41 }
42
43 injector::injector(std::vector<std::unique_ptr<module>> modules) :
44 _pimpl{new ::injeqt::internal::injector_impl{std::move(modules)}}
45 {
46 }
47
48 injector::injector(std::vector<injector *> super_injectors, std::vector<std::unique_ptr<module>> modules)
49 {
50 auto extract_impl = std::function<injector_impl*(injector *)>([](injector *i){ return i->_pimpl.get(); });
51 _pimpl.reset(new ::injeqt::internal::injector_impl{transform(super_injectors, extract_impl), std::move(modules)});
52 }
53
54 injector::injector(injector &&x) :
55 _pimpl{std::move(x._pimpl)}
56 {
57 }
58
59 injector::~injector()
60 {
61 }
62
63 injector & injector::operator = (injector &&x)
64 {
65 _pimpl = std::move(x._pimpl);
66 return *this;
67 }
68
69 void injector::instantiate(const type &interface_type)
70 {
71 assert(!interface_type.is_empty());
72
73 if (interface_type.is_qobject())
74 throw exception::qobject_type{};
75
76 _pimpl->instantiate(interface_type);
77 }
78
79 void injector::instantiate_all_with_type_role(const std::string &type_role)
80 {
81 _pimpl->instantiate_all_with_type_role(type_role);
82 }
83
84 QObject * injector::get(const type &interface_type)
85 {
86 assert(!interface_type.is_empty());
87
88 if (interface_type.is_qobject())
89 throw exception::qobject_type{};
90
91 return _pimpl->get(interface_type);
92 }
93
94 std::vector<QObject *> injector::get_all_with_type_role(const std::string &type_role)
95 {
96 return _pimpl->get_all_with_type_role(type_role);
97 }
98
99 void injector::inject_into(QObject *object)
100 {
101 assert(object);
102
103 _pimpl->inject_into(object);
104 }
105
106 }}