ParserEventDecoder.cpp 8.63 KB
Newer Older
Johnny Jazeix's avatar
Johnny Jazeix committed
1
#include "ParserEventDecoder.hpp"
2

3 4
using namespace std;

5
ParserEventDecoder::ParserEventDecoder(){
Pascal Noisette's avatar
Pascal Noisette committed
6 7
}

8
void ParserEventDecoder::store_event(const Definition &definition, Line &line, Trace &trace){
Pascal Noisette's avatar
Pascal Noisette committed
9

10
    String alias;
11
    bool alias_is_initialized = false;
12
    String name;
13
    bool name_is_initialized = false;
14
    String container_type;
Pascal Noisette's avatar
Pascal Noisette committed
15 16 17 18 19 20 21
    String source_container_type;
    String dest_container_type;
    String entity_type;
    Date time;
    String type;
    String container;
    String value_string;
22
    Double value_double;
Pascal Noisette's avatar
Pascal Noisette committed
23 24
    String source_container;
    String dest_container;
25
    String key;
Pascal Noisette's avatar
Pascal Noisette committed
26

27
    vector<Value *> extra_fields;
Pascal Noisette's avatar
Pascal Noisette committed
28

29
    unsigned int i = 1;
30
    vector<Field> fields = definition.get_fields();
31
    unsigned int number_of_values = fields.size();
Pascal Noisette's avatar
Pascal Noisette committed
32

33
    while(i < number_of_values+1) {
Pascal Noisette's avatar
Pascal Noisette committed
34

35
        string current_value;
36
        if (!line.item(i, current_value)) {
37
            cerr << "warning : missing values" << endl;
38 39
            return;
        }
Pascal Noisette's avatar
Pascal Noisette committed
40

41
        else if (fields[i-1]._name == "Alias") {
Johnny Jazeix's avatar
Johnny Jazeix committed
42
            alias = current_value;
43 44 45
            alias_is_initialized = true;
        }

46
        else if (fields[i-1]._name == "Name") {
Johnny Jazeix's avatar
Johnny Jazeix committed
47
            name = current_value;
48 49 50
            name_is_initialized = true;
        }

51
        else if (fields[i-1]._name == "ContainerType") {
Johnny Jazeix's avatar
Johnny Jazeix committed
52
            container_type = current_value;
53
        }
Pascal Noisette's avatar
Pascal Noisette committed
54

55
        else if (fields[i-1]._name == "SourceContainerType") {
Johnny Jazeix's avatar
Johnny Jazeix committed
56
            source_container_type = current_value;
57
        }
Pascal Noisette's avatar
Pascal Noisette committed
58

59
        else if (fields[i-1]._name == "DestContainerType") {
Johnny Jazeix's avatar
Johnny Jazeix committed
60
            dest_container_type = current_value;
61 62 63
        }

        else if (fields[i-1]._name == "EntityType") {
Johnny Jazeix's avatar
Johnny Jazeix committed
64
            entity_type = current_value;
65 66 67
        }

        else if (fields[i-1]._name == "Time") {
68
            if(!Date::instantiate(current_value, time)) {
69
                cerr << "warning : incompatible value : " << current_value << endl;
70 71 72 73 74
                return;
            }
        }

        else if (fields[i-1]._name == "Type") {
Johnny Jazeix's avatar
Johnny Jazeix committed
75
            type = current_value;
76 77 78
        }

        else if (fields[i-1]._name == "Container") {
Johnny Jazeix's avatar
Johnny Jazeix committed
79
            container = current_value;
80 81 82 83
        }

        else if (fields[i-1]._name == "Value") {
            if(fields[i-1]._type == "double") {
84
                if(!Double::instantiate(current_value, value_double)) {
85
                    cerr << "warning : incompatible value : " << current_value << endl;
86 87
                    return;
                }
88
            }
89
            else {
Johnny Jazeix's avatar
Johnny Jazeix committed
90
                value_string = current_value;
91 92 93 94
            }
        }

        else if (fields[i-1]._name == "SourceContainer") {
95
            source_container = current_value;
96 97 98
        }

        else if (fields[i-1]._name == "DestContainer") {
Johnny Jazeix's avatar
Johnny Jazeix committed
99
            dest_container = current_value;
100 101 102
        }

        else if (fields[i-1]._name == "Key") {
Johnny Jazeix's avatar
Johnny Jazeix committed
103
            key = current_value;
104 105 106 107
        }

        else {
            if(fields[i-1]._type == "string") {
108
                String value = current_value;
Pascal Noisette's avatar
Pascal Noisette committed
109
                extra_fields.push_back(&value);
110 111 112
            }
            else if(fields[i-1]._type == "double") {
                Double value;
113
                if(!Double::instantiate(current_value, value)) {
114
                    cerr << "warning : incompatible value : " << current_value << endl;
115 116
                    return;
                }
Pascal Noisette's avatar
Pascal Noisette committed
117
                extra_fields.push_back(&value);
118 119 120
            }
            else if(fields[i-1]._type == "hex") {
                Hex value;
121
                if(!Hex::instantiate(current_value, value)) {
122
                    cerr << "warning : incompatible value : " << current_value << endl;
123 124
                    return;
                }
Pascal Noisette's avatar
Pascal Noisette committed
125
                extra_fields.push_back(&value);
126 127 128
            }
            else if(fields[i-1]._type == "date") {
                Date value;
129
                if(!Date::instantiate(current_value, value)) {
130
                    cerr << "warning : incompatible value : " << current_value << endl;
131 132
                    return;
                }
Pascal Noisette's avatar
Pascal Noisette committed
133
                extra_fields.push_back(&value);
134
            }
135
            else if(fields[i-1]._type == "int") {
136
                Integer value;
137
                if(!Integer::instantiate(current_value, value)) {
138
                    cerr << "warning : incompatible value : " << current_value << endl;
139 140
                    return;
                }
Pascal Noisette's avatar
Pascal Noisette committed
141
                extra_fields.push_back(&value);
142 143 144
            }
            else if(fields[i-1]._type == "color") {
                Color value;
145
                if(!Color::instantiate(current_value, value)) {
146
                    cerr << "warning : incompatible value : " << current_value << endl;
147 148
                    return;
                }
Pascal Noisette's avatar
Pascal Noisette committed
149
                extra_fields.push_back(&value);
150 151
            }
            else {
152
                cerr << "warning : unknown type" << endl;
153 154 155 156
                return;
            }
        }

157
        i ++;
158
    }
Pascal Noisette's avatar
Pascal Noisette committed
159

Arthur Redondy's avatar
Arthur Redondy committed
160
    if(line.length() > i+1) {
161
        cerr << "warning : extra value(s)" << endl;
162
    }
Pascal Noisette's avatar
Pascal Noisette committed
163

164 165
    Name alias_name;

Pascal Noisette's avatar
Pascal Noisette committed
166 167
    if(alias_is_initialized){
        alias_name.set_alias(alias.to_string());
168
    }
Pascal Noisette's avatar
Pascal Noisette committed
169 170
    if (name_is_initialized){
        alias_name.set_name(name.to_string());
171
    }
Pascal Noisette's avatar
Pascal Noisette committed
172

173

174 175 176
    string event_name = definition.get_event_name();

    if(event_name == "PajeDefineContainerType") {
177
        trace.define_container_type(alias_name, trace.search_container_type(container_type), extra_fields);
178
    }
179 180

    else if(event_name == "PajeCreateContainer") {
181
        trace.create_container(time, alias_name, trace.search_container_type(type), trace.search_container(container), extra_fields);
182 183 184
    }

    else if(event_name == "PajeDestroyContainer") {
Olivier Lagrasse's avatar
Olivier Lagrasse committed
185
        trace.destroy_container(time, trace.search_container(alias_name.to_String()), trace.search_container_type(type), extra_fields);
186 187 188
    }

    else if(event_name == "PajeDefineEventType") {
189
        trace.define_event_type(alias_name, trace.search_container_type(container_type), extra_fields);
190 191 192
    }

    else if(event_name == "PajeDefineStateType") {
193
        trace.define_state_type(alias_name, trace.search_container_type(container_type), extra_fields);
194 195 196
    }

    else if(event_name == "PajeDefineVariableType") {
197
        trace.define_variable_type(alias_name, trace.search_container_type(container_type), extra_fields);
Arthur Redondy's avatar
Arthur Redondy committed
198 199 200
    }

    else if(event_name == "PajeDefineLinkType") {
201
        trace.define_link_type(alias_name, trace.search_container_type(container_type), trace.search_container_type(source_container_type), trace.search_container_type(dest_container_type), extra_fields);
Arthur Redondy's avatar
Arthur Redondy committed
202 203 204
    }

    else if(event_name == "PajeDefineEntityValue") {
205
        trace.define_entity_value(alias_name, trace.search_entity_type(entity_type), extra_fields);
Arthur Redondy's avatar
Arthur Redondy committed
206 207 208
    }

    else if(event_name == "PajeSetState") {
209 210 211 212 213 214 215 216 217 218 219 220 221
        trace.set_state(time, trace.search_state_type(type), trace.search_container(container), trace.search_entity_value(value_string), extra_fields);
    }

    else if(event_name == "PajePushState") {
        trace.push_state(time, trace.search_state_type(type), trace.search_container(container), trace.search_entity_value(value_string), extra_fields);
    }

    else if(event_name == "PajePopState") {
        trace.pop_state(time, trace.search_state_type(type), trace.search_container(container), extra_fields);
    }

    else if(event_name == "PajeNewEvent") {
        trace.new_event(time, trace.search_event_type(type), trace.search_container(container), trace.search_entity_value(value_string), extra_fields);
222 223
    }

224
    else if(event_name == "PajeSetVariable") {
225 226 227
        trace.set_variable(time, trace.search_variable_type(type), trace.search_container(container), value_double, extra_fields);
    }

228
    else if(event_name == "PajeAddVariable") {
229 230 231
        trace.add_variable(time, trace.search_variable_type(type), trace.search_container(container), value_double, extra_fields);
    }

232
    else if(event_name == "PajeSubVariable") {
Arthur Redondy's avatar
Arthur Redondy committed
233
        trace.sub_variable(time, trace.search_variable_type(type), trace.search_container(container), value_double, extra_fields);
234 235
    }

236
    else if(event_name == "PajeStartLink") {
Olivier Lagrasse's avatar
Olivier Lagrasse committed
237
        trace.start_link(time, trace.search_link_type(type), trace.search_container(container), trace.search_container(source_container), trace.search_entity_value(value_string), Integer(), extra_fields);
Arthur Redondy's avatar
Arthur Redondy committed
238 239
    }

240
    else if(event_name == "PajeEndLink") {
Olivier Lagrasse's avatar
Olivier Lagrasse committed
241
        trace.end_link(time, trace.search_link_type(type), trace.search_container(container), trace.search_container(dest_container), trace.search_entity_value(value_string), Integer(), extra_fields);
242
    }
243 244

    else {
245
        cerr << "BUG PARSER BIS" << endl;
Pascal Noisette's avatar
Pascal Noisette committed
246
        return;
247
    }
248
}
Pascal Noisette's avatar
Pascal Noisette committed
249