blob: 3c1819a1495f641ec866c6542330ca4c0cb3170a (
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#include "cru/ui/mapper/style/StyleRuleMapper.h"
#include "cru/base/ClonePtr.h"
#include "cru/ui/mapper/MapperRegistry.h"
#include "cru/ui/mapper/style/ConditionMapper.h"
#include "cru/ui/mapper/style/StylerMapper.h"
#include "cru/ui/style/StyleRule.h"
#include "cru/ui/style/Styler.h"
namespace cru::ui::mapper::style {
using namespace ui::style;
ClonePtr<ui::style::StyleRule> StyleRuleMapper::DoMapFromXml(
xml::XmlElementNode* node) {
std::vector<IConditionMapper*> condition_mappers =
MapperRegistry::GetInstance()->GetMappersByInterface<IConditionMapper>();
std::vector<IStylerMapper*> styler_mappers =
MapperRegistry::GetInstance()->GetMappersByInterface<IStylerMapper>();
std::vector<ClonePtr<Condition>> conditions;
std::vector<ClonePtr<Styler>> stylers;
for (auto child : node->GetChildren()) {
if (child->GetType() == xml::XmlNode::Type::Element) {
auto c = child->AsElement();
bool resolved = false;
for (auto condition_mapper : condition_mappers) {
if (condition_mapper->XmlElementIsOfThisType(c)) {
conditions.push_back(condition_mapper->MapConditionFromXml(c));
resolved = true;
break;
}
}
if (!resolved) {
for (auto styler_mapper : styler_mappers) {
if (styler_mapper->XmlElementIsOfThisType(c)) {
stylers.push_back(styler_mapper->MapStylerFromXml(c));
resolved = true;
break;
}
}
}
if (!resolved) {
throw Exception("Unknown element in StyleRule: " + c->GetTag());
}
}
}
return StyleRule::Create(AndCondition::Create(std::move(conditions)),
CompoundStyler::Create(std::move(stylers)));
}
} // namespace cru::ui::mapper::style
|