Changeset 247 for cpp/frams/util


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

Location:
cpp/frams/util
Files:
9 edited

Legend:

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

    r197 r247  
    6161}
    6262
    63 void Callback::action(long data)
     63void Callback::action(intptr_t data)
    6464{
    6565if (size()==0) return;
  • 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
  • cpp/frams/util/extvalue.cpp

    r228 r247  
    281281}
    282282
    283 static long longsign(long x)
     283static int longsign(paInt x)
    284284{
    285285if (x<0) return -1;
     
    288288}
    289289
    290 static long compareNull(const ExtValue& v)
     290static int compareNull(const ExtValue& v)
    291291{
    292292switch(v.type)
     
    299299}
    300300
    301 long ExtValue::compare(const ExtValue& src) const
    302 {
    303 if (type==TUnknown)
     301int ExtValue::compare(const ExtValue& src) const
     302{
     303if (isNull())
    304304        return compareNull(src);
    305 else if (src.type==TUnknown)
     305else if (src.isNull())
    306306        return compareNull(*this);
    307307switch(type)
     
    309309        case TInt:
    310310        {
    311         long t=src.getInt();
     311        paInt t=src.getInt();
    312312        if (idata()>0)
    313313                {if (t>0) return longsign(idata()-t); else return +1;}
     
    545545        if (args.finished() && (type!=0) && (type!='%'))
    546546                {
    547                 ret+=fmt.substr(curr-begin);
     547                ret+=fmt.substr((int)(curr-begin));
    548548                break;
    549549                }
    550         SString sub=fmt.substr(curr-begin,next-curr);
     550        SString sub=fmt.substr((int)(curr-begin),(int)(next-curr));
    551551        switch(type)
    552552                {
     
    601601}
    602602
    603 long ExtValue::getInt(const char* s)
     603paInt ExtValue::getInt(const char* s)
    604604{
    605605if ((s[0]=='0')&&(s[1]=='x'))
    606606        {
    607         long val;
     607        paInt val;
    608608        sscanf(s+2,"%lx",&val);
    609609        return val;
     
    612612        {
    613613        if (strchr(s,'e')||(strchr(s,'E')))
    614                 return (long)atof(s);
     614                return (paInt)atof(s);
    615615        else
    616                 return atol(s);
     616                return atoi(s);
    617617        }
    618618}
     
    622622if ((s[0]=='0')&&(s[1]=='x'))
    623623        {
    624         long val;
     624        paInt val;
    625625        sscanf(s+2,"%lx",&val);
    626626        return val;
     
    630630}
    631631
    632 long ExtValue::getInt() const
     632paInt ExtValue::getInt() const
    633633{
    634634switch(type)
     
    639639        case TObj:
    640640                FMprintf("ExtValue","getInt",FMLV_WARN,"Getting integer value from object reference (%s)",(const char*)getString());
    641                 return (long)odata().param;
     641                return (paInt)(intptr_t)odata().param;
    642642        default:;
    643643        }
     
    654654        case TObj:
    655655                FMprintf("ExtValue","getDouble",FMLV_WARN,"Getting floating point value from object reference (%s)",(const char*)getString());
    656                 return (double)(long)odata().param;
     656                return (double)(intptr_t)odata().param;
    657657        default:;
    658658        }
     
    732732        else
    733733                {
    734                 setInt(atol(in));
     734                setInt(atoi(in));
    735735                return p;
    736736                }
     
    769769        {
    770770        ret=skipQuoteString(in+1,NULL);
    771         SString s(in+1,ret-(in+1));
     771        SString s(in+1,(int)(ret-(in+1)));
    772772        sstringUnquote(s);
    773773        setString(s);
     
    864864else if ((ret=skipWord(in))&&(ret!=in))
    865865        {
    866         SString clsname(in,ret-in);
     866        SString clsname(in,(int)(ret-in));
    867867        ExtValue tmp;
    868868        ret=tmp.deserialize(ret);
     
    929929ExtValue ExtValue::getExtType()
    930930{
    931 if (getType()!=TObj) return ExtValue((long)getType());
     931if (getType()!=TObj) return ExtValue((paInt)getType());
    932932ExtObject& o=odata();
    933933return ExtValue(SString(o.isEmpty()?"":o.interfaceName()));
  • cpp/frams/util/extvalue.h

    r228 r247  
    101101#ifdef EXTVALUEUNION
    102102long data[(EXTVALUEUNIONSIZE+sizeof(long)-1)/sizeof(long)];
    103 long& idata() const {return (long&)data[0];};
     103paInt& idata() const {return (paInt&)data[0];};
    104104double& ddata() const {return *(double*)data;};
    105105ExtObject& odata() const {return *(ExtObject*)data;};
     
    107107#else
    108108union {
    109 long i;
     109paInt i;
    110110double d;
    111111SString *s;
    112112ExtObject *o;
    113113};
    114 long& idata() const {return (long&)i;};
     114paInt& idata() const {return (paInt&)i;};
    115115double& ddata() const {return (double&)d;};
    116116ExtObject& odata() const {return *o;};
     
    123123ExtValue():type(TUnknown){}
    124124~ExtValue() {setEmpty();}
    125 ExtValue(long v) {seti(v);}
     125ExtValue(paInt v) {seti(v);}
    126126ExtValue(double v) {setd(v);}
    127127ExtValue(const SString &v) {sets(v);}
    128128ExtValue(const ExtObject &srco) {seto(srco);}
    129129static ExtValue invalid() {ExtValue v; v.setInvalid(); return v;}
    130 long compare(const ExtValue& src) const;
     130int compare(const ExtValue& src) const;
    131131int operator==(const ExtValue& src) const;
    132132void operator+=(const ExtValue& src);
     
    144144ExtPType getType() {return type;}
    145145void *getObjectTarget(const char* classname,bool warn=true) const;
    146 void setInt(long v) {if (type!=TInt) setri(v); else idata()=v;}
     146void setInt(paInt v) {if (type!=TInt) setri(v); else idata()=v;}
    147147void setDouble(double v) {if (type!=TDouble) setrd(v); else ddata()=v;}
    148148void setString(const SString &v) {if (type!=TString) setrs(v); else sdata()=v;}
    149149void setObject(const ExtObject &src) {if (type!=TObj) setro(src); else odata()=src;}
    150 static long getInt(const char* s);
     150static paInt getInt(const char* s);
    151151static double getDouble(const char* s);
    152 long getInt() const;
     152paInt getInt() const;
    153153double getDouble() const;
    154154SString getString() const;
     
    176176void setr(const ExtValue& src){setEmpty();set(src);}
    177177void set(const ExtValue& src);
    178 void setri(long v) {setEmpty();seti(v);}
     178void setri(paInt v) {setEmpty();seti(v);}
    179179void setrd(double v) {setEmpty();setd(v);}
    180 void seti(long v) {type=TInt;idata()=v;}
     180void seti(paInt v) {type=TInt;idata()=v;}
    181181void setd(double v) {type=TDouble;ddata()=v;}
    182182#ifdef EXTVALUEUNION
  • cpp/frams/util/hashtable.h

    r226 r247  
    2929int threshold;
    3030float load;
    31 long sync;
     31int sync;
    3232
    3333int hash(const SString &s);
  • cpp/frams/util/list.h

    r197 r247  
    5555public:
    5656
    57 SListTempl(const SListTempl<T>& src):have(0),used(0),mem(0),pos(0)
     57SListTempl(const SListTempl<T>& src):have(0),used(0),pos(0),mem(0)
    5858        {(*this)=src;}
    5959SListTempl():have(0),used(0),pos(0),mem(0)
  • cpp/frams/util/rndutil.cpp

    r197 r247  
    55#include "rndutil.h"
    66#include <common/nonstd_math.h>
     7#include <cstdint>
    78#include <stdlib.h>
    89
    910unsigned short pseudornd(short x)
    1011{
    11         static long seed = 0;
    12         long y;
     12        static int32_t seed = 0;
     13        int32_t y;
    1314        if (x <= 0) { seed = -x; return 0; }
    1415        seed = (y = (3677 * seed + 3680) & 0x7fffffff) - 1;
  • cpp/frams/util/sstring.cpp

    r226 r247  
    113113// to be moved somewhere else?
    114114// public domain source: http://isthe.com/chongo/src/fnv
    115 typedef unsigned long Fnv32_t;
     115typedef uint32_t Fnv32_t;
    116116
    117117#define FNV_32_PRIME ((Fnv32_t)0x01000193)
     
    143143//////////////////////////////////////////////////
    144144
    145 unsigned long SBuf::hash() const
     145uint32_t SBuf::hash() const
    146146{
    147147return fnv_32a_buf(txt,used,FNV1_32A_INIT);
     
    339339///////////////////////////////////////
    340340
    341 int SString::equals(const SString& s) const
    342 {
    343 if (s.buf==buf) return 1;
    344 return !strcmp(buf->txt,s.buf->txt);
     341bool SString::equals(const SString& s) const
     342{
     343if (s.buf==buf) return true;
     344return strcmp(buf->txt,s.buf->txt)==0;
    345345}
    346346
  • cpp/frams/util/sstring.h

    r198 r247  
    2222// - mutex required to be thread safe
    2323
     24#include <stdint.h>
    2425#include <string.h>
    2526#include <stdlib.h>
     
    4748SBuf();
    4849~SBuf();
    49 unsigned long hash() const; // 32-bit FNV-1 hash -> http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash
     50uint32_t hash() const; // 32-bit FNV-1 hash -> http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash
    5051};
    5152
     
    155156void operator+=(const SString&); ///< append other SString
    156157
    157 int equals(const SString &s) const; ///< TRUE if equal
    158 int operator==(const SString &s) const {return equals(s);} ///< TRUE if equal
    159 int operator!=(const SString &s) const {return !equals(s);}
     158bool equals(const SString &s) const; ///< TRUE if equal
     159bool operator==(const SString &s) const {return equals(s);} ///< TRUE if equal
     160bool operator!=(const SString &s) const {return !equals(s);}
    160161const char* operator()(int p) const {return buf->txt+p;} ///< pointer to p'th character in SString
    161162char operator[](int i) const {return buf->txt[i];} ///< get char like in array
     
    175176int startsWith(const char *pattern) const;
    176177char charAt(int pos) const {return buf->txt[pos];}
    177 unsigned long hash() const {return buf->hash();}
     178uint32_t hash() const {return buf->hash();}
    178179
    179180static SString valueOf(int);
Note: See TracChangeset for help on using the changeset viewer.