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<std::shared_ptr<T>, EnableIfJsObject<T>> {
97 static std::shared_ptr<T> convert(
const JsValue& value);
98 static bool isConvertible(
const JsValue& value);
99 static std::string convertErrorTypeInfo();
103class JsValueConverter<std::shared_ptr<T>, EnableIfJsProxyObject<T>> {
109 static std::shared_ptr<T> convert(
const JsValue& value);
110 static bool isConvertible(
const JsValue& value);
111 static std::string convertErrorTypeInfo();
121class IndexedJsValueConverter {
123 explicit IndexedJsValueConverter(
const std::vector<JsValue>& values);
128 template <std::
size_t I>
129 using TypeOfArg =
typename std::remove_reference<decltype(std::get<I>(
130 std::tuple<T...>()))>::type;
140 template <std::
size_t I>
141 TypeOfArg<I> convert();
150 template <std::
size_t I>
151 bool isConvertible();
161 template <std::
size_t I>
162 std::string convertErrorTypeInfo();
165 const std::vector<JsValue>& values_;