7 #ifndef Tomato_TomatoPARSER_HXX 8 #define Tomato_TomatoPARSER_HXX 13 template<
typename MeasureType>
15 TomatoParser<MeasureType>
18 FILE *fh = fopen(_filePath.c_str(),
"rb");
24 if (!yaml_parser_initialize(&parser))
25 throw std::runtime_error(
"Failed to initialize parser!\n");
27 throw std::runtime_error(
"\'" + _filePath +
"\' - failed to open file!\n");
31 yaml_parser_set_input_file(&parser, fh);
33 bool flagKeyToken =
false;
35 bool flagFlowEntryToken =
false;
36 bool flagBlockEntryToken =
false;
37 std::string lastKeyTokenValue;
38 std::string lastFlowEntryTokenValue;
39 std::string lastBlockEntryTokenValue;
41 std::vector<std::string> temp;
44 yaml_parser_scan(&parser, &token);
47 case YAML_KEY_TOKEN: {
51 case YAML_VALUE_TOKEN: {
54 case YAML_FLOW_SEQUENCE_START_TOKEN: {
55 flagFlowEntryToken =
true;
58 case YAML_FLOW_SEQUENCE_END_TOKEN: {
59 flagFlowEntryToken =
false;
60 if (_sequences.find(lastKeyTokenValue) != _sequences.end()) {
61 _sequences[lastKeyTokenValue] = temp;
64 lastFlowEntryTokenValue =
"";
67 case YAML_FLOW_ENTRY_TOKEN: {
68 flagFlowEntryToken =
true;
71 case YAML_BLOCK_SEQUENCE_START_TOKEN: {
72 flagBlockEntryToken =
true;
75 case YAML_BLOCK_END_TOKEN: {
76 flagBlockEntryToken =
false;
77 if ((_sequences.find(lastKeyTokenValue) != _sequences.end()) && (!temp.empty())) {
78 _sequences[lastKeyTokenValue] = temp;
81 lastBlockEntryTokenValue =
"";
84 case YAML_BLOCK_ENTRY_TOKEN: {
85 flagBlockEntryToken =
true;
88 case YAML_SCALAR_TOKEN: {
89 std::string scalar((
char *) token.data.scalar.value);
94 if (!lastFlowEntryTokenValue.empty()){
95 flagFlowEntryToken =
false;
96 if (_sequences.find(lastKeyTokenValue) != _sequences.end()) {
97 _sequences[lastKeyTokenValue] = temp;
100 lastFlowEntryTokenValue =
"";
103 if (!lastBlockEntryTokenValue.empty()) {
104 flagBlockEntryToken =
false;
105 if ((_sequences.find(lastKeyTokenValue) != _sequences.end()) && (!temp.empty())) {
106 _sequences[lastKeyTokenValue] = temp;
109 lastBlockEntryTokenValue =
"";
111 flagKeyToken =
false;
112 lastKeyTokenValue = scalar;
114 if (_scalars.find(lastKeyTokenValue.c_str()) != _scalars.end()) {
115 _scalars[lastKeyTokenValue] = scalar;
120 if (flagFlowEntryToken) {
121 flagFlowEntryToken =
false;
122 lastFlowEntryTokenValue = scalar;
123 temp.push_back(scalar);
127 if (flagBlockEntryToken) {
128 flagBlockEntryToken =
false;
129 lastBlockEntryTokenValue = scalar;
130 temp.push_back(scalar);
137 if (token.type != YAML_STREAM_END_TOKEN) yaml_token_delete(&token);
139 }
while (token.type != YAML_STREAM_END_TOKEN);
140 yaml_token_delete(&token);
144 yaml_parser_delete(&parser);
152 #endif //Tomato_TomatoPARSER_H Definition: OxCalculator.h:19