// Copyright (c) 2023 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #pragma once #include "label.hpp" namespace Dawn { struct ChildInfo; struct ChildrenInfo { std::vector children; }; struct ChildInfo { enum ChildType type; struct ChildrenInfo children; std::string ref; bool_t hasRef = false; struct LabelInfo label; }; class ChildrenParser : public XmlParser { protected: std::vector getRequiredAttributes() { return std::vector(); } std::map getOptionalAttributes() { return std::map(); } int32_t onParse( Xml *node, std::map values, struct ChildrenInfo *out, std::string *error ) { // Parse children of self. int32_t ret = 0; auto itChildren = node->children.begin(); while(itChildren != node->children.end()) { auto c = *itChildren; struct ChildInfo child; if(c->node == "label") { child.type = CHILD_TYPE_LABEL; ret = (LabelParser()).parse(c, &child.label, error); } else { *error = "Unrecognized UI Element " + c->node; return 1; } if(ret != 0) return ret; // Now Parse children of children ret = (ChildrenParser()).parse(c, &child.children, error); if(ret != 0) return ret; ++itChildren; } return ret; } }; }