CYD-UI
A C++ library for building native graphic user interfaces
Loading...
Searching...
No Matches
dimension.cppm
Go to the documentation of this file.
1
5
8import std;
9import reflect;
10
11import fabric.logging;
13export import :types;
14export import :expression;
15export import :impl;
16
17export template <typename Type>
19public:
20 using value_type = Type;
23
25 : impl_(std::shared_ptr<dimension_impl<value_type>>{new dimension_impl<value_type>}) {
26 impl_->self = impl_;
27 }
29 explicit dimension(expression&& expr)
30 : impl_(std::shared_ptr<dimension_impl<value_type>>{new dimension_impl<value_type>}) {
31 impl_->self = impl_;
32 impl_->set_expression(expr);
33 impl_->mark_unknown();
34 }
35
36 explicit dimension(const expression& expr)
37 : impl_(std::shared_ptr<dimension_impl<value_type>>{new dimension_impl<value_type>}) {
38 impl_->self = impl_;
39 impl_->set_expression(expr);
40 impl_->mark_unknown();
41 }
42
43 explicit dimension(const std::shared_ptr<context>& ctx)
44 : impl_(std::shared_ptr<dimension_impl<value_type>>{new dimension_impl<value_type>{ctx}}) {
45 impl_->self = impl_;
46 impl_->mark_unknown();
47 }
49 explicit dimension(const std::shared_ptr<context>& ctx, expression&& expr)
50 : impl_(std::shared_ptr<dimension_impl<value_type>>{new dimension_impl<value_type>{ctx}}) {
51 impl_->self = impl_;
52 impl_->set_expression(expr);
53 impl_->mark_unknown();
54 }
55
56 dimension(const dimension& other)
57 : impl_(std::shared_ptr<dimension_impl<value_type>>{new dimension_impl<value_type>}) {
58 impl_->self = impl_;
59 impl_->set_expression(other.impl_->expr_);
60 impl_->value_ = other.impl_->value_;
61 set_context(other.get_context(), other.impl_->name_);
62 impl_->unknown_ = false;
63 if (other.impl_->unknown_) {
64 impl_->mark_unknown();
65 }
66 }
67
68 dimension& operator=(const dimension& other) {
69 impl_->set_expression(other.impl_->expr_);
70 impl_->value_ = other.impl_->value_;
71 impl_->unknown_ = false;
72 if (other.impl_->unknown_) {
73 impl_->mark_unknown();
74 }
75 return *this;
76 }
79 impl_->set_expression(expr);
80 impl_->mark_unknown();
81 return *this;
82 }
85 impl_->set_expression(expr);
86 impl_->mark_unknown();
87 return *this;
88 }
91 impl_->value_ = std::move(expr);
92 impl_->set_expression(std::move(expr));
93 impl_->unknown_ = false;
94 return *this;
95 }
96
98 impl_->value_ = expr;
99 impl_->set_expression(expr);
100 impl_->unknown_ = false;
101 return *this;
102 }
103
104 bool operator==(const dimension& rhl) const {
105 return get_expression() == rhl.get_expression();
106 }
108 bool is_set() const {
109 return impl_->is_set();
110 }
112 void clear() {
113 for (const auto& dep: impl_->expr_.dependencies_) {
114 dep->dependents_.erase({impl_});
115 }
116 impl_->clear();
117 }
118
119 const std::shared_ptr<context>& get_context() const {
120 return impl_->context_;
121 }
122 void set_context(const std::shared_ptr<context>& ctx, const std::string& name = "") {
123 impl_->set_context(ctx, name);
124 }
125
126 const expression& get_expression() const {
127 return impl_->expr_;
128 }
129
130 friend class dimension_impl<Type>;
133
134 template <typename S>
136 dimension<S>& dim_, const std::unordered_map<std::string, dimension<S>>& parameters
137 );
138 template <typename S>
140 typename dimension_impl<S>::sptr dim,
141 const std::unordered_map<std::string, dimension<S>>& parameters
142 );
143 template <typename S>
144 friend const S& get_value(dimension<S>& dim);
145 template <typename S>
146 friend const S& get_value(const dimension<S>& dim);
147 template <typename S>
148 friend bool find_cycle(
149 cycle_t<S>& cycle,
150 typename dimension_impl<S>::sptr start,
151 typename dimension_impl<S>::sptr head,
152 const std::unordered_map<std::string, dimension<S>>& global_parameters
153 );
154
155private:
156 const value_type& value() const {
157 return impl_->value_;
158 }
159
160 typename dimension_impl<value_type>::sptr impl() const {
161 return impl_;
162 }
163
164 [[meta(refl::eq_policy::shallow)]]
166};
168
171
172#define OPERATOR add
173#define ENUM ADDITION
174#include "operators_impl.inc"
175#undef OPERATOR
176#undef ENUM
177
178#define OPERATOR subtract
179#define ENUM SUBTRACTION
180#include "operators_impl.inc"
181#undef OPERATOR
182#undef ENUM
183
184#define OPERATOR multiply
185#define ENUM MULTIPLICATION
186#include "operators_impl.inc"
187#undef OPERATOR
188#undef ENUM
189
190#define OPERATOR divide
191#define ENUM DIVISION
192#include "operators_impl.inc"
193#undef OPERATOR
194#undef ENUM
195};
196
197export {
198#define OPERATOR +
199#define OP_FUNCTION add
200#include "operators.inc"
201#undef OPERATOR
202#undef OP_FUNCTION
203
204#define OPERATOR -
205#define OP_FUNCTION subtract
206#include "operators.inc"
207#undef OPERATOR
208#undef OP_FUNCTION
209
210#define OPERATOR *
211#define OP_FUNCTION multiply
212#include "operators.inc"
213#undef OPERATOR
214#undef OP_FUNCTION
215
216#define OPERATOR /
217#define OP_FUNCTION divide
218#include "operators.inc"
219#undef OPERATOR
220#undef OP_FUNCTION
221}
std::shared_ptr< dimension_impl > sptr
Definition impl.cppm:28
dimension & operator=(expression &&expr)
dimension & operator=(value_type &&expr)
friend compute_result_t< S > compute_dimension(dimension< S > &dim_, const std::unordered_map< std::string, dimension< S > > &parameters)
void set_context(const std::shared_ptr< context > &ctx, const std::string &name="")
dimension & operator=(const expression &expr)
dimension(const std::shared_ptr< context > &ctx)
const std::shared_ptr< context > & get_context() const
dimension(const dimension &other)
friend bool find_cycle(cycle_t< S > &cycle, typename dimension_impl< S >::sptr start, typename dimension_impl< S >::sptr head, const std::unordered_map< std::string, dimension< S > > &global_parameters)
friend bool evaluate_expression(typename dimension_impl< S >::sptr dim, const std::unordered_map< std::string, dimension< S > > &parameters)
dimension(expression &&expr)
const expression & get_expression() const
dimension(const expression &expr)
friend const S & get_value(dimension< S > &dim)
Definition api.cppm:24
bool operator==(const dimension &rhl) const
dimension & operator=(const dimension &other)
dimension(const std::shared_ptr< context > &ctx, expression &&expr)