aboutsummaryrefslogtreecommitdiff
path: root/src/ui/mapper/style/AndConditionMapper.cpp
blob: dd8784d572f446878f5f2efbd0bc523283e06bac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "cru/ui/mapper/style/AndConditionMapper.h"
#include "cru/common/ClonablePtr.h"
#include "cru/ui/mapper/MapperRegistry.h"
#include "cru/ui/mapper/style/IConditionMapper.h"
#include "cru/ui/style/Condition.h"
#include "cru/xml/XmlNode.h"

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