5#ifndef MOLYBDEN_JS_VALUE_HPP
6#define MOLYBDEN_JS_VALUE_HPP
12#include "molybden/base/internal/void_t.hpp"
71 [[nodiscard]]
const std::string&
asString()
const;
113 explicit operator bool()
const;
123 template <
typename,
typename =
void>
124 struct IsFunctor : std::false_type {};
126 template <
typename T>
127 struct IsFunctor<T, internal::void_t<decltype(&T::operator())>>
131 using EnableIfNumber =
typename std::enable_if<
132 std::is_floating_point<T>::value || std::is_integral<T>::value,
135 using EnableIfFunction =
typename std::enable_if<
136 std::is_function<typename std::remove_pointer<T>::type>::value,
139 using EnableIfFunctor =
typename std::enable_if<IsFunctor<T>::value, T*>::type;
142 explicit JsValue(T value, EnableIfNumber<T> =
nullptr);
144 explicit JsValue(T value, EnableIfFunction<T> =
nullptr);
146 explicit JsValue(T& value, EnableIfFunctor<T> =
nullptr);
148 explicit JsValue(T&& value, EnableIfFunctor<T> =
nullptr);
149 explicit JsValue(
const char* value);
150 explicit JsValue(
const std::string& value);
151 explicit JsValue(std::string&& value);
153 explicit JsValue(
double value);
154 explicit JsValue(std::shared_ptr<JsObject> value);
155 explicit JsValue(std::shared_ptr<JsProxyObject> value);
157 std::unique_ptr<JsValueImpl> impl_;
A JavaScript value.
Definition js_value.hpp:44
static JsValue from(T &&value)
Constructs a JavaScript value from the convertible C++ one.
Definition js_value_detail.hpp:51
double asNumber() const
Returns the number that the value represents if it does, otherwise it should not be called.
std::shared_ptr< JsProxyObject > asJsProxyObject() const
Returns a JsProxyObject if the value represents a boolean value.
bool isNumber() const
Indicates if the given value represents a number.
JsValue()
Constructs an empty JsValue.
bool isString() const
Indicates if the given value represents a string.
bool isBool() const
Indicates if the given value represents a boolean.
std::shared_ptr< JsObject > asJsObject() const
Returns a JsObject if the value represents a boolean value.
bool isEmpty() const
Returns true if this JsValue does not hold a value (or, equally, represents null or undefined).
bool asBool() const
Returns the boolean that the value represents if it does, otherwise it should not be called.
const std::string & asString() const
Returns the string that the value represents if it does, otherwise it should not be called.