5#ifndef MOLYBDEN_JS_VALUE_CONVERTER_HPP
6#define MOLYBDEN_JS_VALUE_CONVERTER_HPP
10#include "molybden/js/js_array.hpp"
11#include "molybden/js/js_value.hpp"
20struct IsJsProxyObject;
23using EnableIfJsObject =
typename std::enable_if<IsJsObject<T>::Value()>::type;
26using EnableIfJsProxyObject =
27 typename std::enable_if<IsJsProxyObject<T>::Value()>::type;
47template <
class T,
class V =
void>
48class JsValueConverter;
51class JsValueConverter<double> {
53 static double convert(
const JsValue& value);
54 static bool isConvertible(
const JsValue& value);
55 static std::string convertErrorTypeInfo();
59class JsValueConverter<float> {
61 static float convert(
const JsValue& value);
62 static bool isConvertible(
const JsValue& value);
63 static std::string convertErrorTypeInfo();
67class JsValueConverter<T, typename std::enable_if<std::is_integral<T>::value>::type> {
69 static T convert(
const JsValue& value);
70 static bool isConvertible(
const JsValue& value);
71 static std::string convertErrorTypeInfo();
75class JsValueConverter<std::string> {
77 static std::string convert(
const JsValue& value);
78 static bool isConvertible(
const JsValue& value);
79 static std::string convertErrorTypeInfo();
83class JsValueConverter<bool> {
85 static bool convert(
const JsValue& value);
86 static bool isConvertible(
const JsValue& value);
87 static std::string convertErrorTypeInfo();
91class JsValueConverter<JsValue> {
93 static JsValue convert(
const JsValue& value);
94 static JsValue convert(JsValue&& value);
95 static constexpr bool isConvertible(
const JsValue& value) {
return true;}
96 static std::string convertErrorTypeInfo();
100class JsValueConverter<std::shared_ptr<T>, EnableIfJsObject<T>> {
106 static std::shared_ptr<T> convert(
const JsValue& value);
107 static bool isConvertible(
const JsValue& value);
108 static std::string convertErrorTypeInfo();
112class JsValueConverter<std::shared_ptr<T>, EnableIfJsProxyObject<T>> {
118 static std::shared_ptr<T> convert(
const JsValue& value);
119 static bool isConvertible(
const JsValue& value);
120 static std::string convertErrorTypeInfo();
130class IndexedJsValueConverter {
132 explicit IndexedJsValueConverter(
const std::vector<JsValue>& values);
137 template <std::
size_t I>
138 using TypeOfArg =
typename std::remove_reference<decltype(std::get<I>(
139 std::tuple<T...>()))>::type;
149 template <std::
size_t I>
150 TypeOfArg<I> convert();
159 template <std::
size_t I>
160 bool isConvertible();
170 template <std::
size_t I>
171 std::string convertErrorTypeInfo();
174 const std::vector<JsValue>& values_;