Changeset 247 for cpp/frams/util
- Timestamp:
- 11/07/14 17:51:01 (10 years ago)
- Location:
- cpp/frams/util
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/util/callbacks.cpp
r197 r247 61 61 } 62 62 63 void Callback::action( longdata)63 void Callback::action(intptr_t data) 64 64 { 65 65 if (size()==0) return; -
cpp/frams/util/callbacks.h
r197 r247 8 8 #include "list.h" 9 9 #include "statrick.h" 10 #include <stdint.h> 10 11 11 12 //#define USEMEMBERCALLBACK … … 15 16 public: 16 17 virtual ~CallbackNode() {} 17 virtual void action( longcalldata)=0;18 virtual void action(intptr_t calldata)=0; 18 19 virtual int equals(CallbackNode*n) {return (this==n);} 19 20 }; … … 25 26 void *userdata; 26 27 CallBase *object; 27 void (CallBase::*member)(void*, long);28 void (CallBase::*member)(void*,intptr_t); 28 29 public: 29 MemberCallbackNode(CallBase *o,void (CallBase::*m)(void*, long),void *d):object(o),member(m),userdata(d) {}30 void action( longcalldata) {(object->*member)(userdata,calldata);}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);} 31 32 int equals(CallbackNode*); 32 33 }; 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)) 34 35 #endif 35 36 … … 37 38 { 38 39 void *userdata; 39 void (*fun)(void*, long);40 void (*fun)(void*,intptr_t); 40 41 public: 41 FunctionCallbackNode(void (*f)(void*, long),void *d):userdata(d),fun(f) {}42 void action( longcalldata) {(*fun)(userdata,calldata);}42 FunctionCallbackNode(void (*f)(void*,intptr_t),void *d):userdata(d),fun(f) {} 43 void action(intptr_t calldata) {(*fun)(userdata,calldata);} 43 44 int equals(CallbackNode*); 44 45 }; 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)) 46 47 47 48 class StatrickCallbackNode :public CallbackNode … … 49 50 void *object; 50 51 void *userdata; 51 void (*fun)(void*,void*, long);52 void (*fun)(void*,void*,intptr_t); 52 53 public: 53 StatrickCallbackNode(void *o,void (*f)(void*,void*, long),void *d):object(o),userdata(d),fun(f) {}54 void action( longcalldata) {(*fun)(object,userdata,calldata);}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);} 55 56 int equals(CallbackNode*); 56 57 }; 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)) 58 59 59 60 /** … … 61 62 add(Function* fun, void* anydata) 62 63 '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, longeventdata)64 and event specific value as the second argument (intptr_t) 65 fun(void* anydata,intptr_t eventdata) 65 66 66 67 'StatrickCallbackNode' uses static functions to emulate object member calls. … … 81 82 ~Callback(); 82 83 CallbackNode* add(CallbackNode*n); 83 CallbackNode* add(void (*f)(void*, long),void *d)84 CallbackNode* add(void (*f)(void*,intptr_t),void *d) 84 85 {return add(new FunctionCallbackNode(f,d));} 85 void remove(void (*f)(void*, long),void *d)86 void remove(void (*f)(void*,intptr_t),void *d) 86 87 {remove(new FunctionCallbackNode(f,d));} 87 88 void remove(CallbackNode*n); 88 89 void 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( longdata);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); 92 93 void action() {action(0);} 93 94 int size() {return SList::size();} … … 97 98 /////////////////// 98 99 99 #define STCALLBACKDEF(name) STATRICKDEF2(name,void*, long)100 #define STCALLBACKDEFC(cls,name) STATRICKSTUB2(cls,name,void*, long) \101 void name(void* arg1, longarg2)102 #define VIRTCALLBACKDEF(name) STATRICKSTUB2(STATRICKCLASS,name,void*, long) \103 virtual void name(void* arg1, longarg2)104 #define VIRTCALLBACKDEFC(cls,name) STATRICKSTUB2(cls,name,void*, long) \105 virtual void name(void* arg1, longarg2)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) 106 107 107 108 /* STCALLBACKDEFC(Class,name) … … 115 116 */ 116 117 117 #define CALLBACKARGS void* arg1, longarg2118 #define CALLBACKARGS void* arg1,intptr_t arg2 118 119 119 120 #endif -
cpp/frams/util/extvalue.cpp
r228 r247 281 281 } 282 282 283 static long longsign(longx)283 static int longsign(paInt x) 284 284 { 285 285 if (x<0) return -1; … … 288 288 } 289 289 290 static longcompareNull(const ExtValue& v)290 static int compareNull(const ExtValue& v) 291 291 { 292 292 switch(v.type) … … 299 299 } 300 300 301 longExtValue::compare(const ExtValue& src) const302 { 303 if ( type==TUnknown)301 int ExtValue::compare(const ExtValue& src) const 302 { 303 if (isNull()) 304 304 return compareNull(src); 305 else if (src. type==TUnknown)305 else if (src.isNull()) 306 306 return compareNull(*this); 307 307 switch(type) … … 309 309 case TInt: 310 310 { 311 longt=src.getInt();311 paInt t=src.getInt(); 312 312 if (idata()>0) 313 313 {if (t>0) return longsign(idata()-t); else return +1;} … … 545 545 if (args.finished() && (type!=0) && (type!='%')) 546 546 { 547 ret+=fmt.substr( curr-begin);547 ret+=fmt.substr((int)(curr-begin)); 548 548 break; 549 549 } 550 SString sub=fmt.substr( curr-begin,next-curr);550 SString sub=fmt.substr((int)(curr-begin),(int)(next-curr)); 551 551 switch(type) 552 552 { … … 601 601 } 602 602 603 longExtValue::getInt(const char* s)603 paInt ExtValue::getInt(const char* s) 604 604 { 605 605 if ((s[0]=='0')&&(s[1]=='x')) 606 606 { 607 longval;607 paInt val; 608 608 sscanf(s+2,"%lx",&val); 609 609 return val; … … 612 612 { 613 613 if (strchr(s,'e')||(strchr(s,'E'))) 614 return ( long)atof(s);614 return (paInt)atof(s); 615 615 else 616 return ato l(s);616 return atoi(s); 617 617 } 618 618 } … … 622 622 if ((s[0]=='0')&&(s[1]=='x')) 623 623 { 624 longval;624 paInt val; 625 625 sscanf(s+2,"%lx",&val); 626 626 return val; … … 630 630 } 631 631 632 longExtValue::getInt() const632 paInt ExtValue::getInt() const 633 633 { 634 634 switch(type) … … 639 639 case TObj: 640 640 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; 642 642 default:; 643 643 } … … 654 654 case TObj: 655 655 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; 657 657 default:; 658 658 } … … 732 732 else 733 733 { 734 setInt(ato l(in));734 setInt(atoi(in)); 735 735 return p; 736 736 } … … 769 769 { 770 770 ret=skipQuoteString(in+1,NULL); 771 SString s(in+1, ret-(in+1));771 SString s(in+1,(int)(ret-(in+1))); 772 772 sstringUnquote(s); 773 773 setString(s); … … 864 864 else if ((ret=skipWord(in))&&(ret!=in)) 865 865 { 866 SString clsname(in, ret-in);866 SString clsname(in,(int)(ret-in)); 867 867 ExtValue tmp; 868 868 ret=tmp.deserialize(ret); … … 929 929 ExtValue ExtValue::getExtType() 930 930 { 931 if (getType()!=TObj) return ExtValue(( long)getType());931 if (getType()!=TObj) return ExtValue((paInt)getType()); 932 932 ExtObject& o=odata(); 933 933 return ExtValue(SString(o.isEmpty()?"":o.interfaceName())); -
cpp/frams/util/extvalue.h
r228 r247 101 101 #ifdef EXTVALUEUNION 102 102 long data[(EXTVALUEUNIONSIZE+sizeof(long)-1)/sizeof(long)]; 103 long& idata() const {return (long&)data[0];};103 paInt& idata() const {return (paInt&)data[0];}; 104 104 double& ddata() const {return *(double*)data;}; 105 105 ExtObject& odata() const {return *(ExtObject*)data;}; … … 107 107 #else 108 108 union { 109 longi;109 paInt i; 110 110 double d; 111 111 SString *s; 112 112 ExtObject *o; 113 113 }; 114 long& idata() const {return (long&)i;};114 paInt& idata() const {return (paInt&)i;}; 115 115 double& ddata() const {return (double&)d;}; 116 116 ExtObject& odata() const {return *o;}; … … 123 123 ExtValue():type(TUnknown){} 124 124 ~ExtValue() {setEmpty();} 125 ExtValue( longv) {seti(v);}125 ExtValue(paInt v) {seti(v);} 126 126 ExtValue(double v) {setd(v);} 127 127 ExtValue(const SString &v) {sets(v);} 128 128 ExtValue(const ExtObject &srco) {seto(srco);} 129 129 static ExtValue invalid() {ExtValue v; v.setInvalid(); return v;} 130 longcompare(const ExtValue& src) const;130 int compare(const ExtValue& src) const; 131 131 int operator==(const ExtValue& src) const; 132 132 void operator+=(const ExtValue& src); … … 144 144 ExtPType getType() {return type;} 145 145 void *getObjectTarget(const char* classname,bool warn=true) const; 146 void setInt( longv) {if (type!=TInt) setri(v); else idata()=v;}146 void setInt(paInt v) {if (type!=TInt) setri(v); else idata()=v;} 147 147 void setDouble(double v) {if (type!=TDouble) setrd(v); else ddata()=v;} 148 148 void setString(const SString &v) {if (type!=TString) setrs(v); else sdata()=v;} 149 149 void setObject(const ExtObject &src) {if (type!=TObj) setro(src); else odata()=src;} 150 static longgetInt(const char* s);150 static paInt getInt(const char* s); 151 151 static double getDouble(const char* s); 152 longgetInt() const;152 paInt getInt() const; 153 153 double getDouble() const; 154 154 SString getString() const; … … 176 176 void setr(const ExtValue& src){setEmpty();set(src);} 177 177 void set(const ExtValue& src); 178 void setri( longv) {setEmpty();seti(v);}178 void setri(paInt v) {setEmpty();seti(v);} 179 179 void setrd(double v) {setEmpty();setd(v);} 180 void seti( longv) {type=TInt;idata()=v;}180 void seti(paInt v) {type=TInt;idata()=v;} 181 181 void setd(double v) {type=TDouble;ddata()=v;} 182 182 #ifdef EXTVALUEUNION -
cpp/frams/util/hashtable.h
r226 r247 29 29 int threshold; 30 30 float load; 31 longsync;31 int sync; 32 32 33 33 int hash(const SString &s); -
cpp/frams/util/list.h
r197 r247 55 55 public: 56 56 57 SListTempl(const SListTempl<T>& src):have(0),used(0), mem(0),pos(0)57 SListTempl(const SListTempl<T>& src):have(0),used(0),pos(0),mem(0) 58 58 {(*this)=src;} 59 59 SListTempl():have(0),used(0),pos(0),mem(0) -
cpp/frams/util/rndutil.cpp
r197 r247 5 5 #include "rndutil.h" 6 6 #include <common/nonstd_math.h> 7 #include <cstdint> 7 8 #include <stdlib.h> 8 9 9 10 unsigned short pseudornd(short x) 10 11 { 11 static longseed = 0;12 longy;12 static int32_t seed = 0; 13 int32_t y; 13 14 if (x <= 0) { seed = -x; return 0; } 14 15 seed = (y = (3677 * seed + 3680) & 0x7fffffff) - 1; -
cpp/frams/util/sstring.cpp
r226 r247 113 113 // to be moved somewhere else? 114 114 // public domain source: http://isthe.com/chongo/src/fnv 115 typedef u nsigned longFnv32_t;115 typedef uint32_t Fnv32_t; 116 116 117 117 #define FNV_32_PRIME ((Fnv32_t)0x01000193) … … 143 143 ////////////////////////////////////////////////// 144 144 145 u nsigned longSBuf::hash() const145 uint32_t SBuf::hash() const 146 146 { 147 147 return fnv_32a_buf(txt,used,FNV1_32A_INIT); … … 339 339 /////////////////////////////////////// 340 340 341 intSString::equals(const SString& s) const342 { 343 if (s.buf==buf) return 1;344 return !strcmp(buf->txt,s.buf->txt);341 bool SString::equals(const SString& s) const 342 { 343 if (s.buf==buf) return true; 344 return strcmp(buf->txt,s.buf->txt)==0; 345 345 } 346 346 -
cpp/frams/util/sstring.h
r198 r247 22 22 // - mutex required to be thread safe 23 23 24 #include <stdint.h> 24 25 #include <string.h> 25 26 #include <stdlib.h> … … 47 48 SBuf(); 48 49 ~SBuf(); 49 u nsigned longhash() const; // 32-bit FNV-1 hash -> http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash50 uint32_t hash() const; // 32-bit FNV-1 hash -> http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash 50 51 }; 51 52 … … 155 156 void operator+=(const SString&); ///< append other SString 156 157 157 intequals(const SString &s) const; ///< TRUE if equal158 intoperator==(const SString &s) const {return equals(s);} ///< TRUE if equal159 intoperator!=(const SString &s) const {return !equals(s);}158 bool equals(const SString &s) const; ///< TRUE if equal 159 bool operator==(const SString &s) const {return equals(s);} ///< TRUE if equal 160 bool operator!=(const SString &s) const {return !equals(s);} 160 161 const char* operator()(int p) const {return buf->txt+p;} ///< pointer to p'th character in SString 161 162 char operator[](int i) const {return buf->txt[i];} ///< get char like in array … … 175 176 int startsWith(const char *pattern) const; 176 177 char charAt(int pos) const {return buf->txt[pos];} 177 u nsigned longhash() const {return buf->hash();}178 uint32_t hash() const {return buf->hash();} 178 179 179 180 static SString valueOf(int);
Note: See TracChangeset
for help on using the changeset viewer.