Changeset 93 for cpp/gdk/param.h


Ignore:
Timestamp:
07/02/13 22:37:44 (11 years ago)
Author:
Maciej Komosinski
Message:

every param.set(value) produces a helpful warning when the "value" exceeds allowed range for this param, e.g.

World.wrldtyp=5;

[WARN] Param::set - Setting 'World.wrldtyp = 5' exceeded allowed range (too big). Adjusted to 2.

World.wrldtyp=-5;

[WARN] Param::set - Setting 'World.wrldtyp = -5' exceeded allowed range (too small). Adjusted to 0.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/gdk/param.h

    r81 r93  
    1111#include "statrick.h"
    1212#include "virtfile.h"
     13#include "framsg.h"
    1314
    1415class ExtValue;
     
    118119int setStringById(const char* prop,const SString &);///< set string value, you can only use this for "s" type prop
    119120int setObjectById(const char* prop,const ExtObject &);///< set object reference, you can only use this for "o" type prop
    120 
    121 int setExtValueById(const char* prop,const ExtValue &); ///< 4 in 1
     121int setExtValueById(const char* prop,const ExtValue &); ///< for ExtValue types only
     122int setById(const char* prop,const ExtValue &);///< can be used for all property types
    122123
    123124/** get valid minimum, maximum and default value for property 'prop'
     
    239240ExtValue getExtValue(int);
    240241
     242template<typename T> void messageOnExceedRange(int i,int setflags, T valuetoset) ///< prints a warning when setflags indicates that allowed param range has been exceeded during set
     243{
     244        if (setflags & (PSET_HITMIN | PSET_HITMAX))
     245    {
     246        SString svaluetoset=SString::valueOf(valuetoset); //converts any type to SString
     247        SString actual=get(i);
     248                FMprintf("Param","set",FMLV_WARN,"Setting '%s.%s = %s' exceeded allowed range (too %s). Adjusted to %s.",
     249                                 getName(),id(i),(const char*)svaluetoset,(setflags&PSET_HITMAX)?"big":"small",(const char*)actual);
     250    }
     251}                         
     252
    241253int setInt(int,long);
    242254int setDouble(int,double);
Note: See TracChangeset for help on using the changeset viewer.