7#include "../utility/utility.hpp"
8#include "../codec/codec.hpp"
9#include "../macros.hpp"
10#include <unordered_map>
14hi_export_module(hikogui.formula.formula_evaluation_context);
16namespace hi {
inline namespace v1 {
22 ssize_t output_disable_count = 0;
37 this->first = count == 0;
40 this->last = count == (size - 1);
54 if (output_disable_count == 0) {
79 hi_assert(output_disable_count > 0);
80 output_disable_count--;
85 output_disable_count++;
95 hi_assert(
ssize(loop_stack) > 0);
101 local_stack.emplace_back();
107 hi_assert(local_stack.size() > 0);
108 local_stack.pop_back();
114 return local_stack.size() > 0;
117 scope
const &locals()
const
119 hi_assert(has_locals());
120 return local_stack.back();
125 hi_assert(has_locals());
126 return local_stack.back();
129 [[
nodiscard]] datum
const &loop_get(std::string_view name)
const
131 hi_assert(name.size() > 0);
132 if (name.back() ==
'$') {
133 throw operation_error(std::format(
"Invalid loop variable '{}'", name));
141 throw operation_error(std::format(
"Accessing loop variable {} while not in loop", name));
154 throw operation_error(std::format(
"Accessing loop variable {} only available in #for loops", name));
159 throw operation_error(std::format(
"Accessing loop variable {} only available in #for loops", name));
163 throw operation_error(std::format(
"Unknown loop variable {}", name));
169 hi_assert(name.
size() > 0);
171 if (name[0] ==
'$') {
172 return loop_get(name);
176 hilet i = locals().
find(name);
177 if (i != locals().
end()) {
182 hilet
j = globals.
find(name);
183 if (
j != globals.
end()) {
187 throw operation_error(std::format(
"Could not find {} in local or global scope.", name));
192 hi_assert(name.
size() > 0);
195 hilet i = locals().
find(name);
196 if (i != locals().
end()) {
201 hilet
j = globals.
find(name);
202 if (
j != globals.
end()) {
206 throw operation_error(std::format(
"Could not find {} in local or global scope.", name));
212 locals()[name] = std::forward<T>(value);
216 void set_global(
std::string const &name, T &&value)
218 globals[name] = std::forward<T>(value);
221 datum &set(
std::string const &name, datum
const &value)
224 return locals()[name] = value;
226 return globals[name] = value;
@ end
Start from the end of the file.
@ write
Allow write access to a file.
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
std::ptrdiff_t ssize_t
Signed size/index into an array.
Definition misc.hpp:33
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
A dynamic data type.
Definition datum.hpp:212
Definition formula_evaluation_context.hpp:18
ssize_t output_size() const noexcept
Get the size of the output.
Definition formula_evaluation_context.hpp:62
void set_output_size(ssize_t new_size) noexcept
Set the size of the output.
Definition formula_evaluation_context.hpp:70
Definition formula_evaluation_context.hpp:27
T emplace_back(T... args)