Ignore:
Timestamp:
03/01/14 22:25:20 (10 years ago)
Author:
sz
Message:

reformatting, english translation

File:
1 edited

Legend:

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

    r144 r154  
    3333#define PARAM_DEPRECATED        8192
    3434
    35 // wynik z param::set() to kombinacja bitow:
    36 
     35// the result of param::set() is a combination of bits:
     36
     37// read-only: cannot modify
    3738#define PSET_RONLY      1
    38 // oznacza,ze nie mozna zmienic
    39 
     39
     40// value has been modified
    4041#define PSET_CHANGED    2
    41 // zaawansowane: wartosc zostala zmieniona
    42 
     42
     43//value has been adjusted because it tried to exceed min or max
    4344#define PSET_HITMIN     4
    4445#define PSET_HITMAX     8
    45 // wartosc zostala dopasowana do min lub max
    46 
     46
     47// 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
    4748#define PSET_WARN (PSET_RONLY | PSET_HITMIN | PSET_HITMAX)
    48 // pozyteczna kombinacja - oznacza, ze nalezy pobrac i wyswietlic
    49 // wartosc, zeby uzytkownik wiedzial, ze jego propozycja jest odrzucona
    5049
    5150#define PSET_NOPROPERTY 16
     
    5756{
    5857public:
    59 virtual int getGroupCount()=0; ///< @return number of property groups
    60 virtual int getPropCount()=0; ///< @return number of properties
    61 
    62 virtual const char* getName()=0;
    63 virtual const char* getDescription() {return 0;}
    64 virtual ParamEntry *getParamTab() const {return NULL;}
    65 
    66 int findId(const char *n);      ///< find id number for internal name
    67 int findIdn(const char *naz,int n);
    68 
    69 virtual const char *id(int i)=0;        ///< get internal name
    70 virtual const char *name(int i)=0;      ///< get human readable name
    71 
    72 /** get type description.
    73     first character defines basic datatype:
    74     - d = integer
    75     - f = floating point
    76     - s = string
    77     - o = ExtObject
    78     - x = ExtValue (universal datatype)
    79  */
    80 virtual const char *type(int i)=0;     
    81 
    82 virtual const char *help(int i)=0;      ///< get long description (tooltip)
    83 
    84 virtual int flags(int i)=0;             ///< get flags
    85 
    86 virtual int group(int i)=0;             ///< get group id for a property
    87 virtual const char *grname(int gi)=0;   ///< get group name
    88 virtual int grmember(int gi,int n)=0;   ///< get property id for n'th member of group "gi"
    89 
    90 virtual void call(int i,ExtValue* args,ExtValue *ret)=0;
    91 
    92 void get(int,ExtValue &retval); ///< most universal get, can be used for every datatype
    93 
    94 virtual SString getString(int)=0;       ///< get string value, you can only use this for "s" type property
    95 virtual long getInt(int)=0;     ///< get long value, you can only use this for "d" type property
    96 virtual double getDouble(int)=0;        ///< get double value, you can only use this for "f" type property
    97 virtual ExtObject getObject(int)=0;     ///< get object reference, you can only use this for "o" type property
    98 virtual ExtValue getExtValue(int)=0;    ///< get extvalue object, you can only use this for "x" type property
    99 
    100 SString get(int);               ///< old style get, can convert long or double to string
    101 SString getText(int);           ///< like getString, returns enumeration label for subtype "d 0 n ~enum1~enum2...
    102 
    103 SString getStringById(const char*prop);  ///< get string value, you can only use this for "s" type property
    104 long getIntById(const char* prop);    ///< get long value, you can only use this for "d" type property
    105 double getDoubleById(const char* prop);///< get double value, you can only use this for "f" type property
    106 ExtObject getObjectById(const char* prop);///< get object reference, you can only use this for "o" type property
    107 ExtValue getExtValueById(const char* prop);///< get extvalue object, you can only use this for "x" type property
    108 ExtValue getById(const char* prop);
    109 
    110 int setInt(int i,const char* str);
    111 int setDouble(int i,const char* str);
    112 virtual int setInt(int,long)=0;         ///< set long value, you can only use this for "d" type prop
    113 virtual int setDouble(int,double)=0;    ///< set double value, you can only use this for "f" type prop
    114 virtual int setString(int,const SString &)=0;   ///< set string value, you can only use this for "s" type prop
    115 virtual int setObject(int,const ExtObject &)=0;         ///< set object reference, you can only use this for "o" type prop
    116 virtual int setExtValue(int,const ExtValue &)=0;        ///< 4 in 1
    117 
    118 int set(int,const ExtValue &);///< most universal set, can be used for every datatype
    119 
    120 int set(int,const char*);               ///< oldstyle set, can convert string to long or double
    121 
    122 int setIntById(const char* prop,long);///< set long value, you can only use this for "d" type prop
    123 int setDoubleById(const char* prop,double);///< set double value, you can only use this for "f" type prop
    124 int setStringById(const char* prop,const SString &);///< set string value, you can only use this for "s" type prop
    125 int setObjectById(const char* prop,const ExtObject &);///< set object reference, you can only use this for "o" type prop
    126 int setExtValueById(const char* prop,const ExtValue &); ///< for ExtValue types only
    127 int setById(const char* prop,const ExtValue &);///< can be used for all property types
    128 
    129 /** get valid minimum, maximum and default value for property 'prop'
    130     @return 0 if min/max/def information is not available */
    131 int getMinMax(int prop,long& minumum,long& maximum,long& def);
    132 /** get valid minimum, maximum and default value for property 'prop'
    133     @return 0 if min/max/def information is not available */
    134 int getMinMax(int prop,double& minumum,double& maximum,double& def);
    135 
    136 virtual void setDefault(bool numericonly=false);
    137 virtual void setDefault(int i,bool numericonly=false);
    138 void setMin();
    139 void setMax();
    140 void setMin(int i);
    141 void setMax(int i);
    142 
    143 /** copy all property values from other ParamInterface object */
    144 void copyFrom(ParamInterface *src);
    145 
    146 /** copy all property values from compatible ParamInterface object.
    147     this method is more efficient than copyFrom,
    148     but can be used only if the other object has the same properties sequence, eg:
    149     - any two Param objects having common paramtab
    150     - any ParamInterface object and the Param with paramtab constructed by ParamObject::makeParamTab
    151  */
    152 void quickCopyFrom(ParamInterface *src);
    153 
    154 int save(VirtFILE*,const char* altname=NULL,bool force=0);
    155 int saveprop(VirtFILE*,int i,const char* p,bool force=0);
    156 int load(VirtFILE*);///< @return number of fields loaded
    157 int load2(const SString &,int &);///< @return number of fields loaded
    158 
    159 static const char* SERIALIZATION_PREFIX;
     58        virtual int getGroupCount() = 0; ///< @return the number of property groups
     59        virtual int getPropCount() = 0; ///< @return the number of properties
     60
     61        virtual const char* getName() = 0;
     62        virtual const char* getDescription() { return 0; }
     63        virtual ParamEntry *getParamTab() const { return NULL; }
     64
     65        int findId(const char *n);      ///< find id number for internal name
     66        int findIdn(const char *naz, int n);
     67
     68        virtual const char *id(int i) = 0;      ///< get internal name
     69        virtual const char *name(int i) = 0;    ///< get the human-readable name
     70
     71        /** get type description.
     72                first character defines basic datatype:
     73                - d = integer
     74                - f = floating point
     75                - s = string
     76                - o = ExtObject
     77                - x = ExtValue (universal datatype)
     78                */
     79        virtual const char *type(int i) = 0;
     80
     81        virtual const char *help(int i) = 0;    ///< get long description (tooltip)
     82
     83        virtual int flags(int i) = 0;           ///< get flags
     84
     85        virtual int group(int i) = 0;           ///< get group id for a property
     86        virtual const char *grname(int gi) = 0; ///< get group name
     87        virtual int grmember(int gi, int n) = 0;        ///< get property id for n'th member of group "gi"
     88
     89        virtual void call(int i, ExtValue* args, ExtValue *ret) = 0;
     90
     91        void get(int, ExtValue &retval);        ///< most universal get, can be used for every datatype
     92
     93        virtual SString getString(int) = 0;     ///< get string value, you can only use this for "s" type property
     94        virtual long getInt(int) = 0;   ///< get long value, you can only use this for "d" type property
     95        virtual double getDouble(int) = 0;      ///< get double value, you can only use this for "f" type property
     96        virtual ExtObject getObject(int) = 0;   ///< get object reference, you can only use this for "o" type property
     97        virtual ExtValue getExtValue(int) = 0;  ///< get extvalue object, you can only use this for "x" type property
     98
     99        SString get(int);               ///< old style get, can convert long or double to string
     100        SString getText(int);           ///< like getString, returns enumeration label for subtype "d 0 n ~enum1~enum2...
     101
     102        SString getStringById(const char*prop);  ///< get string value, you can only use this for "s" type property
     103        long getIntById(const char* prop);    ///< get long value, you can only use this for "d" type property
     104        double getDoubleById(const char* prop);///< get double value, you can only use this for "f" type property
     105        ExtObject getObjectById(const char* prop);///< get object reference, you can only use this for "o" type property
     106        ExtValue getExtValueById(const char* prop);///< get extvalue object, you can only use this for "x" type property
     107        ExtValue getById(const char* prop);
     108
     109        int setInt(int i, const char* str);
     110        int setDouble(int i, const char* str);
     111        virtual int setInt(int, long) = 0;              ///< set long value, you can only use this for "d" type prop
     112        virtual int setDouble(int, double) = 0; ///< set double value, you can only use this for "f" type prop
     113        virtual int setString(int, const SString &) = 0;        ///< set string value, you can only use this for "s" type prop
     114        virtual int setObject(int, const ExtObject &) = 0;      ///< set object reference, you can only use this for "o" type prop
     115        virtual int setExtValue(int, const ExtValue &) = 0;     ///< 4 in 1
     116
     117        int set(int, const ExtValue &);///< most universal set, can be used for every datatype
     118
     119        int set(int, const char*);              ///< oldstyle set, can convert string to long or double
     120
     121        int setIntById(const char* prop, long);///< set long value, you can only use this for "d" type prop
     122        int setDoubleById(const char* prop, double);///< set double value, you can only use this for "f" type prop
     123        int setStringById(const char* prop, const SString &);///< set string value, you can only use this for "s" type prop
     124        int setObjectById(const char* prop, const ExtObject &);///< set object reference, you can only use this for "o" type prop
     125        int setExtValueById(const char* prop, const ExtValue &); ///< for ExtValue types only
     126        int setById(const char* prop, const ExtValue &);///< can be used for all property types
     127
     128        /** get valid minimum, maximum and default value for property 'prop'
     129                @return 0 if min/max/def information is not available */
     130        int getMinMax(int prop, long& minumum, long& maximum, long& def);
     131        /** get valid minimum, maximum and default value for property 'prop'
     132                @return 0 if min/max/def information is not available */
     133        int getMinMax(int prop, double& minumum, double& maximum, double& def);
     134
     135        virtual void setDefault(bool numericonly = false);
     136        virtual void setDefault(int i, bool numericonly = false);
     137        void setMin();
     138        void setMax();
     139        void setMin(int i);
     140        void setMax(int i);
     141
     142        /** copy all property values from other ParamInterface object */
     143        void copyFrom(ParamInterface *src);
     144
     145        /** Copy all property values from compatible ParamInterface object.
     146                This method is more efficient than copyFrom,
     147                but can be used only if the other object has the same properties sequence, e.g.:
     148                - any two Param objects having common paramtab
     149                - any ParamInterface object and the Param with paramtab constructed by ParamObject::makeParamTab
     150                */
     151        void quickCopyFrom(ParamInterface *src);
     152
     153        int save(VirtFILE*, const char* altname = NULL, bool force = 0);
     154        int saveprop(VirtFILE*, int i, const char* p, bool force = 0);
     155        int load(VirtFILE*);///< @return the number of fields loaded
     156        int load2(const SString &, int &);///< @return the number of fields loaded
     157
     158        static const char* SERIALIZATION_PREFIX;
    160159};
    161160
     
    193192struct ParamEntry
    194193{
    195 const char *id;
    196 short group,flags;
    197 const char *name,*type;
    198 long offset;
    199 void *fun1; ///< procedure or get
    200 void *fun2; ///< set
    201 const char *help;
    202 };
    203 
    204 struct ParamEntryConstructor: public ParamEntry
     194        const char *id;
     195        short group, flags;
     196        const char *name, *type;
     197        long offset;
     198        void *fun1; ///< procedure or get
     199        void *fun2; ///< set
     200        const char *help;
     201};
     202
     203struct ParamEntryConstructor : public ParamEntry
    205204{
    206205public:
    207 ParamEntryConstructor(const char *_id,short _group=0,short _flags=0,const char *_name=0,const char *_type=0,long _offset=0,void *_fun1=0, void *_fun2=0, const char *_help=0)
    208 {id=_id;group=_group;flags=_flags;name=_name;type=_type;offset=_offset;fun1=_fun1;fun2=_fun2;help=_help;}
    209 };
    210 
    211 class SimpleAbstractParam: public virtual ParamInterface
     206        ParamEntryConstructor(const char *_id, short _group = 0, short _flags = 0, const char *_name = 0, const char *_type = 0, long _offset = 0, void *_fun1 = 0, void *_fun2 = 0, const char *_help = 0)
     207        {
     208                id = _id; group = _group; flags = _flags; name = _name; type = _type; offset = _offset; fun1 = _fun1; fun2 = _fun2; help = _help;
     209        }
     210};
     211
     212class SimpleAbstractParam : public virtual ParamInterface
    212213{
    213214protected:
    214 virtual void *getTarget(int i);
    215 virtual ParamEntry *entry(int i)=0;
    216 const char* myname;
    217 bool dontcheckchanges;
     215        virtual void *getTarget(int i);
     216        virtual ParamEntry *entry(int i) = 0;
     217        const char* myname;
     218        bool dontcheckchanges;
    218219
    219220public:
    220 void *object;
    221 
    222 const char* getName() {return myname;}
    223 void setName(const char* n) {myname=n;}
    224 
    225 /**
    226         @param t ParamEntry table
    227         @param o controlled object
    228         @param n Param's name
    229 */
    230 SimpleAbstractParam(void* o=0,const char*n=0):myname(n),dontcheckchanges(0),object(o) {}
    231 void setDontCheckChanges(bool x) {dontcheckchanges=x;}
    232 
    233 void select(void *o) {object=o;}
    234 void* getSelected() {return object;}
    235 
    236 const char *id(int i) {return (i>=getPropCount())?0:entry(i)->id;}
    237 const char *name(int i) {return entry(i)->name;}
    238 const char *type(int i) {return entry(i)->type;}
    239 const char *help(int i) {return entry(i)->help;}
    240 int flags(int i) {return entry(i)->flags;}
    241 int group(int i) {return entry(i)->group;}
    242 void call(int i,ExtValue* args,ExtValue *ret);
    243 
    244 SString getString(int);
    245 long getInt(int);
    246 double getDouble(int);
    247 ExtObject getObject(int);
    248 ExtValue getExtValue(int);
    249 
    250 template<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
    251 {
    252         if (setflags & (PSET_HITMIN | PSET_HITMAX))
    253     {
    254         SString svaluetoset=SString::valueOf(valuetoset); //converts any type to SString
    255         SString actual=get(i);
    256                 FMprintf("Param","set",FMLV_WARN,"Setting '%s.%s = %s' exceeded allowed range (too %s). Adjusted to %s.",
    257                                  getName(),id(i),(const char*)svaluetoset,(setflags&PSET_HITMAX)?"big":"small",(const char*)actual);
    258     }
    259 }                         
    260 
    261 int setInt(int,long);
    262 int setDouble(int,double);
    263 int setString(int,const SString &);
    264 int setObject(int,const ExtObject &);
    265 int setExtValue(int,const ExtValue &);
    266 
    267 int isequal(int i,void* defdata);
    268 void save2(SString&,void *defdata,bool addcr=true,bool all_names=true);
    269 
    270 virtual void setDefault(bool numericonly=false);
    271 virtual void setDefault(int i,bool numericonly=false);
    272 };
    273 
    274 class Param: public SimpleAbstractParam
     221        void *object;
     222
     223        const char* getName() { return myname; }
     224        void setName(const char* n) { myname = n; }
     225
     226        /**
     227                @param t ParamEntry table
     228                @param o controlled object
     229                @param n Param's name
     230                */
     231        SimpleAbstractParam(void* o = 0, const char*n = 0) :myname(n), dontcheckchanges(0), object(o) {}
     232        void setDontCheckChanges(bool x) { dontcheckchanges = x; }
     233
     234        void select(void *o) { object = o; }
     235        void* getSelected() { return object; }
     236
     237        const char *id(int i) { return (i >= getPropCount()) ? 0 : entry(i)->id; }
     238        const char *name(int i) { return entry(i)->name; }
     239        const char *type(int i) { return entry(i)->type; }
     240        const char *help(int i) { return entry(i)->help; }
     241        int flags(int i) { return entry(i)->flags; }
     242        int group(int i) { return entry(i)->group; }
     243        void call(int i, ExtValue* args, ExtValue *ret);
     244
     245        SString getString(int);
     246        long getInt(int);
     247        double getDouble(int);
     248        ExtObject getObject(int);
     249        ExtValue getExtValue(int);
     250
     251        template<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
     252        {
     253                if (setflags & (PSET_HITMIN | PSET_HITMAX))
     254                {
     255                        SString svaluetoset = SString::valueOf(valuetoset); //converts any type to SString
     256                        SString actual = get(i);
     257                        FMprintf("Param", "set", FMLV_WARN, "Setting '%s.%s = %s' exceeded allowed range (too %s). Adjusted to %s.",
     258                                getName(), id(i), (const char*)svaluetoset, (setflags&PSET_HITMAX) ? "big" : "small", (const char*)actual);
     259                }
     260        }
     261
     262        int setInt(int, long);
     263        int setDouble(int, double);
     264        int setString(int, const SString &);
     265        int setObject(int, const ExtObject &);
     266        int setExtValue(int, const ExtValue &);
     267
     268        int isequal(int i, void* defdata);
     269        void save2(SString&, void *defdata, bool addcr = true, bool all_names = true);
     270
     271        virtual void setDefault(bool numericonly = false);
     272        virtual void setDefault(int i, bool numericonly = false);
     273};
     274
     275class Param : public SimpleAbstractParam
    275276{
    276277protected:
    277 ParamEntry *entry(int i) {return tab+tab[0].group+i;}
     278        ParamEntry *entry(int i) { return tab + tab[0].group + i; }
    278279public:
    279 ParamEntry *tab;
    280 /**
    281         @param t ParamEntry table
    282         @param o controlled object
    283         @param n Param's name
    284 */
    285 
    286 Param(ParamEntry *t=0,void* o=0,const char*n=0):SimpleAbstractParam(o,n),tab(t)
    287 {if (!n&&tab) myname=tab[0].name;}
    288 
    289 Param(const Param& p):SimpleAbstractParam(p.object,p.myname),tab(p.tab) {}
    290 void operator=(const Param&p) {object=p.object; myname=p.myname; tab=p.tab;}
    291 
    292 const char* getDescription() {return tab[0].type;}
    293 
    294 int getGroupCount() {return tab[0].group;}
    295 int getPropCount() {return tab[0].flags;}
    296 const char *grname(int i) {return (i<getGroupCount())?tab[i].id:0;}
    297 int grmember(int,int);
    298 void setParamTab(ParamEntry *t,int dontupdatename=0) {tab=t; if ((!dontupdatename)&&tab) myname=tab[0].name; }
    299 ParamEntry *getParamTab() const {return tab;}
     280        ParamEntry *tab;
     281        /**
     282                @param t ParamEntry table
     283                @param o controlled object
     284                @param n Param's name
     285                */
     286
     287        Param(ParamEntry *t = 0, void* o = 0, const char*n = 0) :SimpleAbstractParam(o, n), tab(t)
     288        {
     289                if (!n&&tab) myname = tab[0].name;
     290        }
     291
     292        Param(const Param& p) :SimpleAbstractParam(p.object, p.myname), tab(p.tab) {}
     293        void operator=(const Param&p) { object = p.object; myname = p.myname; tab = p.tab; }
     294
     295        const char* getDescription() { return tab[0].type; }
     296
     297        int getGroupCount() { return tab[0].group; }
     298        int getPropCount() { return tab[0].flags; }
     299        const char *grname(int i) { return (i < getGroupCount()) ? tab[i].id : 0; }
     300        int grmember(int, int);
     301        void setParamTab(ParamEntry *t, int dontupdatename = 0) { tab = t; if ((!dontupdatename) && tab) myname = tab[0].name; }
     302        ParamEntry *getParamTab() const { return tab; }
    300303};
    301304
Note: See TracChangeset for help on using the changeset viewer.