blob: d014edc7854a7fbc8923840319bbde6d5b965ff1 (
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
32
33
34
35
 | #include "cru/ui/mapper/style/StyleRuleSetMapper.h"
#include <memory>
#include "cru/ui/mapper/MapperRegistry.h"
#include "cru/ui/style/StyleRule.h"
#include "cru/ui/style/StyleRuleSet.h"
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()->GetClonablePtrMapper<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
 |