mbed-drivers
CallChain.h
1 /*
2  * Copyright (c) 2006-2016, ARM Limited, All Rights Reserved
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may
6  * not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #ifndef MBED_CALLCHAIN_H
18 #define MBED_CALLCHAIN_H
19 
20 #include "core-util/FunctionPointer.h"
21 #include <string.h>
22 
23 namespace mbed {
24 
61 typedef mbed::util::FunctionPointer* pFunctionPointer_t;
62 
63 class CallChain {
64 public:
69  CallChain(int size = 4);
70  virtual ~CallChain();
71 
79  pFunctionPointer_t add(void (*function)(void));
80 
89  template<typename T>
90  pFunctionPointer_t add(T *tptr, void (T::*mptr)(void)) {
91  return common_add(new mbed::util::FunctionPointer(tptr, mptr));
92  }
93 
101  pFunctionPointer_t add_front(void (*function)(void));
102 
111  template<typename T>
112  pFunctionPointer_t add_front(T *tptr, void (T::*mptr)(void)) {
113  return common_add_front(new mbed::util::FunctionPointer(tptr, mptr));
114  }
115 
118  int size() const;
119 
127  pFunctionPointer_t get(int i) const;
128 
136  int find(pFunctionPointer_t f) const;
137 
140  void clear();
141 
149  bool remove(pFunctionPointer_t f);
150 
153  void call();
154 
155 #ifdef MBED_OPERATORS
156  void operator ()(void) {
157  call();
158  }
159  pFunctionPointer_t operator [](int i) const {
160  return get(i);
161  }
162 #endif
163 
164 private:
165  void _check_size();
166  pFunctionPointer_t common_add(pFunctionPointer_t pf);
167  pFunctionPointer_t common_add_front(pFunctionPointer_t pf);
168 
169  pFunctionPointer_t* _chain;
170  int _size;
171  int _elements;
172 
173  /* disallow copy constructor and assignment operators */
174 private:
175  CallChain(const CallChain&);
176  CallChain & operator = (const CallChain&);
177 };
178 
179 } // namespace mbed
180 
181 #endif
182 
void call()
Definition: CallChain.cpp:76
pFunctionPointer_t add_front(void(*function)(void))
Definition: CallChain.cpp:35
void clear()
Definition: CallChain.cpp:56
pFunctionPointer_t add(T *tptr, void(T::*mptr)(void))
Definition: CallChain.h:90
CallChain(int size=4)
Definition: CallChain.cpp:22
int size() const
Definition: CallChain.cpp:39
pFunctionPointer_t add(void(*function)(void))
Definition: CallChain.cpp:31
int find(pFunctionPointer_t f) const
Definition: CallChain.cpp:49
Definition: BusIn.cpp:19
pFunctionPointer_t add_front(T *tptr, void(T::*mptr)(void))
Definition: CallChain.h:112
Definition: CallChain.h:63