1*a65addddSAndroid Build Coastguard Worker /*
2*a65addddSAndroid Build Coastguard Worker * Copyright 2014 Google Inc. All rights reserved.
3*a65addddSAndroid Build Coastguard Worker *
4*a65addddSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*a65addddSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*a65addddSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*a65addddSAndroid Build Coastguard Worker *
8*a65addddSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*a65addddSAndroid Build Coastguard Worker *
10*a65addddSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*a65addddSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*a65addddSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*a65addddSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*a65addddSAndroid Build Coastguard Worker * limitations under the License.
15*a65addddSAndroid Build Coastguard Worker */
16*a65addddSAndroid Build Coastguard Worker
17*a65addddSAndroid Build Coastguard Worker #ifndef FRUIT_PROVIDER_DEFN_H
18*a65addddSAndroid Build Coastguard Worker #define FRUIT_PROVIDER_DEFN_H
19*a65addddSAndroid Build Coastguard Worker
20*a65addddSAndroid Build Coastguard Worker #include <fruit/impl/injector/injector_storage.h>
21*a65addddSAndroid Build Coastguard Worker
22*a65addddSAndroid Build Coastguard Worker // Redundant, but makes KDevelop happy.
23*a65addddSAndroid Build Coastguard Worker #include <fruit/provider.h>
24*a65addddSAndroid Build Coastguard Worker
25*a65addddSAndroid Build Coastguard Worker namespace fruit {
26*a65addddSAndroid Build Coastguard Worker
27*a65addddSAndroid Build Coastguard Worker template <typename C>
Provider(fruit::impl::InjectorStorage * storage,fruit::impl::InjectorStorage::Graph::node_iterator itr)28*a65addddSAndroid Build Coastguard Worker inline Provider<C>::Provider(fruit::impl::InjectorStorage* storage,
29*a65addddSAndroid Build Coastguard Worker fruit::impl::InjectorStorage::Graph::node_iterator itr)
30*a65addddSAndroid Build Coastguard Worker : storage(storage), itr(itr) {}
31*a65addddSAndroid Build Coastguard Worker
32*a65addddSAndroid Build Coastguard Worker template <typename C>
get()33*a65addddSAndroid Build Coastguard Worker inline C* Provider<C>::get() {
34*a65addddSAndroid Build Coastguard Worker return get<C*>();
35*a65addddSAndroid Build Coastguard Worker }
36*a65addddSAndroid Build Coastguard Worker
37*a65addddSAndroid Build Coastguard Worker namespace impl {
38*a65addddSAndroid Build Coastguard Worker namespace meta {
39*a65addddSAndroid Build Coastguard Worker
40*a65addddSAndroid Build Coastguard Worker template <typename C>
41*a65addddSAndroid Build Coastguard Worker struct ProviderImplHelper {
42*a65addddSAndroid Build Coastguard Worker
43*a65addddSAndroid Build Coastguard Worker template <typename T>
44*a65addddSAndroid Build Coastguard Worker using CheckGet = Eval<PropagateError(
45*a65addddSAndroid Build Coastguard Worker CheckInjectableType(RemoveAnnotations(Type<T>)),
46*a65addddSAndroid Build Coastguard Worker If(Not(IsSame(GetClassForType(Type<T>), RemoveConstFromType(Type<C>))),
47*a65addddSAndroid Build Coastguard Worker ConstructError(Id<TypeNotProvidedErrorTag>, Type<T>),
48*a65addddSAndroid Build Coastguard Worker If(And(TypeInjectionRequiresNonConstBinding(Type<T>), Not(IsSame(Id<GetClassForType(Type<T>)>, Type<C>))),
49*a65addddSAndroid Build Coastguard Worker ConstructError(TypeProvidedAsConstOnlyErrorTag, Type<T>), None)))>;
50*a65addddSAndroid Build Coastguard Worker };
51*a65addddSAndroid Build Coastguard Worker
52*a65addddSAndroid Build Coastguard Worker } // namespace meta
53*a65addddSAndroid Build Coastguard Worker } // namespace impl
54*a65addddSAndroid Build Coastguard Worker
55*a65addddSAndroid Build Coastguard Worker template <typename C>
56*a65addddSAndroid Build Coastguard Worker template <typename T>
get()57*a65addddSAndroid Build Coastguard Worker inline T Provider<C>::get() {
58*a65addddSAndroid Build Coastguard Worker using E = typename fruit::impl::meta::ProviderImplHelper<C>::template CheckGet<T>;
59*a65addddSAndroid Build Coastguard Worker (void)typename fruit::impl::meta::CheckIfError<E>::type();
60*a65addddSAndroid Build Coastguard Worker return storage->template get<T>(itr);
61*a65addddSAndroid Build Coastguard Worker }
62*a65addddSAndroid Build Coastguard Worker
63*a65addddSAndroid Build Coastguard Worker template <typename C>
64*a65addddSAndroid Build Coastguard Worker template <typename T>
T()65*a65addddSAndroid Build Coastguard Worker inline Provider<C>::operator T() {
66*a65addddSAndroid Build Coastguard Worker return get<T>();
67*a65addddSAndroid Build Coastguard Worker }
68*a65addddSAndroid Build Coastguard Worker
69*a65addddSAndroid Build Coastguard Worker } // namespace fruit
70*a65addddSAndroid Build Coastguard Worker
71*a65addddSAndroid Build Coastguard Worker #endif // FRUIT_PROVIDER_DEFN_H
72