source: cpp/gdk/callbacks.cpp @ 100

Last change on this file since 100 was 66, checked in by Maciej Komosinski, 14 years ago

set 'eol-style' to 'native'

  • Property svn:eol-style set to native
File size: 2.0 KB
RevLine 
[64]1// This file is a part of the Framsticks GDK library.
2// Copyright (C) 2002-2011  Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.framsticks.com/ for further information.
[5]4
5#include "callbacks.h"
6#include <stdio.h>
7
8#ifdef USEMEMBERCALLBACK
9int MemberCallbackNode::equals(CallbackNode*n)
10{
11if (n==this) return 1;
12MemberCallbackNode *classok=dynamic_cast<MemberCallbackNode*>(n);
13if (!classok) return 0;
14return ((userdata==classok->userdata)&&(object==classok->object)&&(member==classok->member));
15}
16#endif
17
18int FunctionCallbackNode::equals(CallbackNode*n)
19{
20if (n==this) return 1;
21FunctionCallbackNode *classok=dynamic_cast<FunctionCallbackNode*>(n);
22if (!classok) return 0;
23return ((userdata==classok->userdata)&&(fun==classok->fun));
24}
25
26int StatrickCallbackNode::equals(CallbackNode*n)
27{
28if (n==this) return 1;
29StatrickCallbackNode *classok=dynamic_cast<StatrickCallbackNode*>(n);
30if (!classok) return 0;
31return ((object==classok->object)&&(userdata==classok->userdata)&&(fun==classok->fun));
32}
33
34/////////////////
35
36CallbackNode* Callback::add(CallbackNode*n)
37{
38SList::operator+=(n);
39return n;
40}
41
42void Callback::removeNode(CallbackNode*n)
43{
44SList::operator-=(n);
45delete n;
46}
47
48void Callback::remove(CallbackNode*node)
49{
50CallbackNode *n;
51//printf("Hint: removing callbacks (former 'DuoList') is more efficient using removeNode(). (refer to 'callbacks.h')\n");
52for (int i=0;n=(CallbackNode *)operator()(i);i++)
53        if (node->equals(n))
54                {
55                SList::operator-=(i);
56                delete node;
57                if (n!=node) delete n;
58                return;
59                }
60delete node; // tu nie wiem czy na pewno...
61}
62
63void Callback::action(long data)
64{
65FOREACH(CallbackNode*,n,(*this))
66        n->action(data);
67}
68
69Callback::~Callback()
70{
71CallbackNode *n;
72for (int i=size()-1;i>=0;i--)
73        {
74        n=(CallbackNode *)operator()(i);
75        delete n;
76// todo: zrobic zeby kolejnosc delete callbacknode <-> delete callback nie wplywala na poprawne dzialania
77// blad odkryty 24.01 pokazal, ze deletowanie callbacknodow w ~callback
78// moze powodowac problemy, jezeli obiekty sa usuwane w "zlej" kolejnosci
79// ale na razie tak zostanie
80        }
81}
82
Note: See TracBrowser for help on using the repository browser.