Ignore:
Timestamp:
11/07/14 17:51:01 (9 years ago)
Author:
Maciej Komosinski
Message:

Sources support both 32-bit and 64-bit, and more compilers

File:
1 edited

Legend:

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

    r197 r247  
    88#include "list.h"
    99#include "statrick.h"
     10#include <stdint.h>
    1011
    1112//#define USEMEMBERCALLBACK
     
    1516public:
    1617virtual ~CallbackNode() {}
    17 virtual void action(long calldata)=0;
     18virtual void action(intptr_t calldata)=0;
    1819virtual int equals(CallbackNode*n) {return (this==n);}
    1920};
     
    2526void *userdata;
    2627CallBase *object;
    27 void (CallBase::*member)(void*,long);
     28void (CallBase::*member)(void*,intptr_t);
    2829  public:
    29 MemberCallbackNode(CallBase *o,void (CallBase::*m)(void*,long),void *d):object(o),member(m),userdata(d) {}
    30 void action(long calldata) {(object->*member)(userdata,calldata);}
     30MemberCallbackNode(CallBase *o,void (CallBase::*m)(void*,intptr_t),void *d):object(o),member(m),userdata(d) {}
     31void action(intptr_t calldata) {(object->*member)(userdata,calldata);}
    3132int equals(CallbackNode*);
    3233};
    33 #define MEMBERCALLBACK(obj,mem,dat) new MemberCallbackNode((CallBase*)(obj),(void (CallBase::*)(void*,long))(mem),(void*)(dat))
     34#define MEMBERCALLBACK(obj,mem,dat) new MemberCallbackNode((CallBase*)(obj),(void (CallBase::*)(void*,intptr_t))(mem),(void*)(dat))
    3435#endif
    3536
     
    3738{
    3839void *userdata;
    39 void (*fun)(void*,long);
     40void (*fun)(void*,intptr_t);
    4041  public:
    41 FunctionCallbackNode(void (*f)(void*,long),void *d):userdata(d),fun(f) {}
    42 void action(long calldata) {(*fun)(userdata,calldata);}
     42FunctionCallbackNode(void (*f)(void*,intptr_t),void *d):userdata(d),fun(f) {}
     43void action(intptr_t calldata) {(*fun)(userdata,calldata);}
    4344int equals(CallbackNode*);
    4445};
    45 #define FUNCTIONCALLBACK(fun,dat) new FunctionCallbackNode((void (*)(void*,long))(fun),(void*)(dat))
     46#define FUNCTIONCALLBACK(fun,dat) new FunctionCallbackNode((void (*)(void*,intptr_t))(fun),(void*)(dat))
    4647
    4748class StatrickCallbackNode :public CallbackNode
     
    4950void *object;
    5051void *userdata;
    51 void (*fun)(void*,void*,long);
     52void (*fun)(void*,void*,intptr_t);
    5253  public:
    53 StatrickCallbackNode(void *o,void (*f)(void*,void*,long),void *d):object(o),userdata(d),fun(f) {}
    54 void action(long calldata) {(*fun)(object,userdata,calldata);}
     54StatrickCallbackNode(void *o,void (*f)(void*,void*,intptr_t),void *d):object(o),userdata(d),fun(f) {}
     55void action(intptr_t calldata) {(*fun)(object,userdata,calldata);}
    5556int equals(CallbackNode*);
    5657};
    57 #define STATRICKCALLBACK(obj,name,dat) new StatrickCallbackNode((void*)(obj),(void (*)(void*,void*,long))STATRICKNAME(name),(void*)(dat))
     58#define STATRICKCALLBACK(obj,name,dat) new StatrickCallbackNode((void*)(obj),(void (*)(void*,void*,intptr_t))STATRICKNAME(name),(void*)(dat))
    5859
    5960/**
     
    6162      add(Function* fun, void* anydata)
    6263   'fun' will be called with your pointer as the first argument (void*)
    63    and event specific value as the second argument (long)
    64       fun(void* anydata,long eventdata)
     64   and event specific value as the second argument (intptr_t)
     65      fun(void* anydata,intptr_t eventdata)
    6566
    6667   'StatrickCallbackNode' uses static functions to emulate object member calls.
     
    8182~Callback();
    8283CallbackNode* add(CallbackNode*n);
    83 CallbackNode* add(void (*f)(void*,long),void *d)
     84CallbackNode* add(void (*f)(void*,intptr_t),void *d)
    8485        {return add(new FunctionCallbackNode(f,d));}
    85 void remove(void (*f)(void*,long),void *d)
     86void remove(void (*f)(void*,intptr_t),void *d)
    8687        {remove(new FunctionCallbackNode(f,d));}
    8788void remove(CallbackNode*n);
    8889void removeNode(CallbackNode*n);
    89 void operator+=(void* fun) {add((void (*)(void*,long))fun,0);}
    90 void operator-=(void* fun) {remove((void (*)(void*,long))fun,0);}
    91 void action(long data);
     90void operator+=(void* fun) {add((void (*)(void*,intptr_t))fun,0);}
     91void operator-=(void* fun) {remove((void (*)(void*,intptr_t))fun,0);}
     92void action(intptr_t data);
    9293void action() {action(0);}
    9394int size() {return SList::size();}
     
    9798///////////////////
    9899
    99 #define STCALLBACKDEF(name) STATRICKDEF2(name,void*,long)
    100 #define STCALLBACKDEFC(cls,name) STATRICKSTUB2(cls,name,void*,long)  \
    101         void name(void* arg1,long arg2)
    102 #define VIRTCALLBACKDEF(name) STATRICKSTUB2(STATRICKCLASS,name,void*,long)  \
    103         virtual void name(void* arg1,long arg2)
    104 #define VIRTCALLBACKDEFC(cls,name) STATRICKSTUB2(cls,name,void*,long)  \
    105         virtual void name(void* arg1,long arg2)
     100#define STCALLBACKDEF(name) STATRICKDEF2(name,void*,intptr_t)
     101#define STCALLBACKDEFC(cls,name) STATRICKSTUB2(cls,name,void*,intptr_t)  \
     102        void name(void* arg1,intptr_t arg2)
     103#define VIRTCALLBACKDEF(name) STATRICKSTUB2(STATRICKCLASS,name,void*,intptr_t)  \
     104        virtual void name(void* arg1,intptr_t arg2)
     105#define VIRTCALLBACKDEFC(cls,name) STATRICKSTUB2(cls,name,void*,intptr_t)  \
     106        virtual void name(void* arg1,intptr_t arg2)
    106107
    107108/* STCALLBACKDEFC(Class,name)
     
    115116 */
    116117
    117 #define CALLBACKARGS void* arg1,long arg2
     118#define CALLBACKARGS void* arg1,intptr_t arg2
    118119
    119120#endif
Note: See TracChangeset for help on using the changeset viewer.