test test test

Dependencies:   mbed

Committer:
mohamedmoawya
Date:
Mon May 25 19:06:11 2020 +0000
Revision:
0:e4c5e6ec922e
snake game tteest

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mohamedmoawya 0:e4c5e6ec922e 1 /* mbed Microcontroller Library
mohamedmoawya 0:e4c5e6ec922e 2 * Copyright (c) 2006-2013 ARM Limited
mohamedmoawya 0:e4c5e6ec922e 3 *
mohamedmoawya 0:e4c5e6ec922e 4 * Licensed under the Apache License, Version 2.0 (the "License");
mohamedmoawya 0:e4c5e6ec922e 5 * you may not use this file except in compliance with the License.
mohamedmoawya 0:e4c5e6ec922e 6 * You may obtain a copy of the License at
mohamedmoawya 0:e4c5e6ec922e 7 *
mohamedmoawya 0:e4c5e6ec922e 8 * http://www.apache.org/licenses/LICENSE-2.0
mohamedmoawya 0:e4c5e6ec922e 9 *
mohamedmoawya 0:e4c5e6ec922e 10 * Unless required by applicable law or agreed to in writing, software
mohamedmoawya 0:e4c5e6ec922e 11 * distributed under the License is distributed on an "AS IS" BASIS,
mohamedmoawya 0:e4c5e6ec922e 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mohamedmoawya 0:e4c5e6ec922e 13 * See the License for the specific language governing permissions and
mohamedmoawya 0:e4c5e6ec922e 14 * limitations under the License.
mohamedmoawya 0:e4c5e6ec922e 15 */
mohamedmoawya 0:e4c5e6ec922e 16 #ifndef MBED_CALLCHAIN_H
mohamedmoawya 0:e4c5e6ec922e 17 #define MBED_CALLCHAIN_H
mohamedmoawya 0:e4c5e6ec922e 18
mohamedmoawya 0:e4c5e6ec922e 19 #include "platform/Callback.h"
mohamedmoawya 0:e4c5e6ec922e 20 #include "platform/mbed_toolchain.h"
mohamedmoawya 0:e4c5e6ec922e 21 #include "platform/NonCopyable.h"
mohamedmoawya 0:e4c5e6ec922e 22 #include <string.h>
mohamedmoawya 0:e4c5e6ec922e 23
mohamedmoawya 0:e4c5e6ec922e 24 namespace mbed {
mohamedmoawya 0:e4c5e6ec922e 25
mohamedmoawya 0:e4c5e6ec922e 26
mohamedmoawya 0:e4c5e6ec922e 27 typedef Callback<void()> *pFunctionPointer_t;
mohamedmoawya 0:e4c5e6ec922e 28 class CallChainLink;
mohamedmoawya 0:e4c5e6ec922e 29
mohamedmoawya 0:e4c5e6ec922e 30 /** \addtogroup platform */
mohamedmoawya 0:e4c5e6ec922e 31 /** @{*/
mohamedmoawya 0:e4c5e6ec922e 32 /**
mohamedmoawya 0:e4c5e6ec922e 33 * \defgroup platform_CallChain CallChain class
mohamedmoawya 0:e4c5e6ec922e 34 * @{
mohamedmoawya 0:e4c5e6ec922e 35 */
mohamedmoawya 0:e4c5e6ec922e 36
mohamedmoawya 0:e4c5e6ec922e 37 /** Group one or more functions in an instance of a CallChain, then call them in
mohamedmoawya 0:e4c5e6ec922e 38 * sequence using CallChain::call(). Used mostly by the interrupt chaining code,
mohamedmoawya 0:e4c5e6ec922e 39 * but can be used for other purposes.
mohamedmoawya 0:e4c5e6ec922e 40 *
mohamedmoawya 0:e4c5e6ec922e 41 * @deprecated Do not use this class. This class is not part of the public API of mbed-os and is being removed in the future.
mohamedmoawya 0:e4c5e6ec922e 42 * @note Synchronization level: Not protected
mohamedmoawya 0:e4c5e6ec922e 43 *
mohamedmoawya 0:e4c5e6ec922e 44 * Example:
mohamedmoawya 0:e4c5e6ec922e 45 * @code
mohamedmoawya 0:e4c5e6ec922e 46 * #include "mbed.h"
mohamedmoawya 0:e4c5e6ec922e 47 *
mohamedmoawya 0:e4c5e6ec922e 48 * CallChain chain;
mohamedmoawya 0:e4c5e6ec922e 49 *
mohamedmoawya 0:e4c5e6ec922e 50 * void first(void) {
mohamedmoawya 0:e4c5e6ec922e 51 * printf("'first' function.\n");
mohamedmoawya 0:e4c5e6ec922e 52 * }
mohamedmoawya 0:e4c5e6ec922e 53 *
mohamedmoawya 0:e4c5e6ec922e 54 * void second(void) {
mohamedmoawya 0:e4c5e6ec922e 55 * printf("'second' function.\n");
mohamedmoawya 0:e4c5e6ec922e 56 * }
mohamedmoawya 0:e4c5e6ec922e 57 *
mohamedmoawya 0:e4c5e6ec922e 58 * class Test {
mohamedmoawya 0:e4c5e6ec922e 59 * public:
mohamedmoawya 0:e4c5e6ec922e 60 * void f(void) {
mohamedmoawya 0:e4c5e6ec922e 61 * printf("A::f (class member).\n");
mohamedmoawya 0:e4c5e6ec922e 62 * }
mohamedmoawya 0:e4c5e6ec922e 63 * };
mohamedmoawya 0:e4c5e6ec922e 64 *
mohamedmoawya 0:e4c5e6ec922e 65 * int main() {
mohamedmoawya 0:e4c5e6ec922e 66 * Test test;
mohamedmoawya 0:e4c5e6ec922e 67 *
mohamedmoawya 0:e4c5e6ec922e 68 * chain.add(second);
mohamedmoawya 0:e4c5e6ec922e 69 * chain.add_front(first);
mohamedmoawya 0:e4c5e6ec922e 70 * chain.add(&test, &Test::f);
mohamedmoawya 0:e4c5e6ec922e 71 * chain.call();
mohamedmoawya 0:e4c5e6ec922e 72 * }
mohamedmoawya 0:e4c5e6ec922e 73 * @endcode
mohamedmoawya 0:e4c5e6ec922e 74 */
mohamedmoawya 0:e4c5e6ec922e 75 class CallChain : private NonCopyable<CallChain> {
mohamedmoawya 0:e4c5e6ec922e 76 public:
mohamedmoawya 0:e4c5e6ec922e 77 /** Create an empty chain
mohamedmoawya 0:e4c5e6ec922e 78 * @deprecated
mohamedmoawya 0:e4c5e6ec922e 79 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
mohamedmoawya 0:e4c5e6ec922e 80 *
mohamedmoawya 0:e4c5e6ec922e 81 * @param size (optional) Initial size of the chain
mohamedmoawya 0:e4c5e6ec922e 82 */
mohamedmoawya 0:e4c5e6ec922e 83 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
mohamedmoawya 0:e4c5e6ec922e 84 "public API of mbed-os and is being removed in the future.")
mohamedmoawya 0:e4c5e6ec922e 85 CallChain(int size = 4);
mohamedmoawya 0:e4c5e6ec922e 86
mohamedmoawya 0:e4c5e6ec922e 87 /** Create an empty chain
mohamedmoawya 0:e4c5e6ec922e 88 * @deprecated
mohamedmoawya 0:e4c5e6ec922e 89 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
mohamedmoawya 0:e4c5e6ec922e 90 */
mohamedmoawya 0:e4c5e6ec922e 91 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
mohamedmoawya 0:e4c5e6ec922e 92 "public API of mbed-os and is being removed in the future.")
mohamedmoawya 0:e4c5e6ec922e 93 virtual ~CallChain();
mohamedmoawya 0:e4c5e6ec922e 94
mohamedmoawya 0:e4c5e6ec922e 95 /** Add a function at the end of the chain
mohamedmoawya 0:e4c5e6ec922e 96 *
mohamedmoawya 0:e4c5e6ec922e 97 * @deprecated
mohamedmoawya 0:e4c5e6ec922e 98 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
mohamedmoawya 0:e4c5e6ec922e 99 *
mohamedmoawya 0:e4c5e6ec922e 100 * @param func A pointer to a void function
mohamedmoawya 0:e4c5e6ec922e 101 *
mohamedmoawya 0:e4c5e6ec922e 102 * @returns
mohamedmoawya 0:e4c5e6ec922e 103 * The function object created for 'func'
mohamedmoawya 0:e4c5e6ec922e 104 */
mohamedmoawya 0:e4c5e6ec922e 105 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
mohamedmoawya 0:e4c5e6ec922e 106 "public API of mbed-os and is being removed in the future.")
mohamedmoawya 0:e4c5e6ec922e 107 pFunctionPointer_t add(Callback<void()> func);
mohamedmoawya 0:e4c5e6ec922e 108
mohamedmoawya 0:e4c5e6ec922e 109 /** Add a function at the end of the chain
mohamedmoawya 0:e4c5e6ec922e 110 *
mohamedmoawya 0:e4c5e6ec922e 111 * @param obj pointer to the object to call the member function on
mohamedmoawya 0:e4c5e6ec922e 112 * @param method pointer to the member function to be called
mohamedmoawya 0:e4c5e6ec922e 113 *
mohamedmoawya 0:e4c5e6ec922e 114 * @returns
mohamedmoawya 0:e4c5e6ec922e 115 * The function object created for 'obj' and 'method'
mohamedmoawya 0:e4c5e6ec922e 116 *
mohamedmoawya 0:e4c5e6ec922e 117 * @deprecated
mohamedmoawya 0:e4c5e6ec922e 118 * The add function does not support cv-qualifiers. Replaced by
mohamedmoawya 0:e4c5e6ec922e 119 * add(callback(obj, method)).
mohamedmoawya 0:e4c5e6ec922e 120 */
mohamedmoawya 0:e4c5e6ec922e 121 template<typename T, typename M>
mohamedmoawya 0:e4c5e6ec922e 122 MBED_DEPRECATED_SINCE("mbed-os-5.1",
mohamedmoawya 0:e4c5e6ec922e 123 "The add function does not support cv-qualifiers. Replaced by "
mohamedmoawya 0:e4c5e6ec922e 124 "add(callback(obj, method)).")
mohamedmoawya 0:e4c5e6ec922e 125 pFunctionPointer_t add(T *obj, M method)
mohamedmoawya 0:e4c5e6ec922e 126 {
mohamedmoawya 0:e4c5e6ec922e 127 return add(callback(obj, method));
mohamedmoawya 0:e4c5e6ec922e 128 }
mohamedmoawya 0:e4c5e6ec922e 129
mohamedmoawya 0:e4c5e6ec922e 130 /** Add a function at the beginning of the chain
mohamedmoawya 0:e4c5e6ec922e 131 * @deprecated
mohamedmoawya 0:e4c5e6ec922e 132 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
mohamedmoawya 0:e4c5e6ec922e 133 *
mohamedmoawya 0:e4c5e6ec922e 134 *
mohamedmoawya 0:e4c5e6ec922e 135 * @param func A pointer to a void function
mohamedmoawya 0:e4c5e6ec922e 136 *
mohamedmoawya 0:e4c5e6ec922e 137 * @returns
mohamedmoawya 0:e4c5e6ec922e 138 * The function object created for 'func'
mohamedmoawya 0:e4c5e6ec922e 139 */
mohamedmoawya 0:e4c5e6ec922e 140 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
mohamedmoawya 0:e4c5e6ec922e 141 "public API of mbed-os and is being removed in the future.")
mohamedmoawya 0:e4c5e6ec922e 142 pFunctionPointer_t add_front(Callback<void()> func);
mohamedmoawya 0:e4c5e6ec922e 143
mohamedmoawya 0:e4c5e6ec922e 144 /** Add a function at the beginning of the chain
mohamedmoawya 0:e4c5e6ec922e 145 *
mohamedmoawya 0:e4c5e6ec922e 146 * @param obj pointer to the object to call the member function on
mohamedmoawya 0:e4c5e6ec922e 147 * @param method pointer to the member function to be called
mohamedmoawya 0:e4c5e6ec922e 148 *
mohamedmoawya 0:e4c5e6ec922e 149 * @returns
mohamedmoawya 0:e4c5e6ec922e 150 * The function object created for 'tptr' and 'mptr'
mohamedmoawya 0:e4c5e6ec922e 151 *
mohamedmoawya 0:e4c5e6ec922e 152 * @deprecated
mohamedmoawya 0:e4c5e6ec922e 153 * The add_front function does not support cv-qualifiers. Replaced by
mohamedmoawya 0:e4c5e6ec922e 154 * add_front(callback(obj, method)).
mohamedmoawya 0:e4c5e6ec922e 155 */
mohamedmoawya 0:e4c5e6ec922e 156 template<typename T, typename M>
mohamedmoawya 0:e4c5e6ec922e 157 MBED_DEPRECATED_SINCE("mbed-os-5.1",
mohamedmoawya 0:e4c5e6ec922e 158 "The add_front function does not support cv-qualifiers. Replaced by "
mohamedmoawya 0:e4c5e6ec922e 159 "add_front(callback(obj, method)).")
mohamedmoawya 0:e4c5e6ec922e 160 pFunctionPointer_t add_front(T *obj, M method)
mohamedmoawya 0:e4c5e6ec922e 161 {
mohamedmoawya 0:e4c5e6ec922e 162 return add_front(callback(obj, method));
mohamedmoawya 0:e4c5e6ec922e 163 }
mohamedmoawya 0:e4c5e6ec922e 164
mohamedmoawya 0:e4c5e6ec922e 165 /** Get the number of functions in the chain
mohamedmoawya 0:e4c5e6ec922e 166 * @deprecated
mohamedmoawya 0:e4c5e6ec922e 167 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
mohamedmoawya 0:e4c5e6ec922e 168 *
mohamedmoawya 0:e4c5e6ec922e 169 */
mohamedmoawya 0:e4c5e6ec922e 170 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
mohamedmoawya 0:e4c5e6ec922e 171 "public API of mbed-os and is being removed in the future.")
mohamedmoawya 0:e4c5e6ec922e 172 int size() const;
mohamedmoawya 0:e4c5e6ec922e 173
mohamedmoawya 0:e4c5e6ec922e 174 /** Get a function object from the chain
mohamedmoawya 0:e4c5e6ec922e 175 * @deprecated
mohamedmoawya 0:e4c5e6ec922e 176 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
mohamedmoawya 0:e4c5e6ec922e 177 *
mohamedmoawya 0:e4c5e6ec922e 178 * @param i function object index
mohamedmoawya 0:e4c5e6ec922e 179 *
mohamedmoawya 0:e4c5e6ec922e 180 * @returns
mohamedmoawya 0:e4c5e6ec922e 181 * The function object at position 'i' in the chain
mohamedmoawya 0:e4c5e6ec922e 182 */
mohamedmoawya 0:e4c5e6ec922e 183 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
mohamedmoawya 0:e4c5e6ec922e 184 "public API of mbed-os and is being removed in the future.")
mohamedmoawya 0:e4c5e6ec922e 185 pFunctionPointer_t get(int i) const;
mohamedmoawya 0:e4c5e6ec922e 186
mohamedmoawya 0:e4c5e6ec922e 187 /** Look for a function object in the call chain
mohamedmoawya 0:e4c5e6ec922e 188 * @deprecated
mohamedmoawya 0:e4c5e6ec922e 189 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
mohamedmoawya 0:e4c5e6ec922e 190 *
mohamedmoawya 0:e4c5e6ec922e 191 * @param f the function object to search
mohamedmoawya 0:e4c5e6ec922e 192 *
mohamedmoawya 0:e4c5e6ec922e 193 * @returns
mohamedmoawya 0:e4c5e6ec922e 194 * The index of the function object if found, -1 otherwise.
mohamedmoawya 0:e4c5e6ec922e 195 */
mohamedmoawya 0:e4c5e6ec922e 196 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
mohamedmoawya 0:e4c5e6ec922e 197 "public API of mbed-os and is being removed in the future.")
mohamedmoawya 0:e4c5e6ec922e 198 int find(pFunctionPointer_t f) const;
mohamedmoawya 0:e4c5e6ec922e 199
mohamedmoawya 0:e4c5e6ec922e 200 /** Clear the call chain (remove all functions in the chain).
mohamedmoawya 0:e4c5e6ec922e 201 * @deprecated Do not use this function. This class is not part of the public API of mbed-os and is being removed in the future.
mohamedmoawya 0:e4c5e6ec922e 202 */
mohamedmoawya 0:e4c5e6ec922e 203 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
mohamedmoawya 0:e4c5e6ec922e 204 "public API of mbed-os and is being removed in the future.")
mohamedmoawya 0:e4c5e6ec922e 205 void clear();
mohamedmoawya 0:e4c5e6ec922e 206
mohamedmoawya 0:e4c5e6ec922e 207 /** Remove a function object from the chain
mohamedmoawya 0:e4c5e6ec922e 208 * @deprecated
mohamedmoawya 0:e4c5e6ec922e 209 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
mohamedmoawya 0:e4c5e6ec922e 210 *
mohamedmoawya 0:e4c5e6ec922e 211 * @arg f the function object to remove
mohamedmoawya 0:e4c5e6ec922e 212 *
mohamedmoawya 0:e4c5e6ec922e 213 * @returns
mohamedmoawya 0:e4c5e6ec922e 214 * true if the function object was found and removed, false otherwise.
mohamedmoawya 0:e4c5e6ec922e 215 */
mohamedmoawya 0:e4c5e6ec922e 216 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
mohamedmoawya 0:e4c5e6ec922e 217 "public API of mbed-os and is being removed in the future.")
mohamedmoawya 0:e4c5e6ec922e 218 bool remove(pFunctionPointer_t f);
mohamedmoawya 0:e4c5e6ec922e 219
mohamedmoawya 0:e4c5e6ec922e 220 /** Call all the functions in the chain in sequence
mohamedmoawya 0:e4c5e6ec922e 221 * @deprecated
mohamedmoawya 0:e4c5e6ec922e 222 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
mohamedmoawya 0:e4c5e6ec922e 223 *
mohamedmoawya 0:e4c5e6ec922e 224 */
mohamedmoawya 0:e4c5e6ec922e 225 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
mohamedmoawya 0:e4c5e6ec922e 226 "public API of mbed-os and is being removed in the future.")
mohamedmoawya 0:e4c5e6ec922e 227 void call();
mohamedmoawya 0:e4c5e6ec922e 228
mohamedmoawya 0:e4c5e6ec922e 229 /**
mohamedmoawya 0:e4c5e6ec922e 230 * @deprecated
mohamedmoawya 0:e4c5e6ec922e 231 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
mohamedmoawya 0:e4c5e6ec922e 232 *
mohamedmoawya 0:e4c5e6ec922e 233 */
mohamedmoawya 0:e4c5e6ec922e 234 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
mohamedmoawya 0:e4c5e6ec922e 235 "public API of mbed-os and is being removed in the future.")
mohamedmoawya 0:e4c5e6ec922e 236 void operator()(void)
mohamedmoawya 0:e4c5e6ec922e 237 {
mohamedmoawya 0:e4c5e6ec922e 238 call();
mohamedmoawya 0:e4c5e6ec922e 239 }
mohamedmoawya 0:e4c5e6ec922e 240
mohamedmoawya 0:e4c5e6ec922e 241 /**
mohamedmoawya 0:e4c5e6ec922e 242 * @deprecated
mohamedmoawya 0:e4c5e6ec922e 243 * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
mohamedmoawya 0:e4c5e6ec922e 244 *
mohamedmoawya 0:e4c5e6ec922e 245 */
mohamedmoawya 0:e4c5e6ec922e 246 MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
mohamedmoawya 0:e4c5e6ec922e 247 "public API of mbed-os and is being removed in the future.")
mohamedmoawya 0:e4c5e6ec922e 248 pFunctionPointer_t operator [](int i) const
mohamedmoawya 0:e4c5e6ec922e 249 {
mohamedmoawya 0:e4c5e6ec922e 250 return get(i);
mohamedmoawya 0:e4c5e6ec922e 251 }
mohamedmoawya 0:e4c5e6ec922e 252
mohamedmoawya 0:e4c5e6ec922e 253 private:
mohamedmoawya 0:e4c5e6ec922e 254 CallChainLink *_chain;
mohamedmoawya 0:e4c5e6ec922e 255 };
mohamedmoawya 0:e4c5e6ec922e 256
mohamedmoawya 0:e4c5e6ec922e 257 /**@}*/
mohamedmoawya 0:e4c5e6ec922e 258
mohamedmoawya 0:e4c5e6ec922e 259 /**@}*/
mohamedmoawya 0:e4c5e6ec922e 260
mohamedmoawya 0:e4c5e6ec922e 261 } // namespace mbed
mohamedmoawya 0:e4c5e6ec922e 262
mohamedmoawya 0:e4c5e6ec922e 263 #endif
mohamedmoawya 0:e4c5e6ec922e 264