fft
Dependencies: BSP_DISCO_F746NG SDFileSystem_Warning_Fixed
mbed_src_STM32F7/api/CallChain.h@0:3e46577dc273, 2016-10-09 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Sun Oct 09 10:11:14 2016 +0000
- Revision:
- 0:3e46577dc273
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:3e46577dc273 | 1 | /* mbed Microcontroller Library |
MikamiUitOpen | 0:3e46577dc273 | 2 | * Copyright (c) 2006-2013 ARM Limited |
MikamiUitOpen | 0:3e46577dc273 | 3 | * |
MikamiUitOpen | 0:3e46577dc273 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
MikamiUitOpen | 0:3e46577dc273 | 5 | * you may not use this file except in compliance with the License. |
MikamiUitOpen | 0:3e46577dc273 | 6 | * You may obtain a copy of the License at |
MikamiUitOpen | 0:3e46577dc273 | 7 | * |
MikamiUitOpen | 0:3e46577dc273 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
MikamiUitOpen | 0:3e46577dc273 | 9 | * |
MikamiUitOpen | 0:3e46577dc273 | 10 | * Unless required by applicable law or agreed to in writing, software |
MikamiUitOpen | 0:3e46577dc273 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
MikamiUitOpen | 0:3e46577dc273 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
MikamiUitOpen | 0:3e46577dc273 | 13 | * See the License for the specific language governing permissions and |
MikamiUitOpen | 0:3e46577dc273 | 14 | * limitations under the License. |
MikamiUitOpen | 0:3e46577dc273 | 15 | */ |
MikamiUitOpen | 0:3e46577dc273 | 16 | #ifndef MBED_CALLCHAIN_H |
MikamiUitOpen | 0:3e46577dc273 | 17 | #define MBED_CALLCHAIN_H |
MikamiUitOpen | 0:3e46577dc273 | 18 | |
MikamiUitOpen | 0:3e46577dc273 | 19 | #include "FunctionPointer.h" |
MikamiUitOpen | 0:3e46577dc273 | 20 | #include <string.h> |
MikamiUitOpen | 0:3e46577dc273 | 21 | |
MikamiUitOpen | 0:3e46577dc273 | 22 | namespace mbed { |
MikamiUitOpen | 0:3e46577dc273 | 23 | |
MikamiUitOpen | 0:3e46577dc273 | 24 | /** Group one or more functions in an instance of a CallChain, then call them in |
MikamiUitOpen | 0:3e46577dc273 | 25 | * sequence using CallChain::call(). Used mostly by the interrupt chaining code, |
MikamiUitOpen | 0:3e46577dc273 | 26 | * but can be used for other purposes. |
MikamiUitOpen | 0:3e46577dc273 | 27 | * |
MikamiUitOpen | 0:3e46577dc273 | 28 | * Example: |
MikamiUitOpen | 0:3e46577dc273 | 29 | * @code |
MikamiUitOpen | 0:3e46577dc273 | 30 | * #include "mbed.h" |
MikamiUitOpen | 0:3e46577dc273 | 31 | * |
MikamiUitOpen | 0:3e46577dc273 | 32 | * CallChain chain; |
MikamiUitOpen | 0:3e46577dc273 | 33 | * |
MikamiUitOpen | 0:3e46577dc273 | 34 | * void first(void) { |
MikamiUitOpen | 0:3e46577dc273 | 35 | * printf("'first' function.\n"); |
MikamiUitOpen | 0:3e46577dc273 | 36 | * } |
MikamiUitOpen | 0:3e46577dc273 | 37 | * |
MikamiUitOpen | 0:3e46577dc273 | 38 | * void second(void) { |
MikamiUitOpen | 0:3e46577dc273 | 39 | * printf("'second' function.\n"); |
MikamiUitOpen | 0:3e46577dc273 | 40 | * } |
MikamiUitOpen | 0:3e46577dc273 | 41 | * |
MikamiUitOpen | 0:3e46577dc273 | 42 | * class Test { |
MikamiUitOpen | 0:3e46577dc273 | 43 | * public: |
MikamiUitOpen | 0:3e46577dc273 | 44 | * void f(void) { |
MikamiUitOpen | 0:3e46577dc273 | 45 | * printf("A::f (class member).\n"); |
MikamiUitOpen | 0:3e46577dc273 | 46 | * } |
MikamiUitOpen | 0:3e46577dc273 | 47 | * }; |
MikamiUitOpen | 0:3e46577dc273 | 48 | * |
MikamiUitOpen | 0:3e46577dc273 | 49 | * int main() { |
MikamiUitOpen | 0:3e46577dc273 | 50 | * Test test; |
MikamiUitOpen | 0:3e46577dc273 | 51 | * |
MikamiUitOpen | 0:3e46577dc273 | 52 | * chain.add(second); |
MikamiUitOpen | 0:3e46577dc273 | 53 | * chain.add_front(first); |
MikamiUitOpen | 0:3e46577dc273 | 54 | * chain.add(&test, &Test::f); |
MikamiUitOpen | 0:3e46577dc273 | 55 | * chain.call(); |
MikamiUitOpen | 0:3e46577dc273 | 56 | * } |
MikamiUitOpen | 0:3e46577dc273 | 57 | * @endcode |
MikamiUitOpen | 0:3e46577dc273 | 58 | */ |
MikamiUitOpen | 0:3e46577dc273 | 59 | |
MikamiUitOpen | 0:3e46577dc273 | 60 | typedef FunctionPointer* pFunctionPointer_t; |
MikamiUitOpen | 0:3e46577dc273 | 61 | |
MikamiUitOpen | 0:3e46577dc273 | 62 | class CallChain { |
MikamiUitOpen | 0:3e46577dc273 | 63 | public: |
MikamiUitOpen | 0:3e46577dc273 | 64 | /** Create an empty chain |
MikamiUitOpen | 0:3e46577dc273 | 65 | * |
MikamiUitOpen | 0:3e46577dc273 | 66 | * @param size (optional) Initial size of the chain |
MikamiUitOpen | 0:3e46577dc273 | 67 | */ |
MikamiUitOpen | 0:3e46577dc273 | 68 | CallChain(int size = 4); |
MikamiUitOpen | 0:3e46577dc273 | 69 | virtual ~CallChain(); |
MikamiUitOpen | 0:3e46577dc273 | 70 | |
MikamiUitOpen | 0:3e46577dc273 | 71 | /** Add a function at the end of the chain |
MikamiUitOpen | 0:3e46577dc273 | 72 | * |
MikamiUitOpen | 0:3e46577dc273 | 73 | * @param function A pointer to a void function |
MikamiUitOpen | 0:3e46577dc273 | 74 | * |
MikamiUitOpen | 0:3e46577dc273 | 75 | * @returns |
MikamiUitOpen | 0:3e46577dc273 | 76 | * The function object created for 'function' |
MikamiUitOpen | 0:3e46577dc273 | 77 | */ |
MikamiUitOpen | 0:3e46577dc273 | 78 | pFunctionPointer_t add(void (*function)(void)); |
MikamiUitOpen | 0:3e46577dc273 | 79 | |
MikamiUitOpen | 0:3e46577dc273 | 80 | /** Add a function at the end of the chain |
MikamiUitOpen | 0:3e46577dc273 | 81 | * |
MikamiUitOpen | 0:3e46577dc273 | 82 | * @param tptr pointer to the object to call the member function on |
MikamiUitOpen | 0:3e46577dc273 | 83 | * @param mptr pointer to the member function to be called |
MikamiUitOpen | 0:3e46577dc273 | 84 | * |
MikamiUitOpen | 0:3e46577dc273 | 85 | * @returns |
MikamiUitOpen | 0:3e46577dc273 | 86 | * The function object created for 'tptr' and 'mptr' |
MikamiUitOpen | 0:3e46577dc273 | 87 | */ |
MikamiUitOpen | 0:3e46577dc273 | 88 | template<typename T> |
MikamiUitOpen | 0:3e46577dc273 | 89 | pFunctionPointer_t add(T *tptr, void (T::*mptr)(void)) { |
MikamiUitOpen | 0:3e46577dc273 | 90 | return common_add(new FunctionPointer(tptr, mptr)); |
MikamiUitOpen | 0:3e46577dc273 | 91 | } |
MikamiUitOpen | 0:3e46577dc273 | 92 | |
MikamiUitOpen | 0:3e46577dc273 | 93 | /** Add a function at the beginning of the chain |
MikamiUitOpen | 0:3e46577dc273 | 94 | * |
MikamiUitOpen | 0:3e46577dc273 | 95 | * @param function A pointer to a void function |
MikamiUitOpen | 0:3e46577dc273 | 96 | * |
MikamiUitOpen | 0:3e46577dc273 | 97 | * @returns |
MikamiUitOpen | 0:3e46577dc273 | 98 | * The function object created for 'function' |
MikamiUitOpen | 0:3e46577dc273 | 99 | */ |
MikamiUitOpen | 0:3e46577dc273 | 100 | pFunctionPointer_t add_front(void (*function)(void)); |
MikamiUitOpen | 0:3e46577dc273 | 101 | |
MikamiUitOpen | 0:3e46577dc273 | 102 | /** Add a function at the beginning of the chain |
MikamiUitOpen | 0:3e46577dc273 | 103 | * |
MikamiUitOpen | 0:3e46577dc273 | 104 | * @param tptr pointer to the object to call the member function on |
MikamiUitOpen | 0:3e46577dc273 | 105 | * @param mptr pointer to the member function to be called |
MikamiUitOpen | 0:3e46577dc273 | 106 | * |
MikamiUitOpen | 0:3e46577dc273 | 107 | * @returns |
MikamiUitOpen | 0:3e46577dc273 | 108 | * The function object created for 'tptr' and 'mptr' |
MikamiUitOpen | 0:3e46577dc273 | 109 | */ |
MikamiUitOpen | 0:3e46577dc273 | 110 | template<typename T> |
MikamiUitOpen | 0:3e46577dc273 | 111 | pFunctionPointer_t add_front(T *tptr, void (T::*mptr)(void)) { |
MikamiUitOpen | 0:3e46577dc273 | 112 | return common_add_front(new FunctionPointer(tptr, mptr)); |
MikamiUitOpen | 0:3e46577dc273 | 113 | } |
MikamiUitOpen | 0:3e46577dc273 | 114 | |
MikamiUitOpen | 0:3e46577dc273 | 115 | /** Get the number of functions in the chain |
MikamiUitOpen | 0:3e46577dc273 | 116 | */ |
MikamiUitOpen | 0:3e46577dc273 | 117 | int size() const; |
MikamiUitOpen | 0:3e46577dc273 | 118 | |
MikamiUitOpen | 0:3e46577dc273 | 119 | /** Get a function object from the chain |
MikamiUitOpen | 0:3e46577dc273 | 120 | * |
MikamiUitOpen | 0:3e46577dc273 | 121 | * @param i function object index |
MikamiUitOpen | 0:3e46577dc273 | 122 | * |
MikamiUitOpen | 0:3e46577dc273 | 123 | * @returns |
MikamiUitOpen | 0:3e46577dc273 | 124 | * The function object at position 'i' in the chain |
MikamiUitOpen | 0:3e46577dc273 | 125 | */ |
MikamiUitOpen | 0:3e46577dc273 | 126 | pFunctionPointer_t get(int i) const; |
MikamiUitOpen | 0:3e46577dc273 | 127 | |
MikamiUitOpen | 0:3e46577dc273 | 128 | /** Look for a function object in the call chain |
MikamiUitOpen | 0:3e46577dc273 | 129 | * |
MikamiUitOpen | 0:3e46577dc273 | 130 | * @param f the function object to search |
MikamiUitOpen | 0:3e46577dc273 | 131 | * |
MikamiUitOpen | 0:3e46577dc273 | 132 | * @returns |
MikamiUitOpen | 0:3e46577dc273 | 133 | * The index of the function object if found, -1 otherwise. |
MikamiUitOpen | 0:3e46577dc273 | 134 | */ |
MikamiUitOpen | 0:3e46577dc273 | 135 | int find(pFunctionPointer_t f) const; |
MikamiUitOpen | 0:3e46577dc273 | 136 | |
MikamiUitOpen | 0:3e46577dc273 | 137 | /** Clear the call chain (remove all functions in the chain). |
MikamiUitOpen | 0:3e46577dc273 | 138 | */ |
MikamiUitOpen | 0:3e46577dc273 | 139 | void clear(); |
MikamiUitOpen | 0:3e46577dc273 | 140 | |
MikamiUitOpen | 0:3e46577dc273 | 141 | /** Remove a function object from the chain |
MikamiUitOpen | 0:3e46577dc273 | 142 | * |
MikamiUitOpen | 0:3e46577dc273 | 143 | * @arg f the function object to remove |
MikamiUitOpen | 0:3e46577dc273 | 144 | * |
MikamiUitOpen | 0:3e46577dc273 | 145 | * @returns |
MikamiUitOpen | 0:3e46577dc273 | 146 | * true if the function object was found and removed, false otherwise. |
MikamiUitOpen | 0:3e46577dc273 | 147 | */ |
MikamiUitOpen | 0:3e46577dc273 | 148 | bool remove(pFunctionPointer_t f); |
MikamiUitOpen | 0:3e46577dc273 | 149 | |
MikamiUitOpen | 0:3e46577dc273 | 150 | /** Call all the functions in the chain in sequence |
MikamiUitOpen | 0:3e46577dc273 | 151 | */ |
MikamiUitOpen | 0:3e46577dc273 | 152 | void call(); |
MikamiUitOpen | 0:3e46577dc273 | 153 | |
MikamiUitOpen | 0:3e46577dc273 | 154 | #ifdef MBED_OPERATORS |
MikamiUitOpen | 0:3e46577dc273 | 155 | void operator ()(void) { |
MikamiUitOpen | 0:3e46577dc273 | 156 | call(); |
MikamiUitOpen | 0:3e46577dc273 | 157 | } |
MikamiUitOpen | 0:3e46577dc273 | 158 | pFunctionPointer_t operator [](int i) const { |
MikamiUitOpen | 0:3e46577dc273 | 159 | return get(i); |
MikamiUitOpen | 0:3e46577dc273 | 160 | } |
MikamiUitOpen | 0:3e46577dc273 | 161 | #endif |
MikamiUitOpen | 0:3e46577dc273 | 162 | |
MikamiUitOpen | 0:3e46577dc273 | 163 | private: |
MikamiUitOpen | 0:3e46577dc273 | 164 | void _check_size(); |
MikamiUitOpen | 0:3e46577dc273 | 165 | pFunctionPointer_t common_add(pFunctionPointer_t pf); |
MikamiUitOpen | 0:3e46577dc273 | 166 | pFunctionPointer_t common_add_front(pFunctionPointer_t pf); |
MikamiUitOpen | 0:3e46577dc273 | 167 | |
MikamiUitOpen | 0:3e46577dc273 | 168 | pFunctionPointer_t* _chain; |
MikamiUitOpen | 0:3e46577dc273 | 169 | int _size; |
MikamiUitOpen | 0:3e46577dc273 | 170 | int _elements; |
MikamiUitOpen | 0:3e46577dc273 | 171 | |
MikamiUitOpen | 0:3e46577dc273 | 172 | /* disallow copy constructor and assignment operators */ |
MikamiUitOpen | 0:3e46577dc273 | 173 | private: |
MikamiUitOpen | 0:3e46577dc273 | 174 | CallChain(const CallChain&); |
MikamiUitOpen | 0:3e46577dc273 | 175 | CallChain & operator = (const CallChain&); |
MikamiUitOpen | 0:3e46577dc273 | 176 | }; |
MikamiUitOpen | 0:3e46577dc273 | 177 | |
MikamiUitOpen | 0:3e46577dc273 | 178 | } // namespace mbed |
MikamiUitOpen | 0:3e46577dc273 | 179 | |
MikamiUitOpen | 0:3e46577dc273 | 180 | #endif |
MikamiUitOpen | 0:3e46577dc273 | 181 |