Sarah Marsh / Mbed OS EddystoneBeacon
Committer:
sarahmarshy
Date:
Tue Nov 29 06:29:10 2016 +0000
Revision:
0:1c7da5f83647
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew 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_FUNCTIONADAPTOR_H_
sarahmarshy 0:1c7da5f83647 18 #define EVENTQUEUE_DETAIL_FUNCTIONADAPTOR_H_
sarahmarshy 0:1c7da5f83647 19
sarahmarshy 0:1c7da5f83647 20 #include "MemberFunctionAdaptor.h"
sarahmarshy 0:1c7da5f83647 21
sarahmarshy 0:1c7da5f83647 22 namespace eq {
sarahmarshy 0:1c7da5f83647 23 namespace detail {
sarahmarshy 0:1c7da5f83647 24
sarahmarshy 0:1c7da5f83647 25 /**
sarahmarshy 0:1c7da5f83647 26 * In C++, several types can be used as function:
sarahmarshy 0:1c7da5f83647 27 * - function pointer
sarahmarshy 0:1c7da5f83647 28 * - member functions
sarahmarshy 0:1c7da5f83647 29 * - function like object
sarahmarshy 0:1c7da5f83647 30 * While function pointer and function like object can be used with the function
sarahmarshy 0:1c7da5f83647 31 * call syntax, the function call syntax can't be applied for function pointers.
sarahmarshy 0:1c7da5f83647 32 * This meta function yield takes a callable type F in input and as a result
sarahmarshy 0:1c7da5f83647 33 * return a type which can be constructed from F and used with the function call
sarahmarshy 0:1c7da5f83647 34 * syntax.
sarahmarshy 0:1c7da5f83647 35 *
sarahmarshy 0:1c7da5f83647 36 * \code
sarahmarshy 0:1c7da5f83647 37 * class Foo;
sarahmarshy 0:1c7da5f83647 38 *
sarahmarshy 0:1c7da5f83647 39 * Foo foo;
sarahmarshy 0:1c7da5f83647 40 * typedef void (Foo::*foo_function_t)();
sarahmarshy 0:1c7da5f83647 41 * foo_function_t foo_function = &Foo::some_function;
sarahmarshy 0:1c7da5f83647 42 *
sarahmarshy 0:1c7da5f83647 43 * //The following will fail:
sarahmarshy 0:1c7da5f83647 44 * //foo_function(foo)
sarahmarshy 0:1c7da5f83647 45 *
sarahmarshy 0:1c7da5f83647 46 * typedef FunctionAdaptor<foo_function_t>::type foo_function_adaptor_t;
sarahmarshy 0:1c7da5f83647 47 * foo_function_adaptor_t foo_function_adapted(foo_function);
sarahmarshy 0:1c7da5f83647 48 * foo_function_adapted(foo);
sarahmarshy 0:1c7da5f83647 49 *
sarahmarshy 0:1c7da5f83647 50 * \endcode
sarahmarshy 0:1c7da5f83647 51 *
sarahmarshy 0:1c7da5f83647 52 * \tparam F The type of the object to adapt.
sarahmarshy 0:1c7da5f83647 53 */
sarahmarshy 0:1c7da5f83647 54 template<typename F>
sarahmarshy 0:1c7da5f83647 55 struct FunctionAdaptor {
sarahmarshy 0:1c7da5f83647 56 /**
sarahmarshy 0:1c7da5f83647 57 * Common case (function pointer and function like object).
sarahmarshy 0:1c7da5f83647 58 * Yield itself, no addaptation needed.
sarahmarshy 0:1c7da5f83647 59 */
sarahmarshy 0:1c7da5f83647 60 typedef F type;
sarahmarshy 0:1c7da5f83647 61 };
sarahmarshy 0:1c7da5f83647 62
sarahmarshy 0:1c7da5f83647 63 /**
sarahmarshy 0:1c7da5f83647 64 * Partial specializetion for member function with no arguments
sarahmarshy 0:1c7da5f83647 65 */
sarahmarshy 0:1c7da5f83647 66 template<typename T>
sarahmarshy 0:1c7da5f83647 67 struct FunctionAdaptor<void(T::*)()> {
sarahmarshy 0:1c7da5f83647 68 /**
sarahmarshy 0:1c7da5f83647 69 * Yield a member function adaptor.
sarahmarshy 0:1c7da5f83647 70 */
sarahmarshy 0:1c7da5f83647 71 typedef MemberFunctionAdaptor0<T> type;
sarahmarshy 0:1c7da5f83647 72 };
sarahmarshy 0:1c7da5f83647 73
sarahmarshy 0:1c7da5f83647 74 /**
sarahmarshy 0:1c7da5f83647 75 * Partial specializetion for member function with one argument
sarahmarshy 0:1c7da5f83647 76 */
sarahmarshy 0:1c7da5f83647 77 template<typename T, typename Arg0>
sarahmarshy 0:1c7da5f83647 78 struct FunctionAdaptor<void(T::*)(Arg0)> {
sarahmarshy 0:1c7da5f83647 79 /**
sarahmarshy 0:1c7da5f83647 80 * Yield a member function adaptor.
sarahmarshy 0:1c7da5f83647 81 */
sarahmarshy 0:1c7da5f83647 82 typedef MemberFunctionAdaptor1<T, Arg0> type;
sarahmarshy 0:1c7da5f83647 83 };
sarahmarshy 0:1c7da5f83647 84
sarahmarshy 0:1c7da5f83647 85 /**
sarahmarshy 0:1c7da5f83647 86 * Partial specializetion for member function with two arguments
sarahmarshy 0:1c7da5f83647 87 */
sarahmarshy 0:1c7da5f83647 88 template<typename T, typename Arg0, typename Arg1>
sarahmarshy 0:1c7da5f83647 89 struct FunctionAdaptor<void(T::*)(Arg0, Arg1)> {
sarahmarshy 0:1c7da5f83647 90 /**
sarahmarshy 0:1c7da5f83647 91 * Yield a member function adaptor.
sarahmarshy 0:1c7da5f83647 92 */
sarahmarshy 0:1c7da5f83647 93 typedef MemberFunctionAdaptor2<T, Arg0, Arg1> type;
sarahmarshy 0:1c7da5f83647 94 };
sarahmarshy 0:1c7da5f83647 95
sarahmarshy 0:1c7da5f83647 96 } // namespace detail
sarahmarshy 0:1c7da5f83647 97 } // namespace eq
sarahmarshy 0:1c7da5f83647 98
sarahmarshy 0:1c7da5f83647 99 #endif /* EVENTQUEUE_DETAIL_FUNCTIONADAPTOR_H_ */