Skip to content

Commit ccbbe08

Browse files
committed
refactoring
1 parent c904b5e commit ccbbe08

3 files changed

Lines changed: 41 additions & 43 deletions

File tree

src/ruis/style/style_provider.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void style_provider::set(utki::shared_ref<style_sheet> ss)
8383
}
8484
}
8585

86-
std::shared_ptr<const style_provider::style_value_base> style_provider::get_from_cache(style id) const
86+
std::shared_ptr<const internal::style_value_base> style_provider::get_from_cache(style id) const
8787
{
8888
auto& w = this->standard_cache[id];
8989
auto p = w.lock();
@@ -94,7 +94,7 @@ std::shared_ptr<const style_provider::style_value_base> style_provider::get_from
9494
return p;
9595
}
9696

97-
std::shared_ptr<const style_provider::style_value_base> style_provider::get_from_cache(std::string_view id) const
97+
std::shared_ptr<const internal::style_value_base> style_provider::get_from_cache(std::string_view id) const
9898
{
9999
auto i = this->user_cache.find(id);
100100
if (i == this->user_cache.end()) {
@@ -111,7 +111,7 @@ std::shared_ptr<const style_provider::style_value_base> style_provider::get_from
111111

112112
void style_provider::store_to_cache(
113113
style id, //
114-
std::weak_ptr<style_value_base> v
114+
std::weak_ptr<internal::style_value_base> v
115115
) const
116116
{
117117
utki::assert(this->standard_cache[id].expired());
@@ -121,7 +121,7 @@ void style_provider::store_to_cache(
121121

122122
void style_provider::store_to_cache(
123123
std::string_view id, //
124-
std::weak_ptr<style_value_base> v
124+
std::weak_ptr<internal::style_value_base> v
125125
) const
126126
{
127127
utki::assert(!utki::contains(this->user_cache, id));

src/ruis/style/style_provider.hpp

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -32,57 +32,33 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
3232
#include "../util/length.hpp"
3333

3434
#include "style_sheet.hpp"
35+
#include "styled.hpp"
3536

3637
namespace ruis {
3738

3839
namespace res {
3940
class font;
4041
} // namespace res
4142

42-
template <typename styled_value_type>
43-
class styled;
44-
4543
class style_provider
4644
{
4745
template <typename styled_value_type>
4846
friend class styled;
4947

50-
class style_value_base
51-
{
52-
friend class style_provider;
53-
54-
protected:
55-
virtual void reload(
56-
const tml::forest& desc, //
57-
const ruis::resource_loader& loader
58-
) = 0;
59-
60-
style_value_base() = default;
61-
62-
public:
63-
style_value_base(const style_value_base&) = delete;
64-
style_value_base& operator=(const style_value_base&) = delete;
65-
66-
style_value_base(style_value_base&&) = delete;
67-
style_value_base& operator=(style_value_base&&) = delete;
68-
69-
virtual ~style_value_base() = default;
70-
};
48+
mutable utki::enum_array<std::weak_ptr<internal::style_value_base>, style> standard_cache;
49+
mutable std::map<std::string, std::weak_ptr<internal::style_value_base>, std::less<>> user_cache;
7150

72-
mutable utki::enum_array<std::weak_ptr<style_value_base>, style> standard_cache;
73-
mutable std::map<std::string, std::weak_ptr<style_value_base>, std::less<>> user_cache;
74-
75-
std::shared_ptr<const style_value_base> get_from_cache(style id) const;
76-
std::shared_ptr<const style_value_base> get_from_cache(std::string_view id) const;
51+
std::shared_ptr<const internal::style_value_base> get_from_cache(style id) const;
52+
std::shared_ptr<const internal::style_value_base> get_from_cache(std::string_view id) const;
7753

7854
void store_to_cache(
7955
style id, //
80-
std::weak_ptr<style_value_base> v
56+
std::weak_ptr<internal::style_value_base> v
8157
) const;
8258

8359
void store_to_cache(
8460
std::string_view id, //
85-
std::weak_ptr<style_value_base> v
61+
std::weak_ptr<internal::style_value_base> v
8662
) const;
8763

8864
public:
@@ -118,12 +94,6 @@ class style_provider
11894
styled<res::font> get_font_face_normal() const;
11995
};
12096

121-
} // namespace ruis
122-
123-
#include "styled.hpp"
124-
125-
namespace ruis {
126-
12797
template <typename value_type>
12898
styled<value_type> style_provider::get(style id) const
12999
{

src/ruis/style/styled.hpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,38 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2323

2424
#include <concepts>
2525

26-
#include "style_provider.hpp"
26+
#include <tml/tree.hpp>
27+
28+
#include "../resource_loader.hpp"
2729

2830
namespace ruis {
2931

32+
class style_provider;
33+
34+
namespace internal{
35+
class style_value_base
36+
{
37+
friend class ruis::style_provider;
38+
39+
protected:
40+
virtual void reload(
41+
const tml::forest& desc, //
42+
const ruis::resource_loader& loader
43+
) = 0;
44+
45+
style_value_base() = default;
46+
47+
public:
48+
style_value_base(const style_value_base&) = delete;
49+
style_value_base& operator=(const style_value_base&) = delete;
50+
51+
style_value_base(style_value_base&&) = delete;
52+
style_value_base& operator=(style_value_base&&) = delete;
53+
54+
virtual ~style_value_base() = default;
55+
};
56+
}
57+
3058
/**
3159
* @brief A styled value.
3260
* This class is used to represent a value which can be either a direct value or a reference to a style value.
@@ -53,7 +81,7 @@ class styled
5381
>;
5482

5583
private:
56-
class style_value : public style_provider::style_value_base
84+
class style_value : public internal::style_value_base
5785
{
5886
template <typename checked_type, typename = void>
5987
struct has_static_member_make_from : public std::false_type {};

0 commit comments

Comments
 (0)