Changeset 329 for cpp


Ignore:
Timestamp:
02/06/15 05:58:34 (9 years ago)
Author:
Maciej Komosinski
Message:

More examples of Param loader

Location:
cpp/frams/_demos
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/_demos/loader_test_param.cpp

    r323 r329  
    1313 After loading, objects are printed ("saved") to standard output.
    1414 Additional information and messages are printed to standard error.
    15  You can redirect both streams if needed.
    16 
     15 You can redirect one or both streams if needed.
     16 
     17 A sample input file for this program is "loader_test_param.in",
     18 so you can run this program from the "cpp" directory as
     19 ./loader_test_param  frams/_demos/loader_test_param.in
     20 
    1721 \include loader_test_param.cpp
    1822 */
     
    2226public:
    2327        SString text, longtext, deftext;
    24         int i1, i2, i3;
    25         float f1, f2, f3;
    26         ExtValue x;
    27         int notchanged,notloaded,notsaved;
     28        paInt i1, i2, i3, i4;
     29        double f1, f2, f3, f4;
     30        ExtValue x1, x2;
     31        int notchanged, notloaded, notsaved;
    2832};
    2933
     
    3135ParamEntry data_paramtab[] =
    3236{
    33         { "Data", 1, 12, "data", },
     37        { "Data", 1, 16, "data", },
    3438        { "text", 0, 0, "Text", "s 0 10", FIELD(text), }, // 10 = length limit
    3539        { "longtext", 0, 0, "Long text", "s 1", FIELD(longtext), }, // 1 = multiline, 0 = unlimited
     
    3842        { "i2", 0, 0, "Integer 2", "d -5 5 1", FIELD(i2), }, // [-5..5] integer, default=1
    3943        { "i3", 0, 0, "Integer 3", "d -1 3 0 ~Minus~Zero~One~Two~Three", FIELD(i3), }, // [0..3] + text labels (Param::getText())
     44        { "i4", 0, 0, "Integer 4", "d 0 10 15", FIELD(i4), }, // invalid default
    4045        { "f1", 0, 0, "Float 1", "d", FIELD(f1), },          // unrestricted float
    4146        { "f2", 0, 0, "Float 2", "f -100 100 -100", FIELD(f2), }, // [-100..100] float, default=-100
    42         { "x", 0, 0, "Untyped", "x", FIELD(x), }, // any type (class ExtValue)
     47        { "f3", 0, 0, "Float 3", "f -10 10", FIELD(f3), }, // [-10..10] float
     48        { "f4", 0, 0, "Float 4", "f 1 -1 404", FIELD(f4), }, // unrestricted float (invalid min>max), default=44
     49        { "x1", 0, 0, "Untyped 1", "x", FIELD(x1), }, // any type (class ExtValue)
     50        { "x2", 0, 0, "Untyped 2", "x", FIELD(x2), }, // any type (class ExtValue)
    4351        { "notchanged", 0, PARAM_READONLY, "Read only field", "d", FIELD(notchanged), }, // neither load() nor setDefault() can change this
    4452        { "notloaded", 0, PARAM_DONTLOAD, "Unloadable field", "d", FIELD(notloaded), }, // load() does not change this
     
    6573        Param param(data_paramtab, &data);
    6674
    67         data.notchanged=100;
    68         data.notloaded=200;
     75        data.notchanged = 100;
     76        data.notloaded = 200;
    6977
    7078        loader.addObject(&param);
     
    9199                        for (int i = 0; i < param.getPropCount(); i++)
    92100                                fprintf(stderr, "%s=%s\n", param.id(i), (const char*)param.getText(i));
    93                         fprintf(stderr, "type of 'x' is: %s\n", (const char*)data.x.typeDescription());
     101                        fprintf(stderr, "type of 'x1' is: %s\n", (const char*)data.x1.typeDescription());
     102                        fprintf(stderr, "type of 'x2' is: %s\n", (const char*)data.x2.typeDescription());
    94103                        fprintf(stderr, "-----\n\n");
    95104                        param.save(&virt_stdout);
  • cpp/frams/_demos/loader_test_param.in

    r323 r329  
    66Long multiline text
    771\\~
    8 22\~
     822\~\n
    99333\ \\
    10104444~
    1111deftext:other
    1212i1:-12345
    13 i2:10
     13i2:-0X10
    1414i3:2
     15f4:22222
     16f3:2222
     17f2:222
    1518f1:22
    16 f2:222
    17 x:3.14
     19f4:2
     20x1:3.14
     21x2:314
    1822notloaded:44
    19 unchanged:444
     23notchanged:444
    2024notsaved:4444
     25nosuchfield:value
    2126
    22 #all fields except x will have default values
     27#all fields except x1 will have default values
    2328data:
    24 x:just x (string extvalue)
     29x1:just x (string extvalue)
    2530
    2631someotherdata:
     
    3035data:
    3136text:abcdefghijklmnopqrstuvwxyz
    32 i1:uu
     37i1:notanumber
    3338i2:-99999
    34 i3:99999
    35 x:@Serialized:[1,2,3,1.00000,2e0,3.0,"x","]","\""]
     39i3:+99999
     40i4:notanumber_with_default
     41f1:-0x100
     42f2:-1e
     43f3:+1e1
     44f4:1ee
     45x1:@Serialized:[1,2,3,1.00000,2e0,3.0,"x","]","\""]
     46x2:@Serialized:{"a":[1,2,3],"b":"abc","c":1.23}
    3647
    3748data:
    38 i1:0x100
     49i1:+0X10
    3950i2:1e2
    4051i3:-10
    41 x:@Serialized:{"a":[1,2,3],"b":"abc","c":1.23}
     52x1:next line will overwrite this
     53x1:@Serialized:{"a":[1,2,3],"b":^1,"c":^1}
     54x2:@Serialized:[[100,^1],["abc"],[300,^2]]
     55i3:5
Note: See TracChangeset for help on using the changeset viewer.