Changeset 268


Ignore:
Timestamp:
12/16/14 01:48:21 (7 years ago)
Author:
Maciej Komosinski
Message:

ParamInterface::load warns on unknown fields and skips comments

Location:
cpp/frams/param
Files:
4 edited

Legend:

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

    r197 r268  
    103103        else if (status==BeforeUnknown)
    104104                {
    105                 loadObjectNow(&emptyparam);
     105                FMprintf("MultiParamLoader","go",FMLV_WARN,"Skipping object '%s'",(const char*)lastunknown);
     106                loadObjectNow(&emptyparam,false);
    106107                continue;
    107108                }
     
    141142                        break;
    142143                        }
     144                continue;
    143145                }
    144146        buf=trim(buf);
     
    236238}
    237239
    238 int MultiParamLoader::loadObjectNow(const ExtObject& o)
     240int MultiParamLoader::loadObjectNow(const ExtObject& o,bool warn_unknown_fields)
    239241{
    240242Param tmp_param;
    241243ParamInterface *pi=o.getParamInterface(tmp_param);
    242 pi->load(file);
     244pi->load(file,warn_unknown_fields);
    243245status=AfterObject;
    244246return 0;
  • cpp/frams/param/multiparamload.h

    r197 r268  
    1212
    1313/** This is the general "framsticks-format" file parser for loading multiple objects.
    14     The loader can be configured to recognize multiple object types from object headers
     14        http://www.framsticks.com/common/formatspec.html
     15        The loader can be configured to recognize multiple object types from object headers
    1516    and automatically call ParamInterface::load for the matching class.
    1617   
     
    123124const SString& getError() {return lasterror;}
    124125/** Can be used BeforeObject and BeforeUnknown */
    125 int loadObjectNow(ParamInterface *pi) {return loadObjectNow(ExtObject(pi));}
    126 int loadObjectNow(const ExtObject &o);
     126int loadObjectNow(ParamInterface *pi,bool warn_unknown_fields=true) {return loadObjectNow(ExtObject(pi),warn_unknown_fields);}
     127int loadObjectNow(const ExtObject &o,bool warn_unknown_fields=true);
    127128/** Can be used BeforeObject */
    128129int loadObjectNow() {return loadObjectNow(getObject());}
    129130/** Can be used BeforeObject and BeforeUnknown.
    130131    Object data will not be loaded. */
    131 int skipObject() {return loadObjectNow(&emptyparam);}
     132int skipObject() {return loadObjectNow(&emptyparam,false);}
    132133/** @return 1 if no errors */
    133134int run();
  • cpp/frams/param/param.cpp

    r253 r268  
    371371}
    372372
    373 int ParamInterface::load(VirtFILE* f)
     373int ParamInterface::load(VirtFILE* f,bool warn_unknown_fields)
    374374{
    375375        SString buf;
     
    384384                p0 = t; while ((*p0 == ' ') || (*p0 == '\t')) p0++;
    385385                if (!*p0) break;
     386                if (p0[0]=='#') continue;
    386387                p = strchr(p0, ':'); if (!p) continue;
    387388                p_len = (int)(p - p0);
    388389                loaded = false;
    389                 if (p_len && ((i = findIdn(p0, p_len)) >= 0) && (!(flags(i)&PARAM_DONTLOAD)))
    390                 {
     390                if (p_len && ((i = findIdn(p0, p_len)) >= 0))
     391                {
     392                if (!(flags(i)&PARAM_DONTLOAD))
     393                   {
    391394                        if (p0[p_len + 1] == '~')
    392395                        {
     
    404407                        fields_loaded++;
    405408                        loaded = true;
    406                 }
     409                   }
     410                }
     411                else if (warn_unknown_fields)
     412                        {
     413                        SString name(p0,p_len);
     414                        FMprintf("ParamInterface","load",FMLV_WARN,"Unknown property '%s' while loading object '%s'",(const char*)name,getName());
     415                        }
     416
    407417                if ((!loaded) && (p0[p_len + 1] == '~'))
    408418                { // eat unrecognized multiline field
  • cpp/frams/param/param.h

    r253 r268  
    158158        int save(VirtFILE*, const char* altname = NULL, bool force = 0);
    159159        int saveprop(VirtFILE*, int i, const char* p, bool force = 0);
    160         int load(VirtFILE*);///< @return the number of fields loaded
     160        int load(VirtFILE*,bool warn_unknown_fields=true);///< @return the number of fields loaded
    161161        int load2(const SString &, int &);///< @return the number of fields loaded
    162162
Note: See TracChangeset for help on using the changeset viewer.