diff options
Diffstat (limited to 'src/ui/mapper')
-rw-r--r-- | src/ui/mapper/style/AndConditionMapper.cpp | 31 | ||||
-rw-r--r-- | src/ui/mapper/style/OrConditionMapper.cpp | 31 |
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 |