Roy Want / Mbed OS beaconCompileReadyFork
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MakeThunk.h Source File

MakeThunk.h

00001 /*
00002  * Copyright (c) 2016, ARM Limited, All Rights Reserved
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License"); you may
00006  * not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  * http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00013  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 #ifndef EVENTQUEUE_MAKETHUNK_H
00018 #define EVENTQUEUE_MAKETHUNK_H
00019 
00020 #include "detail/MemberFunctionAdaptor.h"
00021 #include "detail/FunctionAdaptor.h"
00022 #include "detail/Thunks.h"
00023 
00024 namespace eq {
00025 
00026 /**
00027  * Make a thunk from an F.
00028  * When this function only takes an F then F it is expected that F is already
00029  * a callable and therefore a kind of thunk.
00030  * @tparam F The type of callable in input.
00031  * @param fn the function to turn into a thunk.
00032  * @return fn
00033  */
00034 template<typename F>
00035 const F& make_thunk(const F& fn) {
00036     return fn;
00037 }
00038 
00039 /**
00040  * Bind fn and arg0 into a thunk.
00041  * @tparam F the type of the function to bind. It can be a function pointer,
00042  * a function like object or a pointer to a member function.
00043  * @tparam Arg0 The type of the first argument of F.
00044  * @param fn the function to bind.
00045  * @param arg0 the first argument to bind.
00046  * @return a thunk binding F and arg0.
00047  */
00048 template<typename F, typename Arg0>
00049 detail::Thunk_1<typename detail::FunctionAdaptor<F>::type, Arg0>
00050 make_thunk(const F& fn, const Arg0& arg0) {
00051     typedef typename detail::FunctionAdaptor<F>::type fn_adaptor_t;
00052     return detail::Thunk_1<fn_adaptor_t, Arg0>(
00053         fn_adaptor_t(fn),
00054         arg0
00055     );
00056 }
00057 
00058 /**
00059  * Bind fn, arg0 and arg1 into a thunk.
00060  * @tparam F the type of the function to bind. It can be a function pointer,
00061  * a function like object or a pointer to a member function.
00062  * @tparam Arg0 The type of the first argument of F.
00063  * @tparam Arg1 The type of the second argument of F.
00064  * @param fn the function to bind.
00065  * @param arg0 the first argument to bind.
00066  * @param arg1 the second argument to bind.
00067  * @return a thunk binding F, arg0 and arg1.
00068  */
00069 template<typename F, typename Arg0, typename Arg1>
00070 detail::Thunk_2<typename detail::FunctionAdaptor<F>::type, Arg0, Arg1>
00071 make_thunk(const F& fn, const Arg0& arg0, const Arg1& arg1) {
00072     typedef typename detail::FunctionAdaptor<F>::type fn_adaptor_t;
00073     return detail::Thunk_2<fn_adaptor_t, Arg0, Arg1>(
00074         fn_adaptor_t(fn),
00075         arg0,
00076         arg1
00077     );
00078 }
00079 
00080 /**
00081  * Bind fn, arg0, arg1 and arg2 into a thunk.
00082  * @tparam F the type of the function to bind. It can be a function pointer,
00083  * a function like object or a pointer to a member function.
00084  * @tparam Arg0 The type of the first argument of F.
00085  * @tparam Arg1 The type of the second argument of F.
00086  * @tparam Arg2 The type of the third argument of F.
00087  * @param fn the function to bind.
00088  * @param arg0 the first argument to bind.
00089  * @param arg1 the second argument to bind.
00090  * @param arg1 the third argument to bind.
00091  * @return a thunk binding F, arg0, arg1 and arg2.
00092  */
00093 template<typename F, typename Arg0, typename Arg1, typename Arg2>
00094 detail::Thunk_3<typename detail::FunctionAdaptor<F>::type, Arg0, Arg1, Arg2>
00095 make_thunk(const F& fn, const Arg0& arg0, const Arg1& arg1, const Arg2& arg2) {
00096     typedef typename detail::FunctionAdaptor<F>::type fn_adaptor_t;
00097     return detail::Thunk_3<fn_adaptor_t, Arg0, Arg1, Arg2>(
00098         fn_adaptor_t(fn),
00099         arg0,
00100         arg1,
00101         arg2
00102     );
00103 }
00104 
00105 } // namespace eq
00106 
00107 #endif /* EVENTQUEUE_MAKETHUNK_H */