Debian Codegraph @

src/internal/provider-by-factory-configuration.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 "provider-by-factory-configuration.h"
22
23 #include <injeqt/exception/qobject-type.h>
24 #include <injeqt/exception/unique-factory-method-not-found.h>
25
26 #include "factory-method.h"
27 #include "provider-by-factory.h"
28
29 #include <cassert>
30
31 namespace injeqt { namespace internal {
32
33 provider_by_factory_configuration::provider_by_factory_configuration(type object_type, type factory_type) :
34 _object_type{std::move(object_type)},
35 _factory_type{std::move(factory_type)}
36 {
37 assert(!_object_type.is_empty());
38 assert(!_factory_type.is_empty());
39 }
40
41 provider_by_factory_configuration::~provider_by_factory_configuration()
42 {
43 }
44
45 std::vector<type> provider_by_factory_configuration::types() const
46 {
47 return {_object_type, _factory_type};
48 }
49
50 std::unique_ptr<provider> provider_by_factory_configuration::create_provider(const types_by_name &known_types) const
51 {
52 if (_object_type.is_qobject())
53 throw exception::qobject_type();
54 if (_factory_type.is_qobject())
55 throw exception::qobject_type();
56
57 auto fm = internal::make_factory_method(known_types, _object_type, _factory_type);
58 if (fm.is_empty())
59 throw exception::unique_factory_method_not_found{_object_type.name() + " in " + _factory_type.name()};
60
61 return std::unique_ptr<provider_by_factory>{new provider_by_factory{std::move(fm)}};
62 }
63
64 }}