Changeset 393 for cpp/frams


Ignore:
Timestamp:
06/03/15 17:57:46 (10 years ago)
Author:
sz
Message:

f0 parsing corrections and enhancements:

  • f0 genotype becomes invalid if any of its numeric fields can't be parsed
  • ParamInterface::set and ParamInterface::load2 return the error flag if a numeric parsing error occured
  • fixed a bug in load2 (was failing on quoted fields containing a comma)
Location:
cpp/frams
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/model/model.cpp

    r391 r393  
    570570        partparam.select(p);
    571571        pos+=2;
    572         partparam.load2(line,pos);
     572        if (partparam.load2(line,pos) & ParamInterface::LOAD2_PARSE_FAILED) return -1;
    573573        p->o.rotate(p->rot);
    574574        parts+=p;
     
    582582        modelparam.select(this);
    583583        pos+=2;
    584         modelparam.load2(line,pos);
     584        if (modelparam.load2(line,pos) & ParamInterface::LOAD2_PARSE_FAILED) return -1;
    585585        return 0;
    586586        }
     
    592592        pos+=2;
    593593        j->owner=this;
    594         jointparam.load2(line,pos);
     594        if (jointparam.load2(line,pos) & ParamInterface::LOAD2_PARSE_FAILED) return -1;
    595595        if ((j->p1_refno>=0)&&(j->p1_refno<getPartCount())&&
    596596           (j->p2_refno>=0)&&(j->p2_refno<getPartCount()))
     
    620620        neuroparam.select(nu);
    621621        pos+=2;
    622         neuroparam.load2(line,pos);
     622        if (neuroparam.load2(line,pos) & ParamInterface::LOAD2_PARSE_FAILED) return -1;
    623623#ifdef MODEL_V1_COMPATIBLE
    624624        if (nu->neuro_refno>=0) // parent specified...
     
    684684        ncparam.select(&c);
    685685        pos+=2;
    686         ncparam.load2(line,pos);
     686        if (ncparam.load2(line,pos) & ParamInterface::LOAD2_PARSE_FAILED) return -1;
    687687        if ((c.n1_refno>=0)&&(c.n1_refno<getNeuroCount())&&(c.n2_refno>=0)&&(c.n2_refno<getNeuroCount()))
    688688                {
     
    706706        neuroitemparam.select(nu);
    707707        pos+=3;
    708         neuroitemparam.load2(line,pos);
     708        if (neuroitemparam.load2(line,pos) & ParamInterface::LOAD2_PARSE_FAILED) return -1;
    709709        // illegal parent?
    710710        if ((nu->neuro_refno<0)||(nu->neuro_refno>=old_getNeuroCount()))
  • cpp/frams/param/param.cpp

    r375 r393  
    529529                paInt mn, mx, def;
    530530                if (getMinMax(i, mn, mx, def) >= 3)
    531                         return setInt(i, def);
     531                        return setInt(i, def) | PSET_PARSEFAILED;
    532532                else
    533                         return setInt(i, (paInt)0);
     533                        return setInt(i, (paInt)0) | PSET_PARSEFAILED;
    534534        }
    535535        else
     
    544544                double mn, mx, def;
    545545                if (getMinMax(i, mn, mx, def) >= 3)
    546                         return setDouble(i, def);
     546                        return setDouble(i, def) | PSET_PARSEFAILED;
    547547                else
    548                         return setDouble(i, (double)0);
     548                        return setDouble(i, (double)0) | PSET_PARSEFAILED;
    549549        }
    550550        else
     
    10131013        const char *value, *valstop;
    10141014        SString tmpvalue;
     1015        bool parse_failed=false;
    10151016        if (poz >= s.len()) return fields_loaded;
    10161017        t = s.c_str() + poz;
     
    10381039                        {
    10391040                                field_end = strchrlimit(quote2 + 1, ',', end);
    1040                                 if (!field_end) next_field = field_end = end;
     1041                                if (!field_end) field_end = end;
     1042                                next_field = field_end;
    10411043                        }
    10421044                        equals_sign = strchrlimit(t, '=', quote);
     
    10941096                                logPrintf("Param", "load2", LOG_WARN, "Adjusted '%s' in '%s' (was too %s)",
    10951097                                id(i), getName(), (ret&PSET_HITMAX) ? "big" : "small");
     1098                        if (ret&PSET_PARSEFAILED)
     1099                                parse_failed=true;
    10961100                        *(char*)valstop = remember;
    10971101                }
     
    11041108#endif
    11051109        }
    1106         return fields_loaded;
     1110        return fields_loaded | (parse_failed ? LOAD2_PARSE_FAILED : 0);
    11071111}
    11081112
  • cpp/frams/param/param.h

    r382 r393  
    5050#define PSET_HITMAX     8
    5151
     52#define PSET_NOPROPERTY 16
     53
     54#define PSET_PARSEFAILED        32
     55
    5256// useful combination: need to get and display the value so that a user knows that the value they tried to set has been rejected or changed
    53 #define PSET_WARN (PSET_RONLY | PSET_HITMIN | PSET_HITMAX)
    54 
    55 #define PSET_NOPROPERTY 16
     57#define PSET_WARN (PSET_RONLY | PSET_HITMIN | PSET_HITMAX | PSET_PARSEFAILED)
     58
    5659
    5760struct ParamEntry;
     
    162165        int saveprop(VirtFILE*, int i, const char* p, bool force = 0);
    163166        int load(VirtFILE*, bool warn_unknown_fields = true, bool *abortable = NULL, int *linenum = NULL);///< @return the number of fields loaded
    164         int load2(const SString &, int &);///< @return the number of fields loaded
     167        int load2(const SString &, int &);///< @return the number of fields loaded (or'ed with LOAD2_PARSE_FAILED if a parsing error was detected)
    165168
    166169        static const char* SERIALIZATION_PREFIX;
     170        static const int LOAD2_PARSE_FAILED=(1<<30); ///< this bit is set in return value from load2 if a parse error was detected while loading. usage: if (load2(...) & LOAD2_PARSE_FAILED) ...
     171        static const int LOAD2_IGNORE_PARSE_FAILED=(~LOAD2_PARSE_FAILED); ///< bitmask to be used if the parsing error is to be ignored. usage: int number_of_loaded_fields=load2(...) & LOAD2_IGNORE_PARSE_FAILED;
    167172
    168173#ifdef DEBUG
Note: See TracChangeset for help on using the changeset viewer.