Changeset 796 for cpp


Ignore:
Timestamp:
06/06/18 00:45:50 (6 years ago)
Author:
Maciej Komosinski
Message:

Unified error messages and error handling for loadSingleLine and loadMultiLine

Location:
cpp/frams/param
Files:
2 edited

Legend:

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

    r754 r796  
    422422}
    423423
     424void SimpleAbstractParam::messageOnExceedRangeExtValue(int i, int setflags, ExtValue& valuetoset) ///< prints a warning when setflags indicates that allowed param range has been exceeded during set
     425{
     426        if (setflags & (PSET_HITMIN | PSET_HITMAX))
     427        {
     428                SString svaluetoset = valuetoset.getString(); //converts any type to SString
     429                SString actual = get(i);
     430                bool s_type = type(i)[0] == 's';
     431                bool show_length = valuetoset.getType() == TString;
     432                const char* quote = (valuetoset.getType() == TString) ? "\"" : "'";
     433                logPrintf("Param", "set", LOG_WARN, "Setting %s.%s = %s exceeded allowed range (too %s). %s to %s.",
     434                        getName(), id(i),
     435                        ::sstringDelimitAndShorten(svaluetoset, 30, show_length, quote, quote).c_str(),
     436                        (setflags&PSET_HITMAX) ? (s_type ? "long" : "big") : "small", s_type ? "Truncated" : "Adjusted",
     437                        ::sstringDelimitAndShorten(actual, 30, show_length, quote, quote).c_str()
     438                        );
     439        }
     440}
     441
    424442int ParamInterface::load(FileFormat format, VirtFILE* f, LoadOptions *options)
    425443{
     
    526544                                                fileinfo += SString::sprintf(" (line %d)", *options.linenum);
    527545                                }
    528                                 logPrintf("ParamInterface", "load", LOG_WARN, "Multiple '%s.%s' fields found%s", getName(), id(i), fileinfo.c_str());
     546                                logPrintf("ParamInterface", "load", LOG_WARN, "Multiple '%s.%s' properties found%s", getName(), id(i), fileinfo.c_str());
    529547                        }
    530548                        else
     
    564582                {
    565583                        SString name(p0, p_len);
    566                         logPrintf("ParamInterface", "load", LOG_WARN, "Ignored unknown property '%s' while reading object '%s'", name.c_str(), getName());
     584                        logPrintf("ParamInterface", "load", LOG_WARN, "Ignored unknown property '%s.%s'", getName(), name.c_str());
    567585                }
    568586
     
    640658        case 'o':       ret.setObject(getObject(i)); break;
    641659        case 'x':       ret = getExtValue(i); break;
    642         default: logPrintf("ParamInterface", "get", LOG_ERROR, "'%s.%s' is not a field", getName(), id(i));
     660        default: logPrintf("ParamInterface", "get", LOG_ERROR, "'%s.%s' is not a property", getName(), id(i));
    643661        }
    644662}
     
    710728                break;
    711729        case 'x': return setExtValue(i, v);
    712         default: logPrintf("ParamInterface", "set", LOG_ERROR, "'%s.%s' is not a field", getName(), id(i));
     730        default: logPrintf("ParamInterface", "set", LOG_ERROR, "'%s.%s' is not a property", getName(), id(i));
    713731        }
    714732        return 0;
     
    12671285                        {
    12681286                                SString name(t, (int)(equals_sign - t));
    1269                                 logPrintf("Param", "load2", LOG_WARN, "Unknown property '%s' while reading object '%s' (ignored)", name.c_str(), getName());
     1287                                logPrintf("Param", "loadSingleLine", LOG_WARN, "Unknown property '%s.%s' (ignored)", getName(), name.c_str());
    12701288                        }
    12711289                        t = equals_sign + 1; // t=value
     
    12781296                        {
    12791297                        if (id(i))
    1280                                 logPrintf("Param", "load2", LOG_WARN, "Missing property name in '%s' (assuming '%s')", getName(), id(i));
     1298                                logPrintf("Param", "loadSingleLine", LOG_WARN, "Missing property name in '%s' (assuming '%s')", getName(), id(i));
    12811299                        else
    1282                                 logPrintf("Param", "load2", LOG_WARN, "Value after the last property of '%s'", getName());
     1300                                logPrintf("Param", "loadSingleLine", LOG_WARN, "Value after the last property of '%s'", getName());
    12831301                        }
    12841302#endif
     
    13001318                        ret = setFromString(i, value, true);
    13011319                        fields_loaded++;
    1302                         if (ret&(PSET_HITMAX | PSET_HITMIN))
    1303                                 logPrintf("Param", "load2", LOG_WARN, "Adjusted '%s' in '%s' (was too %s)",
    1304                                 id(i), getName(), (ret&PSET_HITMAX) ? "big" : "small");
    13051320                        if (ret&PSET_PARSEFAILED)
    13061321                                parse_failed = true;
  • cpp/frams/param/param.h

    r786 r796  
    252252};
    253253
    254 template<typename T> struct quote_in_messages { constexpr static const char* value = "'"; };
    255 template<> struct quote_in_messages < SString > { constexpr static const char* value = "\""; };
    256 template<typename T> struct length_in_messages { static const bool value = false; };
    257 template<> struct length_in_messages < SString > { static const bool value = true; };
    258 
    259254class SimpleAbstractParam : public virtual ParamInterface
    260255{
     
    300295                if (setflags & (PSET_HITMIN | PSET_HITMAX))
    301296                {
    302                         SString svaluetoset = SString::valueOf(valuetoset); //converts any type to SString
    303                         SString actual = get(i);
    304                         bool s_type = type(i)[0] == 's';
    305                         logPrintf("Param", "set", LOG_WARN, "Setting %s.%s = %s exceeded allowed range (too %s). %s to %s.",
    306                                 getName(), id(i),
    307                                 ::sstringDelimitAndShorten(svaluetoset, 30, length_in_messages<T>::value, quote_in_messages<T>::value, quote_in_messages<T>::value).c_str(),
    308                                 (setflags&PSET_HITMAX) ? (s_type ? "long" : "big") : "small", s_type ? "Truncated" : "Adjusted",
    309                                 ::sstringDelimitAndShorten(actual, 30, length_in_messages<T>::value, quote_in_messages<T>::value, quote_in_messages<T>::value).c_str()
    310                                 );
     297                        ExtValue v(valuetoset);
     298                        messageOnExceedRangeExtValue(i, setflags, v);
    311299                }
    312300        }
     301        void messageOnExceedRangeExtValue(int i, int setflags, ExtValue& valuetoset); ///< used by messageOnExceedRange() internally
    313302
    314303        int setInt(int, paInt);
Note: See TracChangeset for help on using the changeset viewer.