Changeset 247 for cpp/frams/param


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/param
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/param/mutableparam.cpp

    r240 r247  
    108108        switch(pe->type[0])
    109109                {
    110                 case 'd': d=new int(); *((int*)d)=0; break;
     110                case 'd': d=new paInt(); *((paInt*)d)=0; break;
    111111                case 'f': d=new double(); *((double*)d)=0; break;
    112112                case 's': d=new SString(); break;
     
    114114                case 'o': d=new ExtObject(); break;
    115115                }
    116         pe->offset=(int)d;
     116        pe->offset=(intptr_t)d;
    117117        }
    118118onadd.action(position);
     
    134134        switch(pe->type[0])
    135135                {
    136                 case 'd': delete (int*)d; break;
     136                case 'd': delete (paInt*)d; break;
    137137                case 'f': delete (double*)d; break;
    138138                case 's': delete (SString*)d; break;
     
    173173pe->group=(short)group;
    174174pe->flags=(short)(flags | MUTPARAM_ALLOCENTRY);
    175 pe->offset=(long)data;
     175pe->offset=(intptr_t)data;
    176176pe->id=strdup(id);
    177177pe->type=strdup(type);
     
    209209}
    210210
    211 int MutableParam::setInt(int i,long v)
     211int MutableParam::setInt(int i,paInt v)
    212212{
    213213int ret=SimpleAbstractParam::setInt(i,v);
  • cpp/frams/param/mutableparam.h

    r197 r247  
    2323SList entries;
    2424SList groups;
    25 long changed;
     25int changed;
    2626ParamEntry *entry(int i) {return (i<staticprops)? pe_tab+i : ((ParamEntry*)entries(i-staticprops));}
    2727void *getTarget(int i) {return (i<staticprops)? SimpleAbstractParam::getTarget(i) : (void*)entry(i)->offset;}
     
    5454void notify(int id);
    5555
    56 int setInt(int,long);
     56int setInt(int,paInt);
    5757int setDouble(int,double);
    5858int setString(int,const SString &);
  • cpp/frams/param/mutparamlist.cpp

    r197 r247  
    126126}
    127127
    128 void MutableParamList::onPropAdd(void* data,long i)
     128void MutableParamList::onPropAdd(void* data,intptr_t i)
    129129{
    130130ParamInfo *pi=(ParamInfo*)data;
     
    136136}
    137137
    138 void MutableParamList::onPropDelete(void* data,long i)
     138void MutableParamList::onPropDelete(void* data,intptr_t i)
    139139{
    140140ParamInfo *pi=(ParamInfo*)data;
     
    146146}
    147147
    148 void MutableParamList::onPropChange(void* data,long i)
     148void MutableParamList::onPropChange(void* data,intptr_t i)
    149149{
    150150ParamInfo *pi=(ParamInfo*)data;
     
    152152}
    153153
    154 void MutableParamList::onPropActivate(void* data,long i)
     154void MutableParamList::onPropActivate(void* data,intptr_t i)
    155155{
    156156ParamInfo *pi=(ParamInfo*)data;
     
    158158}
    159159
    160 void MutableParamList::onGroupAdd(void* data,long i)
     160void MutableParamList::onGroupAdd(void* data,intptr_t i)
    161161{
    162162ParamInfo *pi=(ParamInfo*)data;
     
    168168}
    169169
    170 void MutableParamList::onGroupDelete(void* data,long i)
     170void MutableParamList::onGroupDelete(void* data,intptr_t i)
    171171{
    172172ParamInfo *pi=(ParamInfo*)data;
     
    178178}
    179179
    180 void MutableParamList::onGroupChange(void* data,long i)
     180void MutableParamList::onGroupChange(void* data,intptr_t i)
    181181{
    182182ParamInfo *pi=(ParamInfo*)data;
     
    295295FUN(int,flags,0)
    296296FUN(SString,getString,SString())
    297 FUN(long,getInt,0)
     297FUN(paInt,getInt,0)
    298298FUN(double,getDouble,0)
    299 FUN(ExtValue,getExtValue,ExtValue((long)0))
     299FUN(ExtValue,getExtValue,ExtValue((paInt)0))
    300300FUN(ExtObject,getObject,ExtObject())
    301301
     
    322322}
    323323
    324 FUN2(int,setInt,long)
     324FUN2(int,setInt,paInt)
    325325FUN2(int,setDouble,double)
    326326FUN2(int,setString,const SString &)
  • cpp/frams/param/mutparamlist.h

    r197 r247  
    7575
    7676SString getString(int);
    77 long getInt(int);
     77paInt getInt(int);
    7878double getDouble(int);
    7979ExtValue getExtValue(int);
    8080ExtObject getObject(int);
    8181
    82 int setInt(int,long);
     82int setInt(int,paInt);
    8383int setDouble(int,double);
    8484int setString(int,const SString &);
  • cpp/frams/param/param.cpp

    r230 r247  
    3737static const char *strchrlimit(const char *t, int ch, const char *limit)
    3838{
    39         int n = limit - t;
     39        int n = (int)(limit - t);
    4040        for (; (n > 0) && *t; t++, n--)
    4141                if (*t == ch) return t;
     
    7272}
    7373
    74 int ParamInterface::getMinMax(int prop, long& minumum, long& maximum, long &def)
     74int ParamInterface::getMinMax(int prop, paInt& minumum, paInt& maximum, paInt &def)
    7575{
    7676        const char* t = type(prop) + 1;
    7777        while (*t) if (*t == ' ') break; else t++;
    78         return sscanf(t, "%ld %ld %ld", &minumum, &maximum, &def);
     78        return sscanf(t, PA_INT_SCANF " " PA_INT_SCANF " " PA_INT_SCANF, &minumum, &maximum, &def);
    7979}
    8080
     
    121121        case 'd':
    122122        {
    123                 long a = 0, b = 0, c = 0;
     123                paInt a = 0, b = 0, c = 0;
    124124                if (getMinMax(i, a, b, c) < 3) c = a;
    125125                setInt(i, c);
     
    144144        case 'd':
    145145        {
    146                 long a = 0, b = 0, c = 0;
     146                paInt a = 0, b = 0, c = 0;
    147147                getMinMax(i, a, b, c);
    148148                setInt(i, a);
     
    167167        case 'd':
    168168        {
    169                 long a = 0, b = 0, c = 0;
     169                paInt a = 0, b = 0, c = 0;
    170170                getMinMax(i, a, b, c);
    171171                setInt(i, b);
     
    178178SString ParamInterface::getStringById(const char*prop)
    179179{int i=findId(prop); if (i>=0) return getString(i); else return SString();}
    180 long ParamInterface::getIntById(const char*prop)
     180paInt ParamInterface::getIntById(const char*prop)
    181181{int i=findId(prop); if (i>=0) return getInt(i); else return 0;}
    182182double ParamInterface::getDoubleById(const char*prop)
     
    187187{int i=findId(prop); if (i>=0) return getExtValue(i); else return ExtValue();}
    188188
    189 int ParamInterface::setIntById(const char* prop,long v)
     189int ParamInterface::setIntById(const char* prop,paInt v)
    190190{int i=findId(prop); if (i>=0) return setInt(i,v); else return PSET_NOPROPERTY;}
    191191int ParamInterface::setDoubleById(const char* prop,double v)
     
    260260        {
    261261                select(defdata);
    262                 long x = getInt(i);
     262                paInt x = getInt(i);
    263263                select(backup);
    264264                return x == getInt(i);
     
    347347                if (!*p0) break;
    348348                p = strchr(p0, ':'); if (!p) continue;
    349                 p_len = p - p0;
     349                p_len = (int)(p - p0);
    350350                loaded = false;
    351351                if (p_len && ((i = findIdn(p0, p_len)) >= 0) && (!(flags(i)&PARAM_DONTLOAD)))
     
    442442        if (!stringIsNumeric(str))
    443443        {
    444                 long a, b, c;
     444                paInt a, b, c;
    445445                if (getMinMax(i, a, b, c) >= 3)
    446446                        return setInt(i, c);
    447447                else
    448                         return setInt(i, (long)0);
     448                        return setInt(i, (paInt)0);
    449449        }
    450450        else
     
    536536                        const char *t2 = strchr(t, '~');
    537537                        if (!t2) t2 = t + strlen(t);
    538                         return SString(t, t2 - t);
     538                        return SString(t, (int)(t2 - t));
    539539                }
    540540        }
     
    599599#endif
    600600
    601 long SimpleAbstractParam::getInt(int i)
     601paInt SimpleAbstractParam::getInt(int i)
    602602{
    603603        SANITY_CHECK(i);
     
    612612        {
    613613                void *target = getTarget(i);
    614                 return *((long*)target);
     614                return *((paInt*)target);
    615615        }
    616616}
     
    687687//////// set
    688688
    689 int SimpleAbstractParam::setInt(int i, long x)
     689int SimpleAbstractParam::setInt(int i, paInt x)
    690690{
    691691        SANITY_CHECK(i);
     
    693693        ParamEntry *pe = entry(i);
    694694        if (pe->flags&PARAM_READONLY) return PSET_RONLY;
    695         long xcopy = x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below
    696         long a = 0, b = 0;
     695        paInt xcopy = x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below
     696        paInt a = 0, b = 0;
    697697        int result = 0;
    698698        const char* t = pe->type + 1;
    699699        while (*t) if (*t == ' ') break; else t++;
    700         if (sscanf(t, "%ld %ld", &a, &b) == 2)
     700        if (sscanf(t, PA_INT_SCANF " " PA_INT_SCANF, &a, &b) == 2)
    701701                if (a <= b) // if max<min then the min/max constraint check is not supported
    702702                {
     
    713713        {
    714714                void *target = getTarget(i);
    715                 if (dontcheckchanges || (*((long*)target) != x))
     715                if (dontcheckchanges || (*((paInt*)target) != x))
    716716                {
    717717                        result |= PSET_CHANGED;
    718                         *((long*)target) = x;
     718                        *((paInt*)target) = x;
    719719                }
    720720        }
     
    770770        const char* t = pe->type + 1;
    771771        while (*t) if (*t == ' ') break; else t++;
    772         long a = 0, b = 0;
     772        paInt a = 0, b = 0;
    773773        int result = 0;
    774         if (sscanf(t, "%ld %ld", &a, &b) == 2)
     774        if (sscanf(t, PA_INT_SCANF " " PA_INT_SCANF, &a, &b) == 2)
    775775        {
    776776                if ((x.len() > b) && (b > 0))
     
    883883        const char *lf = strchr(beg, '\n');
    884884        if (!lf) { lf = (const char*)s + s.len() - 1; poz = s.len(); }
    885         else { poz = (lf - (const char*)s) + 1; if (poz > s.len()) poz = s.len(); }
     885        else { poz = (int)(lf - (const char*)s) + 1; if (poz > s.len()) poz = s.len(); }
    886886        while (lf >= beg) if ((*lf == '\n') || (*lf == '\r')) lf--; else break;
    887         len = lf - beg + 1;
     887        len = (int)(lf - beg) + 1;
    888888        return beg;
    889889}
     
    939939                if (equals_sign) // have parameter name
    940940                {
    941                         tmpi = findIdn(t, equals_sign - t);
     941                        tmpi = findIdn(t, (int)(equals_sign - t));
    942942                        i = tmpi;
    943943                        if (tmpi < 0)
     
    960960                        if (quote)
    961961                        {
    962                                 tmpvalue.copyFrom(quote + 1, quote2 - quote - 1);
     962                                tmpvalue.copyFrom(quote + 1, (int)(quote2 - quote) - 1);
    963963                                sstringUnquote(tmpvalue);
    964964                                value = tmpvalue;
  • cpp/frams/param/param.h

    r230 r247  
    77
    88#include <stdio.h>
     9#include <stdint.h>
    910#include <frams/util/sstring.h>
    1011#include <frams/util/list.h>
     
    3334#define PARAM_DEPRECATED        8192
    3435
     36typedef int32_t paInt;
     37#define PA_INT_SCANF "%d"
     38
    3539// the result of param::set() is a combination of bits:
    3640
     
    9296
    9397        virtual SString getString(int) = 0;     ///< get string value, you can only use this for "s" type property
    94         virtual long getInt(int) = 0;   ///< get long value, you can only use this for "d" type property
     98        virtual paInt getInt(int) = 0;  ///< get long value, you can only use this for "d" type property
    9599        virtual double getDouble(int) = 0;      ///< get double value, you can only use this for "f" type property
    96100        virtual ExtObject getObject(int) = 0;   ///< get object reference, you can only use this for "o" type property
     
    101105
    102106        SString getStringById(const char*prop);  ///< get string value, you can only use this for "s" type property
    103         long getIntById(const char* prop);    ///< get long value, you can only use this for "d" type property
     107        paInt getIntById(const char* prop);    ///< get long value, you can only use this for "d" type property
    104108        double getDoubleById(const char* prop);///< get double value, you can only use this for "f" type property
    105109        ExtObject getObjectById(const char* prop);///< get object reference, you can only use this for "o" type property
     
    109113        int setInt(int i, const char* str);
    110114        int setDouble(int i, const char* str);
    111         virtual int setInt(int, long) = 0;              ///< set long value, you can only use this for "d" type prop
     115        virtual int setInt(int, paInt) = 0;             ///< set long value, you can only use this for "d" type prop
    112116        virtual int setDouble(int, double) = 0; ///< set double value, you can only use this for "f" type prop
    113117        virtual int setString(int, const SString &) = 0;        ///< set string value, you can only use this for "s" type prop
     
    119123        int set(int, const char*);              ///< oldstyle set, can convert string to long or double
    120124
    121         int setIntById(const char* prop, long);///< set long value, you can only use this for "d" type prop
     125        int setIntById(const char* prop, paInt);///< set long value, you can only use this for "d" type prop
    122126        int setDoubleById(const char* prop, double);///< set double value, you can only use this for "f" type prop
    123127        int setStringById(const char* prop, const SString &);///< set string value, you can only use this for "s" type prop
     
    128132        /** get valid minimum, maximum and default value for property 'prop'
    129133                @return 0 if min/max/def information is not available */
    130         int getMinMax(int prop, long& minumum, long& maximum, long& def);
     134        int getMinMax(int prop, paInt& minumum, paInt& maximum, paInt& def);
    131135        /** get valid minimum, maximum and default value for property 'prop'
    132136                @return 0 if min/max/def information is not available */
     
    172176#define SETOFFSET(_proc_) ( (int (*)(void*,const ExtValue*)) &(FIELDSTRUCT :: _proc_ ## _statrick))
    173177
    174 #define FIELDOFFSET(_fld_) ((long)((char*)(&((FIELDSTRUCT*)&MakeCodeGuardHappy)->_fld_)-((char*)((FIELDSTRUCT*)&MakeCodeGuardHappy))))
     178#define FIELDOFFSET(_fld_) ((intptr_t)((char*)(&((FIELDSTRUCT*)&MakeCodeGuardHappy)->_fld_)-((char*)((FIELDSTRUCT*)&MakeCodeGuardHappy))))
    175179
    176180#ifdef DEBUG
    177 #define PARAM_ILLEGAL_OFFSET ((long)0xdeadbeef)
     181#define PARAM_ILLEGAL_OFFSET ((intptr_t)0xdeadbeef)
    178182#else
    179183#define PARAM_ILLEGAL_OFFSET 0
     
    205209        short group, flags;
    206210        const char *name, *type;
    207         long offset;
     211        intptr_t offset;
    208212        void *fun1; ///< procedure or get
    209213        void *fun2; ///< set
     
    214218{
    215219public:
    216         ParamEntryConstructor(const char *_id, short _group = 0, short _flags = 0, const char *_name = 0, const char *_type = 0, long _offset = 0, void *_fun1 = 0, void *_fun2 = 0, const char *_help = 0)
     220        ParamEntryConstructor(const char *_id, short _group = 0, short _flags = 0, const char *_name = 0, const char *_type = 0, intptr_t _offset = 0, void *_fun1 = 0, void *_fun2 = 0, const char *_help = 0)
    217221        {
    218222                id = _id; group = _group; flags = _flags; name = _name; type = _type; offset = _offset; fun1 = _fun1; fun2 = _fun2; help = _help;
     
    254258
    255259        SString getString(int);
    256         long getInt(int);
     260        paInt getInt(int);
    257261        double getDouble(int);
    258262        ExtObject getObject(int);
     
    270274        }
    271275
    272         int setInt(int, long);
     276        int setInt(int, paInt);
    273277        int setDouble(int, double);
    274278        int setString(int, const SString &);
Note: See TracChangeset for help on using the changeset viewer.