6#pragma clang diagnostic push
7#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
8#pragma clang diagnostic ignored "-Wold-style-cast"
9#include <boost/describe.hpp>
10#include <boost/mp11/algorithm.hpp>
11#pragma clang diagnostic pop
19#include <unordered_map>
65 class Bases = boost::describe::describe_bases<T, boost::describe::mod_any_access>,
66 class Members = boost::describe::describe_members<T, boost::describe::mod_any_access>,
67 class Enable = std::enable_if_t<!std::is_union_v<T>>>
138 template <
typename T>
148 template <
typename T>
158 template <
typename T>
168 template <
typename T>
178 template <
typename T>
188 template <
typename T>
198 template <
typename T>
202#if __POINTER_WIDTH__ == 64
221 throw std::runtime_error(
"Use -sMEMORY64 to convert long long to val");
225 throw std::runtime_error(
"Use -sMEMORY64 to convert unsigned long long to val");
235 return Nui::val::undefined();
245 template <
typename... Ts>
250 template <
typename T,
class Members>
251 requires(!std::is_union_v<T>)
262 template <
typename T,
class Bases,
class Members>
263 requires(!std::is_union_v<T>)
272 template <
typename T,
class Members>
273 requires(!std::is_union_v<T> && !boost::describe::has_describe_bases<T>::value)
283 template <
typename T>
284 requires Fundamental<T>
302 template <
typename T>
328 template <
typename T>
338 template <
typename T>
339 requires Fundamental<T>
349 template <
typename T>
359 template <
typename T>
369 template <
typename T>
373#if __POINTER_WIDTH__ == 64
392 throw std::invalid_argument(
"Use -sMEMORY64 to convert from val to long long");
397 throw std::invalid_argument(
"Use -sMEMORY64 to convert from val to unsigned long long");
401 template <
typename T,
class Bases,
class Members,
class Enable>
406 boost::mp11::mp_for_each<Bases>([&](
auto&& base) {
407 using type =
typename std::decay_t<
decltype(base)>::type;
411 boost::mp11::mp_for_each<Members>([&](
auto&& memAccessor) {
418 template <
typename T>
421 return option ?
convertToVal(*option) : Nui::val::undefined();
423 template <
typename T>
424 requires Fundamental<T>
447 return Nui::val{std::string{value}};
449 template <
typename T>
452 Nui::val result = Nui::val::array();
453 for (
auto const& element : vector)
457 template <
typename T>
462 template <
typename T>
465 Nui::val result = Nui::val::object();
466 for (
auto const& [key, value] : map)
470 template <
typename T>
473 Nui::val result = Nui::val::object();
474 for (
auto const& [key, value] : map)
478 template <
typename T>
483 return Nui::val::null();
485 template <
typename T>
490 return Nui::val::null();
492 template <
typename... Ts>
502 template <
typename T>
511#if __POINTER_WIDTH__ == 64
522 template <
typename T,
class Members = boost::describe::describe_members<T, boost::describe::mod_any_access>>
523 requires(!std::is_union_v<T> && !boost::describe::has_describe_bases<T>::value)
531 class Bases = boost::describe::describe_bases<T, boost::describe::mod_any_access>,
532 class Members = boost::describe::describe_members<T, boost::describe::mod_any_access>>
533 requires(!std::is_union_v<T> && boost::describe::has_describe_bases<T>::value)
536 boost::mp11::mp_for_each<Bases>([&](
auto&& base) {
537 using type =
typename std::decay_t<
decltype(base)>::type;
545 template <
typename T,
class Members = boost::describe::describe_members<T, boost::describe::mod_any_access>>
546 requires(!std::is_union_v<T>)
549 boost::mp11::mp_for_each<Members>([&](
auto&&
memAccessor) {
552 if constexpr (!Detail::IsOptional<std::decay_t<decltype(obj.*memAccessor.pointer)>>::value)
554 if (val[memAccessor.name].isNull() || val[memAccessor.name].isUndefined())
556 throw std::invalid_argument(
557 std::string{
"Expected member "} + memAccessor.name +
" to be non nullish");
559 convertFromVal(val[memAccessor.name], obj.*memAccessor.pointer);
573 throw std::invalid_argument(std::string{
"Missing required member "} +
memAccessor.name);
580 template <
typename T>
581 requires Fundamental<T>
588 str =
val.as<std::string>();
590 template <
typename T>
593 if (
val.isNull() ||
val.isUndefined())
594 option = std::nullopt;
604 value =
val.as<std::string>();
610 template <
typename T>
614 const auto length =
val[
"length"].as<std::size_t>();
615 vector.reserve(length);
616 for (std::size_t i = 0; i < length; ++i)
620 vector.push_back(std::move(value));
623 template <
typename T>
624 requires Fundamental<T>
627 vector = emscripten::convertJSArrayToNumberVector<T>(
val);
629 template <
typename T>
632 auto proxy = observed.
modify();
635 template <
typename T>
639 const auto keys = Nui::val::global(
"Object").call<
Nui::val>(
"keys",
val);
640 const auto length = keys[
"length"].as<std::size_t>();
641 for (std::size_t i = 0; i < length; ++i)
643 const auto key = keys[i].as<std::string>();
646 map.emplace(key, std::move(value));
650 template <
typename T>
651 requires Detail::HasFromVal<T>
654 from_val(
val, value);
657#if __POINTER_WIDTH__ == 64
658 inline void convertFromVal(
Nui::val const& val,
long long& value)
660 value = val.as<
long long>();
664 value =
val.as<
unsigned long long>();
ModificationProxy modify()
Can be used to make mutations to the underlying class that get commited when the returned proxy is de...
Definition observed_value.hpp:356
ContainedT & value()
Definition observed_value.hpp:372
Definition observed_value.hpp:1283
Concept detecting if a from_val function is provided for a type.
Definition val_conversion.hpp:50
Concept detecting if a to_val function is provided for a type.
Definition val_conversion.hpp:42
Definition concepts.hpp:11
void convertFromValObjImpl(Nui::val const &val, T &obj)
Definition val_conversion.hpp:547
static constexpr auto extractJsonMember(nlohmann::json const &json) -> decltype(auto)
Definition rpc_hub.hpp:29
Definition file_dialog.hpp:6
Nui::val convertToVal(T const &obj)
Converts a boost described class/struct to a Nui::val object.
Definition val_conversion.hpp:402
void convertFromVal(Nui::val const &val, T &obj)
Converts a Nui::val to a class/struct object.
Definition val_conversion.hpp:534
emscripten::val val
Definition val.hpp:5
Definition val_conversion.hpp:31