Roy Want / Mbed OS beaconCompileReadyFork
Committer:
roywant
Date:
Mon Sep 19 00:59:11 2016 +0000
Revision:
0:ed0152b5c495
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
roywant 0:ed0152b5c495 1 /*
roywant 0:ed0152b5c495 2 * Copyright (c) 2016, ARM Limited, All Rights Reserved
roywant 0:ed0152b5c495 3 * SPDX-License-Identifier: Apache-2.0
roywant 0:ed0152b5c495 4 *
roywant 0:ed0152b5c495 5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
roywant 0:ed0152b5c495 6 * not use this file except in compliance with the License.
roywant 0:ed0152b5c495 7 * You may obtain a copy of the License at
roywant 0:ed0152b5c495 8 *
roywant 0:ed0152b5c495 9 * http://www.apache.org/licenses/LICENSE-2.0
roywant 0:ed0152b5c495 10 *
roywant 0:ed0152b5c495 11 * Unless required by applicable law or agreed to in writing, software
roywant 0:ed0152b5c495 12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
roywant 0:ed0152b5c495 13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
roywant 0:ed0152b5c495 14 * See the License for the specific language governing permissions and
roywant 0:ed0152b5c495 15 * limitations under the License.
roywant 0:ed0152b5c495 16 */
roywant 0:ed0152b5c495 17 #ifndef EVENTQUEUE_DETAIL_THUNKS_H_
roywant 0:ed0152b5c495 18 #define EVENTQUEUE_DETAIL_THUNKS_H_
roywant 0:ed0152b5c495 19
roywant 0:ed0152b5c495 20 namespace eq {
roywant 0:ed0152b5c495 21 namespace detail {
roywant 0:ed0152b5c495 22
roywant 0:ed0152b5c495 23 /**
roywant 0:ed0152b5c495 24 * Generate a Thunk for a callable of type F with one argument.
roywant 0:ed0152b5c495 25 * This class is a function like object containing the function to call and
roywant 0:ed0152b5c495 26 * its argument. When it is invoked, F is invoked with the argument passed
roywant 0:ed0152b5c495 27 * at construction time.
roywant 0:ed0152b5c495 28 * \tparam F the type of the callable.
roywant 0:ed0152b5c495 29 * \tparam Arg0 type of the first parameter of F to pass to F.
roywant 0:ed0152b5c495 30 */
roywant 0:ed0152b5c495 31 template<typename F, typename Arg0>
roywant 0:ed0152b5c495 32 struct Thunk_1 {
roywant 0:ed0152b5c495 33 /**
roywant 0:ed0152b5c495 34 * Construct the Thunk and bind its arguments.
roywant 0:ed0152b5c495 35 * \param fn the callable, it will be invoked with arg0.
roywant 0:ed0152b5c495 36 * \param arg0 The first argument to pass to fn when this object is called.
roywant 0:ed0152b5c495 37 * \note member function should be adapted by using FunctionAdaptor
roywant 0:ed0152b5c495 38 */
roywant 0:ed0152b5c495 39 Thunk_1(const F& fn, const Arg0& arg0) :
roywant 0:ed0152b5c495 40 _fn(fn), _arg0(arg0) {
roywant 0:ed0152b5c495 41 }
roywant 0:ed0152b5c495 42
roywant 0:ed0152b5c495 43 /**
roywant 0:ed0152b5c495 44 * Apply arg0 to fn.
roywant 0:ed0152b5c495 45 */
roywant 0:ed0152b5c495 46 void operator()() const {
roywant 0:ed0152b5c495 47 _fn(_arg0);
roywant 0:ed0152b5c495 48 }
roywant 0:ed0152b5c495 49
roywant 0:ed0152b5c495 50 private:
roywant 0:ed0152b5c495 51 mutable F _fn;
roywant 0:ed0152b5c495 52 mutable Arg0 _arg0;
roywant 0:ed0152b5c495 53 };
roywant 0:ed0152b5c495 54
roywant 0:ed0152b5c495 55 /**
roywant 0:ed0152b5c495 56 * Generate a Thunk for a callable of type F with two arguments.
roywant 0:ed0152b5c495 57 * This class is a function like object containing the function to call and
roywant 0:ed0152b5c495 58 * its arguments. When it is invoked, F is invoked with the arguments passed
roywant 0:ed0152b5c495 59 * at construction time.
roywant 0:ed0152b5c495 60 * \tparam F the type of the callable.
roywant 0:ed0152b5c495 61 * \tparam Arg0 type of the first parameter to pass to F.
roywant 0:ed0152b5c495 62 * \tparam Arg1 type of the second parameter to pass to F.
roywant 0:ed0152b5c495 63 */
roywant 0:ed0152b5c495 64 template<typename F, typename Arg0, typename Arg1>
roywant 0:ed0152b5c495 65 struct Thunk_2 {
roywant 0:ed0152b5c495 66 /**
roywant 0:ed0152b5c495 67 * Construct the Thunk and bind its arguments.
roywant 0:ed0152b5c495 68 * \param fn the callable, it will be invoked with arg0 and arg1.
roywant 0:ed0152b5c495 69 * \param arg0 The first argument to pass to fn when this object is called.
roywant 0:ed0152b5c495 70 * \param arg1 The second argument to pass to fn when this object is called.
roywant 0:ed0152b5c495 71 * \note member function should be adapted by using FunctionAdaptor
roywant 0:ed0152b5c495 72 */
roywant 0:ed0152b5c495 73 Thunk_2(const F& fn, const Arg0& arg0, const Arg1& arg1) :
roywant 0:ed0152b5c495 74 _fn(fn),
roywant 0:ed0152b5c495 75 _arg0(arg0),
roywant 0:ed0152b5c495 76 _arg1(arg1) {
roywant 0:ed0152b5c495 77 }
roywant 0:ed0152b5c495 78
roywant 0:ed0152b5c495 79 /**
roywant 0:ed0152b5c495 80 * Apply arg0 and arg1 to fn.
roywant 0:ed0152b5c495 81 */
roywant 0:ed0152b5c495 82 void operator()() const {
roywant 0:ed0152b5c495 83 _fn(_arg0, _arg1);
roywant 0:ed0152b5c495 84 }
roywant 0:ed0152b5c495 85
roywant 0:ed0152b5c495 86 private:
roywant 0:ed0152b5c495 87 mutable F _fn;
roywant 0:ed0152b5c495 88 mutable Arg0 _arg0;
roywant 0:ed0152b5c495 89 mutable Arg1 _arg1;
roywant 0:ed0152b5c495 90 };
roywant 0:ed0152b5c495 91
roywant 0:ed0152b5c495 92 /**
roywant 0:ed0152b5c495 93 * Generate a Thunk for a callable of type F with three arguments.
roywant 0:ed0152b5c495 94 * This class is a function like object containing the function to call and
roywant 0:ed0152b5c495 95 * its arguments. When it is invoked, F is invoked with the arguments passed
roywant 0:ed0152b5c495 96 * at construction time.
roywant 0:ed0152b5c495 97 * \tparam F the type of the callable.
roywant 0:ed0152b5c495 98 * \tparam Arg0 type of the first parameter to pass to F.
roywant 0:ed0152b5c495 99 * \tparam Arg1 type of the second parameter to pass to F.
roywant 0:ed0152b5c495 100 * \tparam Arg2 type of the third parameter to pass to F.
roywant 0:ed0152b5c495 101 */
roywant 0:ed0152b5c495 102 template<typename F, typename Arg0, typename Arg1, typename Arg2>
roywant 0:ed0152b5c495 103 struct Thunk_3 {
roywant 0:ed0152b5c495 104 /**
roywant 0:ed0152b5c495 105 * Construct the Thunk and bind its arguments.
roywant 0:ed0152b5c495 106 * \param fn the callable, it will be invoked with arg0, arg1 and arg2.
roywant 0:ed0152b5c495 107 * \param arg0 The first argument to pass to fn when this object is called.
roywant 0:ed0152b5c495 108 * \param arg1 The second argument to pass to fn when this object is called.
roywant 0:ed0152b5c495 109 * \param arg2 The third argument to pass to fn when this object is called.
roywant 0:ed0152b5c495 110 * \note member function should be adapted by using FunctionAdaptor
roywant 0:ed0152b5c495 111 */
roywant 0:ed0152b5c495 112 Thunk_3(const F& fn, const Arg0& arg0, const Arg1& arg1, const Arg2& arg2) :
roywant 0:ed0152b5c495 113 _fn(fn),
roywant 0:ed0152b5c495 114 _arg0(arg0),
roywant 0:ed0152b5c495 115 _arg1(arg1),
roywant 0:ed0152b5c495 116 _arg2(arg2){
roywant 0:ed0152b5c495 117 }
roywant 0:ed0152b5c495 118
roywant 0:ed0152b5c495 119 /**
roywant 0:ed0152b5c495 120 * Apply arg0, arg1 and arg2 to fn.
roywant 0:ed0152b5c495 121 */
roywant 0:ed0152b5c495 122 void operator()() const {
roywant 0:ed0152b5c495 123 _fn(_arg0, _arg1, _arg2);
roywant 0:ed0152b5c495 124 }
roywant 0:ed0152b5c495 125
roywant 0:ed0152b5c495 126 private:
roywant 0:ed0152b5c495 127 mutable F _fn;
roywant 0:ed0152b5c495 128 mutable Arg0 _arg0;
roywant 0:ed0152b5c495 129 mutable Arg1 _arg1;
roywant 0:ed0152b5c495 130 mutable Arg2 _arg2;
roywant 0:ed0152b5c495 131 };
roywant 0:ed0152b5c495 132
roywant 0:ed0152b5c495 133 } // namespace detail
roywant 0:ed0152b5c495 134 } // namespace eq
roywant 0:ed0152b5c495 135
roywant 0:ed0152b5c495 136 #endif /* EVENTQUEUE_DETAIL_THUNKS_H_ */