aboutsummaryrefslogtreecommitdiff
path: root/src/ui/mapper
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-01-24 17:52:47 +0800
committercrupest <crupest@outlook.com>2022-01-24 17:52:47 +0800
commit1cc6e51838fcd5fc986dbb3e13bbb85f11a348be (patch)
tree438ed0961b708139f2c3f8429052a737e0b8e334 /src/ui/mapper
parent6d64ac7d354831b687aee1b7450d539411648888 (diff)
downloadcru-1cc6e51838fcd5fc986dbb3e13bbb85f11a348be.tar.gz
cru-1cc6e51838fcd5fc986dbb3e13bbb85f11a348be.tar.bz2
cru-1cc6e51838fcd5fc986dbb3e13bbb85f11a348be.zip
...
Diffstat (limited to 'src/ui/mapper')
-rw-r--r--src/ui/mapper/style/AndConditionMapper.cpp31
-rw-r--r--src/ui/mapper/style/OrConditionMapper.cpp31
2 files changed, 62 insertions, 0 deletions
diff --git a/src/ui/mapper/style/AndConditionMapper.cpp b/src/ui/mapper/style/AndConditionMapper.cpp
new file mode 100644
index 00000000..e07e514c
--- /dev/null
+++ b/src/ui/mapper/style/AndConditionMapper.cpp
@@ -0,0 +1,31 @@
+#include "cru/ui/mapper/style/AndConditionMapper.hpp"
+#include "cru/common/ClonablePtr.hpp"
+#include "cru/ui/mapper/MapperRegistry.hpp"
+#include "cru/ui/mapper/style/IConditionMapper.hpp"
+#include "cru/ui/style/Condition.hpp"
+#include "cru/xml/XmlNode.hpp"
+
+namespace cru::ui::mapper::style {
+bool AndConditionMapper::XmlElementIsOfThisType(xml::XmlElementNode *node) {
+ return node->GetTag().CaseInsensitiveEqual(u"AndCondition");
+}
+
+ClonablePtr<ui::style::AndCondition> AndConditionMapper::DoMapFromXml(
+ xml::XmlElementNode *node) {
+ std::vector<ClonablePtr<ui::style::Condition>> conditions;
+ auto condition_mappers =
+ MapperRegistry::GetInstance()->GetMappersByInterface<IConditionMapper>();
+ for (auto child : node->GetChildren()) {
+ if (child->GetType() == xml::XmlNode::Type::Element) {
+ auto c = child->AsElement();
+ for (auto mapper : condition_mappers) {
+ if (mapper->XmlElementIsOfThisType(c)) {
+ conditions.push_back(mapper->MapConditionFromXml(c));
+ break;
+ }
+ }
+ }
+ }
+ return ui::style::AndCondition::Create(std::move(conditions));
+}
+} // namespace cru::ui::mapper::style
diff --git a/src/ui/mapper/style/OrConditionMapper.cpp b/src/ui/mapper/style/OrConditionMapper.cpp
new file mode 100644
index 00000000..a91f5130
--- /dev/null
+++ b/src/ui/mapper/style/OrConditionMapper.cpp
@@ -0,0 +1,31 @@
+#include "cru/ui/mapper/style/OrConditionMapper.hpp"
+#include "cru/common/ClonablePtr.hpp"
+#include "cru/ui/mapper/MapperRegistry.hpp"
+#include "cru/ui/mapper/style/IConditionMapper.hpp"
+#include "cru/ui/style/Condition.hpp"
+#include "cru/xml/XmlNode.hpp"
+
+namespace cru::ui::mapper::style {
+bool OrConditionMapper::XmlElementIsOfThisType(xml::XmlElementNode *node) {
+ return node->GetTag().CaseInsensitiveEqual(u"OrCondition");
+}
+
+ClonablePtr<ui::style::OrCondition> OrConditionMapper::DoMapFromXml(
+ xml::XmlElementNode *node) {
+ std::vector<ClonablePtr<ui::style::Condition>> conditions;
+ auto condition_mappers =
+ MapperRegistry::GetInstance()->GetMappersByInterface<IConditionMapper>();
+ for (auto child : node->GetChildren()) {
+ if (child->GetType() == xml::XmlNode::Type::Element) {
+ auto c = child->AsElement();
+ for (auto mapper : condition_mappers) {
+ if (mapper->XmlElementIsOfThisType(c)) {
+ conditions.push_back(mapper->MapConditionFromXml(c));
+ break;
+ }
+ }
+ }
+ }
+ return ui::style::OrCondition::Create(std::move(conditions));
+}
+} // namespace cru::ui::mapper::style