5 #include <rapidxml/rapidxml_print.hpp>
24 std::vector<std::string> xmlTypes{};
26 for(
unsigned int i = 0; i < files.size(); i++)
29 std::string fileNameNoExt = files[i].substr(0, files[i].size() - 4);
30 std::string fileNameExt = files[i].substr(files[i].size() - 4, 4);
32 if(fileNameExt ==
".xml")
36 xmlTypes.push_back(fileNameNoExt);
41 for(
unsigned int i = 0; i < xmlTypes.size(); i++)
43 std::ifstream file(filepath +
"/" + xmlTypes[i] +
".xml");
47 "Could not read from file: " + filepath +
"/" + xmlTypes[i] +
".xml");
62 rapidxml::xml_document<> doc;
65 std::string totalContent;
66 while(std::getline(file, line))
68 totalContent += line +
"\n";
70 doc.parse<rapidxml::parse_full>((
char*)totalContent.c_str());
73 for(rapidxml::xml_node<>* node = doc.first_node(); node; node = node->next_sibling())
75 if(node->type() != rapidxml::node_comment)
78 std::string nodeName = std::string(node->name());
84 ". Is this type registered?");
96 std::to_string(d->
id) +
")");
110 std::string dataType = cache.first;
113 std::ofstream file(filepath +
"/" + dataType +
".xml");
118 "Could not save to file: " + filepath +
"/" + dataType +
".xml");
135 rapidxml::xml_document<> doc;
141 e.second->write(&doc);
144 std::to_string(e.second->id) +
")");
183 rapidxml::xml_node<>* node = parent->first_node(valueName.c_str());
193 if(std::string(node->value()) != std::string(
""))
195 variable = std::string(node->value());
203 rapidxml::xml_node<>* node = parent->first_node(valueName.c_str());
213 if(std::string(node->value()) != std::string(
""))
215 variable = std::stoi(std::string(node->value()));
224 rapidxml::xml_node<>* node = parent->first_node(valueName.c_str());
234 if(std::string(node->value()) != std::string(
""))
236 variable = std::vector<unsigned int>{};
238 std::string value = node->value();
242 unsigned int elementCount = std::count(value.begin(), value.end(),
'{');
245 for(
unsigned int i = 0; i < elementCount; i++)
248 std::string uintStr = value.substr(value.find(
'{') + 1, value.find(
'}') - value.find(
'{') - 1);
251 unsigned int val = std::stoi(uintStr);
254 variable.emplace_back(val);
257 value = value.substr(value.find(
'{') + 1, value.size() - value.find(
'{') - 1);
266 rapidxml::xml_node<>* node = parent->first_node(valueName.c_str());
276 if(std::string(node->value()) != std::string(
""))
278 variable = std::stoi(std::string(node->value()));
286 rapidxml::xml_node<>* node = parent->first_node(valueName.c_str());
296 if(std::string(node->value()) != std::string(
""))
298 variable = std::stof(std::string(node->value()));
307 rapidxml::xml_node<>* node = parent->first_node(valueName.c_str());
317 if(std::string(node->value()) != std::string(
""))
319 variable = std::vector<float>{};
321 std::string value = node->value();
325 unsigned int elementCount = std::count(value.begin(), value.end(),
'{');
328 for(
unsigned int i = 0; i < elementCount; i++)
331 std::string floatStr = value.substr(value.find(
'{') + 1, value.find(
'}') - value.find(
'{') - 1);
334 float val = std::stof(floatStr);
337 variable.emplace_back(val);
340 value = value.substr(value.find(
'{') + 1, value.size() - value.find(
'{') - 1);
349 rapidxml::xml_node<>* node = parent->first_node(valueName.c_str());
359 if(std::string(node->value()) != std::string(
""))
361 variable = (std::string(node->value()) !=
"0");
370 rapidxml::xml_node<>* node = parent->first_node(valueName.c_str());
380 if(std::string(node->value()) != std::string(
""))
382 variable = std::vector<bool>{};
384 std::string value = node->value();
388 unsigned int elementCount = std::count(value.begin(), value.end(),
'{');
391 for(
unsigned int i = 0; i < elementCount; i++)
394 std::string boolStr = value.substr(value.find(
'{') + 1, value.find(
'}') - value.find(
'{') - 1);
397 bool val = (boolStr !=
"0");
400 variable.emplace_back(val);
403 value = value.substr(value.find(
'{') + 1, value.size() - value.find(
'{') - 1);
412 rapidxml::xml_node<>* node = parent->first_node(valueName.c_str());
422 if(std::string(node->value()) != std::string(
""))
424 std::string value = node->value();
427 float val0 = std::stof(value.substr(0, value.find(
',')));
428 float val1 = std::stof(value.substr(value.find(
',') + 1, value.size() - value.find(
',') - 1));
431 variable = glm::vec2(val0, val1);
440 rapidxml::xml_node<>* node = parent->first_node(valueName.c_str());
450 if(std::string(node->value()) != std::string(
""))
452 variable = std::vector<glm::vec2>{};
454 std::string value = node->value();
458 unsigned int elementCount = std::count(value.begin(), value.end(),
'{');
461 for(
unsigned int i = 0; i < elementCount; i++)
464 std::string vec2Str = value.substr(value.find(
'{') + 1, value.find(
'}') - value.find(
'{') - 1);
467 float val0 = std::stof(vec2Str.substr(0, vec2Str.find(
',')));
469 std::stof(vec2Str.substr(vec2Str.find(
',') + 1, vec2Str.size() - vec2Str.find(
',') - 1));
472 variable.emplace_back(val0, val1);
475 value = value.substr(value.find(
'}') + 1, value.size() - value.find(
'}') - 1);