2024-02-09 09:59:36 +03:00

60 lines
1.5 KiB
C++

#ifndef FRONTEND_GUI_GUI_XML_H_
#define FRONTEND_GUI_GUI_XML_H_
#include <memory>
#include <unordered_map>
#include "GUI.h"
#include "../../coders/xml.h"
namespace scripting {
class Environment;
}
namespace gui {
class UiXmlReader;
using uinode_reader = std::function<std::shared_ptr<UINode>(UiXmlReader&, xml::xmlelement)>;
class UiXmlReader {
std::unordered_map<std::string, uinode_reader> readers;
std::string filename;
const scripting::Environment& env;
public:
UiXmlReader(const scripting::Environment& env);
void add(const std::string& tag, uinode_reader reader);
bool hasReader(const std::string& tag) const;
std::shared_ptr<UINode> readUINode(xml::xmlelement element);
void readUINode(
UiXmlReader& reader,
xml::xmlelement element,
UINode& node
);
void readUINode(
UiXmlReader& reader,
xml::xmlelement element,
Container& container,
bool ignoreUnknown=false
);
std::shared_ptr<UINode> readXML(
const std::string& filename,
const std::string& source
);
std::shared_ptr<UINode> readXML(
const std::string& filename,
xml::xmlelement root
);
const scripting::Environment& getEnvironment() const;
const std::string& getFilename() const;
};
}
#endif // FRONTEND_GUI_GUI_XML_H_