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_COMPONENT_FUNCTION_DEFN_H
18*a65addddSAndroid Build Coastguard Worker #define FRUIT_COMPONENT_FUNCTION_DEFN_H
19*a65addddSAndroid Build Coastguard Worker
20*a65addddSAndroid Build Coastguard Worker #include <fruit/component_function.h>
21*a65addddSAndroid Build Coastguard Worker #include <fruit/impl/util/call_with_tuple.h>
22*a65addddSAndroid Build Coastguard Worker #include <fruit/impl/component_install_arg_checks.h>
23*a65addddSAndroid Build Coastguard Worker
24*a65addddSAndroid Build Coastguard Worker namespace fruit {
25*a65addddSAndroid Build Coastguard Worker
26*a65addddSAndroid Build Coastguard Worker template <typename ComponentType, typename... ComponentFunctionArgs>
ComponentFunction(ComponentType (* getComponent)(ComponentFunctionArgs...),ComponentFunctionArgs...args)27*a65addddSAndroid Build Coastguard Worker inline ComponentFunction<ComponentType, ComponentFunctionArgs...>::ComponentFunction(
28*a65addddSAndroid Build Coastguard Worker ComponentType (*getComponent)(ComponentFunctionArgs...), ComponentFunctionArgs... args)
29*a65addddSAndroid Build Coastguard Worker : getComponent(getComponent), args_tuple{args...} {
30*a65addddSAndroid Build Coastguard Worker using IntCollector = int[];
31*a65addddSAndroid Build Coastguard Worker (void)IntCollector{0, fruit::impl::checkAcceptableComponentInstallArg<ComponentFunctionArgs>()...};
32*a65addddSAndroid Build Coastguard Worker }
33*a65addddSAndroid Build Coastguard Worker
34*a65addddSAndroid Build Coastguard Worker template <typename ComponentType, typename... ComponentFunctionArgs>
35*a65addddSAndroid Build Coastguard Worker template <typename... ActualArgs>
36*a65addddSAndroid Build Coastguard Worker inline ComponentFunction<ComponentType, ComponentFunctionArgs...>
create(ComponentType (* getComponent)(ComponentFunctionArgs...),ActualArgs &&...args)37*a65addddSAndroid Build Coastguard Worker ComponentFunction<ComponentType, ComponentFunctionArgs...>::create(
38*a65addddSAndroid Build Coastguard Worker ComponentType(*getComponent)(ComponentFunctionArgs...), ActualArgs&&... args) {
39*a65addddSAndroid Build Coastguard Worker return ComponentFunction<ComponentType, ComponentFunctionArgs...>(getComponent, std::forward<ActualArgs>(args)...);
40*a65addddSAndroid Build Coastguard Worker }
41*a65addddSAndroid Build Coastguard Worker
42*a65addddSAndroid Build Coastguard Worker template <typename ComponentType, typename... ComponentFunctionArgs>
operator()43*a65addddSAndroid Build Coastguard Worker inline ComponentType ComponentFunction<ComponentType, ComponentFunctionArgs...>::operator()() {
44*a65addddSAndroid Build Coastguard Worker return fruit::impl::callWithTuple(getComponent, args_tuple);
45*a65addddSAndroid Build Coastguard Worker }
46*a65addddSAndroid Build Coastguard Worker
47*a65addddSAndroid Build Coastguard Worker template <typename... ComponentParams, typename... FormalArgs, typename... ActualArgs>
componentFunction(fruit::Component<ComponentParams...> (* getComponent)(FormalArgs...),ActualArgs &&...args)48*a65addddSAndroid Build Coastguard Worker inline ComponentFunction<fruit::Component<ComponentParams...>, FormalArgs...> componentFunction(
49*a65addddSAndroid Build Coastguard Worker fruit::Component<ComponentParams...> (*getComponent)(FormalArgs...),
50*a65addddSAndroid Build Coastguard Worker ActualArgs&&... args) {
51*a65addddSAndroid Build Coastguard Worker return ComponentFunction<fruit::Component<ComponentParams...>, FormalArgs...>::create(
52*a65addddSAndroid Build Coastguard Worker getComponent, std::forward<ActualArgs>(args)...);
53*a65addddSAndroid Build Coastguard Worker }
54*a65addddSAndroid Build Coastguard Worker
55*a65addddSAndroid Build Coastguard Worker }
56*a65addddSAndroid Build Coastguard Worker
57*a65addddSAndroid Build Coastguard Worker #endif // FRUIT_COMPONENT_FUNCTION_DEFN_H
58