Skip to content

Commit e22c830

Browse files
committed
refactoring
1 parent 5364c1d commit e22c830

1 file changed

Lines changed: 50 additions & 56 deletions

File tree

src/ruis/style/style_provider.hpp

Lines changed: 50 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,63 @@ class style_provider
6868
utki::shared_ref<ruis::style_sheet> cur_style_sheet;
6969

7070
template <typename value_type>
71-
styled<value_type> get(style id) const;
71+
styled<value_type> get(style id) const
72+
{
73+
if (auto svb = this->get_from_cache(id)) {
74+
if (auto sv = std::dynamic_pointer_cast<const typename styled<value_type>::style_value>(svb)) {
75+
return {utki::shared_ref<const typename styled<value_type>::style_value>(std::move(sv))};
76+
}
77+
throw std::invalid_argument("style::get(id): requested value_type does not match the one stored in cache");
78+
}
79+
const auto& desc = this->cur_style_sheet.get().get(id);
80+
81+
if (desc.empty()) {
82+
throw std::invalid_argument(
83+
utki::cat("style_provider::get(style): no style value with id ", unsigned(id), " in the style sheet")
84+
);
85+
}
86+
87+
auto ret = utki::make_shared<typename styled<value_type>::style_value>(
88+
desc, //
89+
this->res_loader.get()
90+
);
91+
this->store_to_cache(
92+
id, //
93+
ret.to_shared_ptr()
94+
);
95+
return {ret};
96+
}
7297

7398
public:
7499
style_provider(utki::shared_ref<ruis::resource_loader> loader);
75100

76101
void set(utki::shared_ref<style_sheet> ss);
77102

78103
template <typename value_type>
79-
styled<value_type> get(std::string_view id) const;
104+
styled<value_type> get(std::string_view id) const
105+
{
106+
if (auto svb = this->get_from_cache(id)) {
107+
if (auto sv = std::dynamic_pointer_cast<const typename styled<value_type>::style_value>(svb)) {
108+
return {utki::shared_ref<const typename styled<value_type>::style_value>(std::move(sv))};
109+
}
110+
throw std::invalid_argument("style::get(id): requested value_type does not match the one stored in cache");
111+
}
112+
113+
const auto* desc = this->cur_style_sheet.get().get(id);
114+
if (!desc) {
115+
return typename styled<value_type>::actual_value_type();
116+
}
117+
118+
auto ret = utki::make_shared<typename styled<value_type>::style_value>(
119+
*desc, //
120+
this->res_loader.get()
121+
);
122+
this->store_to_cache(
123+
id, //
124+
ret.to_shared_ptr()
125+
);
126+
return {ret};
127+
}
80128

81129
// ===================================
82130
// ====== standard style values ======
@@ -94,58 +142,4 @@ class style_provider
94142
styled<res::font> get_font_face_normal() const;
95143
};
96144

97-
template <typename value_type>
98-
styled<value_type> style_provider::get(style id) const
99-
{
100-
if (auto svb = this->get_from_cache(id)) {
101-
if (auto sv = std::dynamic_pointer_cast<const typename styled<value_type>::style_value>(svb)) {
102-
return {utki::shared_ref<const typename styled<value_type>::style_value>(std::move(sv))};
103-
}
104-
throw std::invalid_argument("style::get(id): requested value_type does not match the one stored in cache");
105-
}
106-
const auto& desc = this->cur_style_sheet.get().get(id);
107-
108-
if (desc.empty()) {
109-
throw std::invalid_argument(
110-
utki::cat("style_provider::get(style): no style value with id ", unsigned(id), " in the style sheet")
111-
);
112-
}
113-
114-
auto ret = utki::make_shared<typename styled<value_type>::style_value>(
115-
desc, //
116-
this->res_loader.get()
117-
);
118-
this->store_to_cache(
119-
id, //
120-
ret.to_shared_ptr()
121-
);
122-
return {ret};
123-
}
124-
125-
template <typename value_type>
126-
styled<value_type> style_provider::get(std::string_view id) const
127-
{
128-
if (auto svb = this->get_from_cache(id)) {
129-
if (auto sv = std::dynamic_pointer_cast<const typename styled<value_type>::style_value>(svb)) {
130-
return {utki::shared_ref<const typename styled<value_type>::style_value>(std::move(sv))};
131-
}
132-
throw std::invalid_argument("style::get(id): requested value_type does not match the one stored in cache");
133-
}
134-
135-
const auto* desc = this->cur_style_sheet.get().get(id);
136-
if (!desc) {
137-
return typename styled<value_type>::actual_value_type();
138-
}
139-
140-
auto ret = utki::make_shared<typename styled<value_type>::style_value>(
141-
*desc, //
142-
this->res_loader.get()
143-
);
144-
this->store_to_cache(
145-
id, //
146-
ret.to_shared_ptr()
147-
);
148-
return {ret};
149-
}
150-
151145
} // namespace ruis

0 commit comments

Comments
 (0)