Ignore:
Timestamp:
05/29/18 16:51:14 (6 years ago)
Author:
Maciej Komosinski
Message:

Code formatting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/util/callbacks.h

    r286 r793  
    1515{
    1616public:
    17 virtual ~CallbackNode() {}
    18 virtual void action(intptr_t calldata)=0;
    19 virtual int equals(CallbackNode*n) {return (this==n);}
     17        virtual ~CallbackNode() {}
     18        virtual void action(intptr_t calldata) = 0;
     19        virtual int equals(CallbackNode*n) { return (this == n); }
    2020};
    2121
     
    2424class MemberCallbackNode :public CallbackNode
    2525{
    26 void *userdata;
    27 CallBase *object;
    28 void (CallBase::*member)(void*,intptr_t);
    29   public:
    30 MemberCallbackNode(CallBase *o,void (CallBase::*m)(void*,intptr_t),void *d):object(o),member(m),userdata(d) {}
    31 void action(intptr_t calldata) {(object->*member)(userdata,calldata);}
    32 int equals(CallbackNode*);
     26        void *userdata;
     27        CallBase *object;
     28        void (CallBase::*member)(void*, intptr_t);
     29public:
     30        MemberCallbackNode(CallBase *o, void (CallBase::*m)(void*, intptr_t), void *d) :object(o), member(m), userdata(d) {}
     31        void action(intptr_t calldata) { (object->*member)(userdata, calldata); }
     32        int equals(CallbackNode*);
    3333};
    3434#define MEMBERCALLBACK(obj,mem,dat) new MemberCallbackNode((CallBase*)(obj),(void (CallBase::*)(void*,intptr_t))(mem),(void*)(dat))
     
    3737class FunctionCallbackNode :public CallbackNode
    3838{
    39 void *userdata;
    40 void (*fun)(void*,intptr_t);
    41   public:
    42 FunctionCallbackNode(void (*f)(void*,intptr_t),void *d):userdata(d),fun(f) {}
    43 void action(intptr_t calldata) {(*fun)(userdata,calldata);}
    44 int equals(CallbackNode*);
     39        void *userdata;
     40        void(*fun)(void*, intptr_t);
     41public:
     42        FunctionCallbackNode(void(*f)(void*, intptr_t), void *d) :userdata(d), fun(f) {}
     43        void action(intptr_t calldata) { (*fun)(userdata, calldata); }
     44        int equals(CallbackNode*);
    4545};
    4646#define FUNCTIONCALLBACK(fun,dat) new FunctionCallbackNode((void (*)(void*,intptr_t))(fun),(void*)(dat))
     
    4848class StatrickCallbackNode :public CallbackNode
    4949{
    50 void *object;
    51 void *userdata;
    52 void (*fun)(void*,void*,intptr_t);
    53   public:
    54 StatrickCallbackNode(void *o,void (*f)(void*,void*,intptr_t),void *d):object(o),userdata(d),fun(f) {}
    55 void action(intptr_t calldata) {(*fun)(object,userdata,calldata);}
    56 int equals(CallbackNode*);
     50        void *object;
     51        void *userdata;
     52        void(*fun)(void*, void*, intptr_t);
     53public:
     54        StatrickCallbackNode(void *o, void(*f)(void*, void*, intptr_t), void *d) :object(o), userdata(d), fun(f) {}
     55        void action(intptr_t calldata) { (*fun)(object, userdata, calldata); }
     56        int equals(CallbackNode*);
    5757};
    5858#define STATRICKCALLBACK(obj,name,dat) new StatrickCallbackNode((void*)(obj),(void (*)(void*,void*,intptr_t))STATRICKNAME(name),(void*)(dat))
     
    6060/**
    6161   Like in old 'DuoList' you can register for an event giving function pointer
    62       add(Function* fun, void* anydata)
     62   add(Function* fun, void* anydata)
    6363   'fun' will be called with your pointer as the first argument (void*)
    6464   and event specific value as the second argument (intptr_t)
    65       fun(void* anydata,intptr_t eventdata)
     65   fun(void* anydata,intptr_t eventdata)
    6666
    6767   'StatrickCallbackNode' uses static functions to emulate object member calls.
    6868   @see statrick.h
    69    
     69
    7070   Unregistering callbacks:
    7171   The old remove(...) still works, but removeNode() is more efficient.
    7272   To use it you have to store what you get from add(...);
    73       CallbackNode* node=thelist.l_add.add(&fun,data);
    74       // thelist.l_add.remove(&fun,data);
    75       thelist.l_add.removeNode(node); // this is better!
     73   CallbackNode* node=thelist.l_add.add(&fun,data);
     74   // thelist.l_add.remove(&fun,data);
     75   thelist.l_add.removeNode(node); // this is better!
    7676
    77  */
     77   */
    7878
    79 class Callback: protected SList
     79class Callback : protected SList
    8080{
    8181public:
    82 ~Callback();
    83 CallbackNode* add(CallbackNode*n);
    84 CallbackNode* add(void (*f)(void*,intptr_t),void *d)
    85         {return add(new FunctionCallbackNode(f,d));}
    86 void remove(void (*f)(void*,intptr_t),void *d)
    87         {remove(new FunctionCallbackNode(f,d));}
    88 void remove(CallbackNode*n);
    89 void removeNode(CallbackNode*n);
    90 void operator+=(void* fun) {add((void (*)(void*,intptr_t))fun,0);}
    91 void operator-=(void* fun) {remove((void (*)(void*,intptr_t))fun,0);}
    92 void action(intptr_t data);
    93 void action() {action(0);}
    94 int size() {return SList::size();}
    95 void clear() {SList::clear();}
     82        ~Callback();
     83        CallbackNode* add(CallbackNode*n);
     84        CallbackNode* add(void(*f)(void*, intptr_t), void *d)
     85        {
     86                return add(new FunctionCallbackNode(f, d));
     87        }
     88        void remove(void(*f)(void*, intptr_t), void *d)
     89        {
     90                remove(new FunctionCallbackNode(f, d));
     91        }
     92        void remove(CallbackNode*n);
     93        void removeNode(CallbackNode*n);
     94        void operator+=(void* fun) { add((void(*)(void*, intptr_t))fun, 0); }
     95        void operator-=(void* fun) { remove((void(*)(void*, intptr_t))fun, 0); }
     96        void action(intptr_t data);
     97        void action() { action(0); }
     98        int size() { return SList::size(); }
     99        void clear() { SList::clear(); }
    96100};
    97101
     
    108112/* STCALLBACKDEFC(Class,name)
    109113
    110     |
    111     v
     114        |
     115        v
    112116
    113   #define STATRICKCLASS Class
    114   STCALLBACKDEF(name)
    115   #undef STATRICKCLASS
    116  */
     117        #define STATRICKCLASS Class
     118        STCALLBACKDEF(name)
     119        #undef STATRICKCLASS
     120        */
    117121
    118122#define CALLBACKARGS void* arg1,intptr_t arg2
    119123
    120124#endif
    121 
Note: See TracChangeset for help on using the changeset viewer.