Debian Codegraph @

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