aboutsummaryrefslogtreecommitdiff
path: root/src/ui/mapper/style/StyleRuleSetMapper.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-01-24 20:26:58 +0800
committercrupest <crupest@outlook.com>2022-01-24 20:26:58 +0800
commit72402c09d45b696cd58a65b4a141a804e1cd9371 (patch)
tree4a8793a588370c071d576f144994495886d8e909 /src/ui/mapper/style/StyleRuleSetMapper.cpp
parent549b072d241a8d2d1ca187bba8c1cb5190dd737e (diff)
downloadcru-72402c09d45b696cd58a65b4a141a804e1cd9371.tar.gz
cru-72402c09d45b696cd58a65b4a141a804e1cd9371.tar.bz2
cru-72402c09d45b696cd58a65b4a141a804e1cd9371.zip
...
Diffstat (limited to 'src/ui/mapper/style/StyleRuleSetMapper.cpp')
-rw-r--r--src/ui/mapper/style/StyleRuleSetMapper.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/ui/mapper/style/StyleRuleSetMapper.cpp b/src/ui/mapper/style/StyleRuleSetMapper.cpp
new file mode 100644
index 00000000..b9199d27
--- /dev/null
+++ b/src/ui/mapper/style/StyleRuleSetMapper.cpp
@@ -0,0 +1,35 @@
+#include "cru/ui/mapper/style/StyleRuleSetMapper.hpp"
+#include <memory>
+#include "cru/ui/mapper/MapperRegistry.hpp"
+#include "cru/ui/style/StyleRule.hpp"
+#include "cru/ui/style/StyleRuleSet.hpp"
+
+namespace cru::ui::mapper::style {
+using namespace cru::ui::style;
+
+bool StyleRuleSetMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
+ return node->GetTag().CaseInsensitiveEqual(u"StyleRuleSet");
+}
+
+std::shared_ptr<ui::style::StyleRuleSet> StyleRuleSetMapper::DoMapFromXml(
+ xml::XmlElementNode* node) {
+ auto style_rule_mapper =
+ MapperRegistry::GetInstance()->GetPtrMapper<StyleRule>();
+
+ auto result = std::make_shared<StyleRuleSet>();
+
+ for (auto child : node->GetChildren()) {
+ if (child->GetType() == xml::XmlNode::Type::Element) {
+ auto c = child->AsElement();
+ if (style_rule_mapper->XmlElementIsOfThisType(c)) {
+ auto style_rule = style_rule_mapper->MapFromXml(c);
+ result->AddStyleRule(*style_rule);
+ } else {
+ throw Exception(u"StyleRuleSet can only contain StyleRule.");
+ }
+ }
+ }
+
+ return result;
+}
+} // namespace cru::ui::mapper::style