Changeset 104 for cpp/gdk/param.cpp


Ignore:
Timestamp:
07/23/13 18:15:30 (11 years ago)
Author:
sz
Message:

introducing object de/serialization - see serialtest.cpp
the core GDK classes can be now used in multiple threads (ifdef MULTITHREADED)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/gdk/param.cpp

    r93 r104  
    231231}
    232232
     233const char* ParamInterface::SERIALIZATION_PREFIX="@Serialized:";
     234
    233235int ParamInterface::saveprop(VirtFILE* f,int i,const char* p,bool force)
    234236{
     
    243245err|=(fputs(p,f)==EOF); fputc(':',f);
    244246cr=0;
    245 ws=get(i);
     247if (*typ=='x')
     248        {
     249        ExtValue ex;
     250        get(i,ex);
     251        ws=SString(SERIALIZATION_PREFIX)+ex.serialize();
     252        }
     253else
     254        ws=get(i);
    246255quoteTilde(ws);
    247256w=ws;
     
    497506        {
    498507        ExtValue e;
    499         if (isdigit(*v)||((*v=='-')&&isdigit(v[1])))
    500                 {
    501                 if (strchr(v,'.')) e.setDouble(atof(v));
    502                 else e.setInt(atol(v));
     508        const char* after;
     509        if (!strncmp(v,SERIALIZATION_PREFIX,strlen(SERIALIZATION_PREFIX)))
     510                {
     511                after=e.deserialize(v+strlen(SERIALIZATION_PREFIX));
     512                if ((after==NULL)||(*after))
     513                        FMprintf("ParamInterface","set",FMLV_WARN,"serialization format mismatch in %s.%s",(getName()?getName():"<Unknown>"),id(i));
     514                }
     515        else if ((after=e.parseNumber(v))&&(*after==0)) //consumed the whole string
     516                {
     517                //OK!
    503518                }
    504519        else
     
    566581long SimpleAbstractParam::getInt(int i)
    567582{
    568 static ExtValue v;
     583ExtValue v;
    569584ParamEntry *pe=entry(i);
    570585if (pe->fun1)
     
    582597double SimpleAbstractParam::getDouble(int i)
    583598{
    584 static ExtValue v;
     599ExtValue v;
    585600ParamEntry *pe=entry(i);
    586601if (pe->fun1)
     
    598613SString SimpleAbstractParam::getString(int i)
    599614{
    600 static ExtValue v;
     615ExtValue v;
    601616ParamEntry *pe=entry(i);
    602617if (pe->fun1)
     
    614629ExtObject SimpleAbstractParam::getObject(int i)
    615630{
    616 static ExtValue v;
     631ExtValue v;
    617632ParamEntry *pe=entry(i);
    618633if (pe->fun1)
     
    630645ExtValue SimpleAbstractParam::getExtValue(int i)
    631646{
    632 static ExtValue v;
     647ExtValue v;
    633648ParamEntry *pe=entry(i);
    634649if (pe->fun1)
     
    649664int SimpleAbstractParam::setInt(int i,long x)
    650665{
    651 static ExtValue v;
     666ExtValue v;
    652667ParamEntry *pe=entry(i);
    653668if (pe->flags&PARAM_READONLY) return PSET_RONLY;
    654 long xcopy=x; //only needed for helpful printed messages: retain original, requested value of x because it may be changed below
     669long xcopy=x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below
    655670long a=0,b=0;
    656671int result=0;
     
    684699int SimpleAbstractParam::setDouble(int i,double x)
    685700{
    686 static ExtValue v;
     701ExtValue v;
    687702ParamEntry *pe=entry(i);
    688703if (pe->flags&PARAM_READONLY) return PSET_RONLY;
    689 double xcopy=x; //only needed for helpful printed messages: retain original, requested value of x because it may be changed below
     704double xcopy=x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below
    690705double a=0,b=0;
    691706int result=0;
     
    719734int SimpleAbstractParam::setString(int i,const SString& x)
    720735{
    721 static ExtValue v;
    722 static SString vs;
     736ExtValue v;
     737SString vs;
    723738const SString *xx=&x;
    724739ParamEntry *pe=entry(i);
    725740if (pe->flags&PARAM_READONLY) return PSET_RONLY;
    726 SString xcopy=x; //only needed for helpful printed messages: retain original, requested value of x because it may be changed below
     741SString xcopy=x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below
    727742const char* t=pe->type+1;
    728743while(*t) if (*t==' ') break; else t++;
     
    759774int SimpleAbstractParam::setObject(int i,const ExtObject& x)
    760775{
    761 static ExtValue v;
     776ExtValue v;
    762777ParamEntry *pe=entry(i);
    763778if (pe->flags&PARAM_READONLY) return PSET_RONLY;
    764 ExtObject xcopy=x; //only needed for helpful printed messages: retain original, requested value of x because it may be changed below
     779ExtObject xcopy=x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below
    765780if (pe->fun2)
    766781        {
Note: See TracChangeset for help on using the changeset viewer.