File: checkredo.cc

package info (click to toggle)
simrisc 16.05.00-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,568 kB
  • sloc: cpp: 6,877; fortran: 665; makefile: 112; ansic: 112; sh: 107
file content (81 lines) | stat: -rw-r--r-- 2,198 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#define XERR "parser"
#include "parser.ih"

// If the previous key allows additional number-lines and a number-line is
// read next then set that line's key to the last-read key, so multiple
// lines of that key are returned.

namespace
{
    enum
    {
        INIT,
        REDO,
    };

    size_t s_state = INIT;
    string s_key;

    unordered_set<string> redo{ "death:", "riskTable:", "ageGroup:",
                                "sensitivity:", "round:", "prob:", 
                                "type:", 
                                "lung0:", "lung1:", "lung2:", "lung3:" };

    unordered_set<string> survival{ "type:", 
                                 "lung0:", "lung1:", "lung2:", "lung3:" };

    unordered_set<string> abcd{ "a",  "b",  "c",  "d", "e" };
}

    // by addconfigline.cc

//static
string Parser::checkRedo(ConfigLines &configLine)
{
    string key = configLine.key();

    if (redo.find(key) != redo.end() )      // at a key: refill with that key
    {
        s_key = key;
        s_state = REDO;
    }
    else if                         // digits always OK. '*' OK for prob:
    (                               // a..d OK voor 'survival:'
        isdigit(key.front())
        or 
        (s_key == "prob:" and key.front() == '*')
        or
        (
            survival.find(s_key) != survival.end() 
            and abcd.find(key) != abcd.end()
        )
        or (key == "-" and s_key == "ageGroup:")    // 2nd etc. ageGroup: 
                                                    // specs may omit the 
                                                    // initial values
    )
        configLine.key(key = s_key);
    else
        s_state = INIT;

    return key;
}


//    if (s_state == INIT)
//    {
//        if (redo.find(key) != redo.end() )
//        {
//            s_key = key;
//            s_state = REDO;
//        }
//    }
//    else if (                       // digits always OK. '*' OK for prob:
//                isdigit(key.front())        // a..d OK voor survival:
//                or 
//                (s_key == "prob:" and key.front() == '*')
//    )
//         configLine.key(key = s_key);
//    else
//         s_state = INIT;