POC
This commit is contained in:
68
src/dawntools/tools/uigen/parse/elements/children.hpp
Normal file
68
src/dawntools/tools/uigen/parse/elements/children.hpp
Normal file
@ -0,0 +1,68 @@
|
||||
// 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 {
|
||||
enum ChildType {
|
||||
CHILD_TYPE_LABEL
|
||||
};
|
||||
|
||||
struct ChildInfo;
|
||||
|
||||
struct ChildrenInfo {
|
||||
std::vector<struct ChildInfo> children;
|
||||
};
|
||||
|
||||
struct ChildInfo {
|
||||
enum ChildType type;
|
||||
struct LabelInfo label;
|
||||
struct ChildrenInfo children;
|
||||
};
|
||||
|
||||
class ChildrenParser : public XmlParser<struct ChildrenInfo> {
|
||||
protected:
|
||||
std::vector<std::string> getRequiredAttributes() {
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> getOptionalAttributes() {
|
||||
return std::map<std::string, std::string>();
|
||||
}
|
||||
|
||||
int32_t onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> 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;
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user