6 CallChain::CallChain(int size) : _chain(), _size(size), _elements(0) {
7 _chain = new pFunctionPointer_t[size]();
10 CallChain::~CallChain() {
15 pFunctionPointer_t CallChain::add(void (*function)(void)) {
16 return common_add(new FunctionPointer(function));
19 pFunctionPointer_t CallChain::add_front(void (*function)(void)) {
20 return common_add_front(new FunctionPointer(function));
23 int CallChain::size() const {
27 pFunctionPointer_t CallChain::get(int i) const {
28 if (i < 0 || i >= _elements)
33 int CallChain::find(pFunctionPointer_t f) const {
34 for (int i = 0; i < _elements; i++)
40 void CallChain::clear() {
41 for(int i = 0; i < _elements; i ++) {
48 bool CallChain::remove(pFunctionPointer_t f) {
51 if ((i = find(f)) == -1)
53 if (i != _elements - 1)
54 memmove(_chain + i, _chain + i + 1, (_elements - i - 1) * sizeof(pFunctionPointer_t));
60 void CallChain::call() {
61 for(int i = 0; i < _elements; i++)
65 void CallChain::_check_size() {
66 if (_elements < _size)
68 _size = (_size < 4) ? 4 : _size + 4;
69 pFunctionPointer_t* new_chain = new pFunctionPointer_t[_size]();
70 memcpy(new_chain, _chain, _elements * sizeof(pFunctionPointer_t));
75 pFunctionPointer_t CallChain::common_add(pFunctionPointer_t pf) {
77 _chain[_elements] = pf;
82 pFunctionPointer_t CallChain::common_add_front(pFunctionPointer_t pf) {
84 memmove(_chain + 1, _chain, _elements * sizeof(pFunctionPointer_t));