Changeset 81 for cpp/gdk/param.cpp


Ignore:
Timestamp:
02/08/13 03:29:17 (11 years ago)
Author:
Maciej Komosinski
Message:

improved parsing of properties (e.g. in f0 genotypes)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/gdk/param.cpp

    r66 r81  
    283283}
    284284
    285 void SimpleAbstractParam::save2(SString& f,void *defdata,int addcr)
     285void SimpleAbstractParam::save2(SString& f,void *defdata,bool addcr,bool all_names)
    286286{ // defdata!=NULL -> nie zapisuje wartosci domyslnych
    287287const char *p;
     
    303303#ifndef SAVE_ALL_NAMES
    304304#ifdef SAVE_SELECTED_NAMES
    305                 if (needlabel || !(fl & PARAM_CANOMITNAME))
     305                if (needlabel || all_names || !(fl & PARAM_CANOMITNAME))
    306306#else
    307307                if (needlabel)
     
    312312                        { // string - special case
    313313                        SString str=getString(i);
    314                         if (strContainsOneOf(str,", \\\n\r\t"))
     314                        if (strContainsOneOf(str,", \\\n\r\t\""))
    315315                                {
    316316                                t+="\"";
     
    439439}
    440440
     441static bool stringIsNumeric(const char* str)
     442{//   /-?.?[0-9]+/
     443if (!str) return false;
     444if (*str=='-') str++;
     445if (*str=='.') str++;
     446return isdigit(*str);
     447}
     448
     449int ParamInterface::setInt(int i,const char* str)
     450{
     451if (!stringIsNumeric(str))
     452        {
     453        long a,b,c;
     454        if (getMinMax(i,a,b,c)>=3)
     455                return setInt(i,c);
     456        else
     457                return setInt(i,(long)0);
     458        }
     459else
     460        return setInt(i,atol(str));
     461}
     462
     463int ParamInterface::setDouble(int i,const char* str)
     464{
     465if (!stringIsNumeric(str))
     466        {
     467        double a,b,c;
     468        if (getMinMax(i,a,b,c)>=3)
     469                return setDouble(i,c);
     470        else
     471                return setDouble(i,(double)0);
     472        }
     473else
     474        return setDouble(i,atof(str));
     475}
     476
    441477int ParamInterface::set(int i,const ExtValue &v)
    442478{
    443479switch(type(i)[0])
    444480        {
    445         case 'd': return setInt(i,v.getInt());
    446         case 'f': return setDouble(i,v.getDouble());
     481        case 'd': if ((v.type==TInt)||(v.type==TDouble)) return setInt(i,v.getInt()); else return setInt(i,(const char*)v.getString());
     482        case 'f': if ((v.type==TInt)||(v.type==TDouble)) return setDouble(i,v.getDouble()); else return setDouble(i,(const char*)v.getString());
    447483        case 's': { SString t=v.getString(); return setString(i,t); }
    448484        case 'o': return setObject(i,v.getObject());
     
    457493switch(type(i)[0])
    458494        {
    459         case 'd': return setInt(i,atol(v));
    460         case 'f': return setDouble(i,atof(v));
     495        case 'd': return setInt(i,v);
     496        case 'f': return setDouble(i,v);
    461497        case 's': { SString t(v); return setString(i,t); }
    462498        case 'x':
Note: See TracChangeset for help on using the changeset viewer.