Changeset 253 for cpp/frams/param


Ignore:
Timestamp:
11/18/14 17:01:07 (9 years ago)
Author:
Maciej Komosinski
Message:

String-type properties can now have a default value stored in their definition, just like numerics

Location:
cpp/frams/param
Files:
2 edited

Legend:

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

    r247 r253  
    8686}
    8787
     88int ParamInterface::getMinMax(int prop, int& minumum, int& maximum, SString& def)
     89{
     90        const char* t = type(prop) + 1;
     91        while (*t) if (*t == ' ') break; else t++;
     92        int ret=sscanf(t, "%d %d", &minumum, &maximum);
     93        def=SString::empty();
     94        if (ret==2)
     95                {
     96                while (*t==' ') t++;
     97                for(int skip_fields=2;skip_fields>0;skip_fields--)
     98                        {
     99                        while (*t) if (*t == ' ') break; else t++;
     100                        while (*t==' ') t++;
     101                        }
     102                if (*t)
     103                        {
     104                        const char* til=strchr(t,'~');
     105                        if (!til)
     106                                def=SString(t);
     107                        else
     108                                {
     109                                while ((til>t)&&(til[-1]==' ')) til--;
     110                                def=SString(t,til-t);
     111                                }
     112                        }
     113                return 3;
     114                }
     115        else
     116                return ret;
     117}
     118
    88119void ParamInterface::setDefault(bool numericonly)
    89120{
     
    125156                setInt(i, c);
    126157        }
     158                break;
     159        case 's': if (!numericonly)
     160        {
     161                int a,b; SString c;
     162                getMinMax(i,a,b,c);
     163                setString(i,c);
     164        }
    127165                break;
    128166        default: if (!numericonly) set(i, "");
     
    770808        const char* t = pe->type + 1;
    771809        while (*t) if (*t == ' ') break; else t++;
    772         paInt a = 0, b = 0;
     810        int a = 0, b = 0;
    773811        int result = 0;
    774         if (sscanf(t, PA_INT_SCANF " " PA_INT_SCANF, &a, &b) == 2)
     812        if (sscanf(t, "%d %d", &a, &b) == 2) //using getMinMax would also get default value, which is not needed here
    775813        {
    776814                if ((x.len() > b) && (b > 0))
  • cpp/frams/param/param.h

    r247 r253  
    136136                @return 0 if min/max/def information is not available */
    137137        int getMinMax(int prop, double& minumum, double& maximum, double& def);
     138        int getMinMax(int prop, int& minumum, int& maximum, SString& def);
    138139
    139140        virtual void setDefault(bool numericonly = false);
     
    228229protected:
    229230        virtual void *getTarget(int i);
    230         virtual ParamEntry *entry(int i) = 0;
    231231        const char* myname;
    232232        bool dontcheckchanges;
     
    249249        void* getSelected() { return object; }
    250250
     251        virtual ParamEntry *entry(int i) = 0;
    251252        const char *id(int i) { return (i >= getPropCount()) ? 0 : entry(i)->id; }
    252253        const char *name(int i) { return entry(i)->name; }
Note: See TracChangeset for help on using the changeset viewer.