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.
Thunks.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_DETAIL_THUNKS_H_ 00018 #define EVENTQUEUE_DETAIL_THUNKS_H_ 00019 00020 namespace eq { 00021 namespace detail { 00022 00023 /** 00024 * Generate a Thunk for a callable of type F with one argument. 00025 * This class is a function like object containing the function to call and 00026 * its argument. When it is invoked, F is invoked with the argument passed 00027 * at construction time. 00028 * \tparam F the type of the callable. 00029 * \tparam Arg0 type of the first parameter of F to pass to F. 00030 */ 00031 template<typename F, typename Arg0> 00032 struct Thunk_1 { 00033 /** 00034 * Construct the Thunk and bind its arguments. 00035 * \param fn the callable, it will be invoked with arg0. 00036 * \param arg0 The first argument to pass to fn when this object is called. 00037 * \note member function should be adapted by using FunctionAdaptor 00038 */ 00039 Thunk_1(const F& fn, const Arg0& arg0) : 00040 _fn(fn), _arg0(arg0) { 00041 } 00042 00043 /** 00044 * Apply arg0 to fn. 00045 */ 00046 void operator()() const { 00047 _fn(_arg0); 00048 } 00049 00050 private: 00051 mutable F _fn; 00052 mutable Arg0 _arg0; 00053 }; 00054 00055 /** 00056 * Generate a Thunk for a callable of type F with two arguments. 00057 * This class is a function like object containing the function to call and 00058 * its arguments. When it is invoked, F is invoked with the arguments passed 00059 * at construction time. 00060 * \tparam F the type of the callable. 00061 * \tparam Arg0 type of the first parameter to pass to F. 00062 * \tparam Arg1 type of the second parameter to pass to F. 00063 */ 00064 template<typename F, typename Arg0, typename Arg1> 00065 struct Thunk_2 { 00066 /** 00067 * Construct the Thunk and bind its arguments. 00068 * \param fn the callable, it will be invoked with arg0 and arg1. 00069 * \param arg0 The first argument to pass to fn when this object is called. 00070 * \param arg1 The second argument to pass to fn when this object is called. 00071 * \note member function should be adapted by using FunctionAdaptor 00072 */ 00073 Thunk_2(const F& fn, const Arg0& arg0, const Arg1& arg1) : 00074 _fn(fn), 00075 _arg0(arg0), 00076 _arg1(arg1) { 00077 } 00078 00079 /** 00080 * Apply arg0 and arg1 to fn. 00081 */ 00082 void operator()() const { 00083 _fn(_arg0, _arg1); 00084 } 00085 00086 private: 00087 mutable F _fn; 00088 mutable Arg0 _arg0; 00089 mutable Arg1 _arg1; 00090 }; 00091 00092 /** 00093 * Generate a Thunk for a callable of type F with three arguments. 00094 * This class is a function like object containing the function to call and 00095 * its arguments. When it is invoked, F is invoked with the arguments passed 00096 * at construction time. 00097 * \tparam F the type of the callable. 00098 * \tparam Arg0 type of the first parameter to pass to F. 00099 * \tparam Arg1 type of the second parameter to pass to F. 00100 * \tparam Arg2 type of the third parameter to pass to F. 00101 */ 00102 template<typename F, typename Arg0, typename Arg1, typename Arg2> 00103 struct Thunk_3 { 00104 /** 00105 * Construct the Thunk and bind its arguments. 00106 * \param fn the callable, it will be invoked with arg0, arg1 and arg2. 00107 * \param arg0 The first argument to pass to fn when this object is called. 00108 * \param arg1 The second argument to pass to fn when this object is called. 00109 * \param arg2 The third argument to pass to fn when this object is called. 00110 * \note member function should be adapted by using FunctionAdaptor 00111 */ 00112 Thunk_3(const F& fn, const Arg0& arg0, const Arg1& arg1, const Arg2& arg2) : 00113 _fn(fn), 00114 _arg0(arg0), 00115 _arg1(arg1), 00116 _arg2(arg2){ 00117 } 00118 00119 /** 00120 * Apply arg0, arg1 and arg2 to fn. 00121 */ 00122 void operator()() const { 00123 _fn(_arg0, _arg1, _arg2); 00124 } 00125 00126 private: 00127 mutable F _fn; 00128 mutable Arg0 _arg0; 00129 mutable Arg1 _arg1; 00130 mutable Arg2 _arg2; 00131 }; 00132 00133 } // namespace detail 00134 } // namespace eq 00135 00136 #endif /* EVENTQUEUE_DETAIL_THUNKS_H_ */
Generated on Thu Jul 14 2022 09:28:18 by
1.7.2