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