USB Serial application

Fork of USBSerial_HelloWorld by Samuel Mokrani

Committer:
Zaitsev
Date:
Sat Dec 16 10:26:48 2017 +0000
Revision:
11:b3f2a8bdac4d
Parent:
10:41552d038a69
A copy for D.S;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Zaitsev 10:41552d038a69 1 /* mbed Microcontroller Library
Zaitsev 10:41552d038a69 2 * Copyright (c) 2006-2015 ARM Limited
Zaitsev 10:41552d038a69 3 *
Zaitsev 10:41552d038a69 4 * Licensed under the Apache License, Version 2.0 (the "License");
Zaitsev 10:41552d038a69 5 * you may not use this file except in compliance with the License.
Zaitsev 10:41552d038a69 6 * You may obtain a copy of the License at
Zaitsev 10:41552d038a69 7 *
Zaitsev 10:41552d038a69 8 * http://www.apache.org/licenses/LICENSE-2.0
Zaitsev 10:41552d038a69 9 *
Zaitsev 10:41552d038a69 10 * Unless required by applicable law or agreed to in writing, software
Zaitsev 10:41552d038a69 11 * distributed under the License is distributed on an "AS IS" BASIS,
Zaitsev 10:41552d038a69 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Zaitsev 10:41552d038a69 13 * See the License for the specific language governing permissions and
Zaitsev 10:41552d038a69 14 * limitations under the License.
Zaitsev 10:41552d038a69 15 */
Zaitsev 10:41552d038a69 16 #ifndef MBED_FUNCTIONPOINTER_H
Zaitsev 10:41552d038a69 17 #define MBED_FUNCTIONPOINTER_H
Zaitsev 10:41552d038a69 18
Zaitsev 10:41552d038a69 19 #include "platform/Callback.h"
Zaitsev 10:41552d038a69 20 #include "platform/toolchain.h"
Zaitsev 10:41552d038a69 21 #include <string.h>
Zaitsev 10:41552d038a69 22 #include <stdint.h>
Zaitsev 10:41552d038a69 23
Zaitsev 10:41552d038a69 24 namespace mbed {
Zaitsev 10:41552d038a69 25 /** \addtogroup platform */
Zaitsev 10:41552d038a69 26 /** @{*/
Zaitsev 10:41552d038a69 27
Zaitsev 10:41552d038a69 28
Zaitsev 10:41552d038a69 29 // Declarations for backwards compatibility
Zaitsev 10:41552d038a69 30 // To be foward compatible, code should adopt the Callback class
Zaitsev 10:41552d038a69 31 template <typename R, typename A1>
Zaitsev 10:41552d038a69 32 class FunctionPointerArg1 : public Callback<R(A1)> {
Zaitsev 10:41552d038a69 33 public:
Zaitsev 10:41552d038a69 34 MBED_DEPRECATED_SINCE("mbed-os-5.1",
Zaitsev 10:41552d038a69 35 "FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>")
Zaitsev 10:41552d038a69 36 FunctionPointerArg1(R (*function)(A1) = 0)
Zaitsev 10:41552d038a69 37 : Callback<R(A1)>(function) {}
Zaitsev 10:41552d038a69 38
Zaitsev 10:41552d038a69 39 template<typename T>
Zaitsev 10:41552d038a69 40 MBED_DEPRECATED_SINCE("mbed-os-5.1",
Zaitsev 10:41552d038a69 41 "FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>")
Zaitsev 10:41552d038a69 42 FunctionPointerArg1(T *object, R (T::*member)(A1))
Zaitsev 10:41552d038a69 43 : Callback<R(A1)>(object, member) {}
Zaitsev 10:41552d038a69 44
Zaitsev 10:41552d038a69 45 R (*get_function())(A1) {
Zaitsev 10:41552d038a69 46 return *reinterpret_cast<R (**)(A1)>(this);
Zaitsev 10:41552d038a69 47 }
Zaitsev 10:41552d038a69 48
Zaitsev 10:41552d038a69 49 R call(A1 a1) const {
Zaitsev 10:41552d038a69 50 if (!Callback<R(A1)>::operator bool()) {
Zaitsev 10:41552d038a69 51 return (R)0;
Zaitsev 10:41552d038a69 52 }
Zaitsev 10:41552d038a69 53
Zaitsev 10:41552d038a69 54 return Callback<R(A1)>::call(a1);
Zaitsev 10:41552d038a69 55 }
Zaitsev 10:41552d038a69 56
Zaitsev 10:41552d038a69 57 R operator()(A1 a1) const {
Zaitsev 10:41552d038a69 58 return Callback<R(A1)>::call(a1);
Zaitsev 10:41552d038a69 59 }
Zaitsev 10:41552d038a69 60 };
Zaitsev 10:41552d038a69 61
Zaitsev 10:41552d038a69 62 template <typename R>
Zaitsev 10:41552d038a69 63 class FunctionPointerArg1<R, void> : public Callback<R()> {
Zaitsev 10:41552d038a69 64 public:
Zaitsev 10:41552d038a69 65 MBED_DEPRECATED_SINCE("mbed-os-5.1",
Zaitsev 10:41552d038a69 66 "FunctionPointer has been replaced by Callback<void()>")
Zaitsev 10:41552d038a69 67 FunctionPointerArg1(R (*function)() = 0)
Zaitsev 10:41552d038a69 68 : Callback<R()>(function) {}
Zaitsev 10:41552d038a69 69
Zaitsev 10:41552d038a69 70 template<typename T>
Zaitsev 10:41552d038a69 71 MBED_DEPRECATED_SINCE("mbed-os-5.1",
Zaitsev 10:41552d038a69 72 "FunctionPointer has been replaced by Callback<void()>")
Zaitsev 10:41552d038a69 73 FunctionPointerArg1(T *object, R (T::*member)())
Zaitsev 10:41552d038a69 74 : Callback<R()>(object, member) {}
Zaitsev 10:41552d038a69 75
Zaitsev 10:41552d038a69 76 R (*get_function())() {
Zaitsev 10:41552d038a69 77 return *reinterpret_cast<R (**)()>(this);
Zaitsev 10:41552d038a69 78 }
Zaitsev 10:41552d038a69 79
Zaitsev 10:41552d038a69 80 R call() const {
Zaitsev 10:41552d038a69 81 if (!Callback<R()>::operator bool()) {
Zaitsev 10:41552d038a69 82 return (R)0;
Zaitsev 10:41552d038a69 83 }
Zaitsev 10:41552d038a69 84
Zaitsev 10:41552d038a69 85 return Callback<R()>::call();
Zaitsev 10:41552d038a69 86 }
Zaitsev 10:41552d038a69 87
Zaitsev 10:41552d038a69 88 R operator()() const {
Zaitsev 10:41552d038a69 89 return Callback<R()>::call();
Zaitsev 10:41552d038a69 90 }
Zaitsev 10:41552d038a69 91 };
Zaitsev 10:41552d038a69 92
Zaitsev 10:41552d038a69 93 typedef FunctionPointerArg1<void, void> FunctionPointer;
Zaitsev 10:41552d038a69 94
Zaitsev 10:41552d038a69 95
Zaitsev 10:41552d038a69 96 } // namespace mbed
Zaitsev 10:41552d038a69 97
Zaitsev 10:41552d038a69 98 #endif
Zaitsev 10:41552d038a69 99
Zaitsev 10:41552d038a69 100 /** @}*/