Molybden API
Loading...
Searching...
No Matches
molybden::JsValue Class Reference

A JavaScript value. More...

#include <js_value.hpp>

Public Member Functions

 JsValue ()
 Constructs an empty JsValue.
 
bool isEmpty () const
 Returns true if this JsValue does not hold a value (or, equally, represents null or undefined).
 
const std::string & asString () const
 Returns the string that the value represents if it does, otherwise it should not be called.
 
bool isString () const
 Indicates if the given value represents a string.
 
double asNumber () const
 Returns the number that the value represents if it does, otherwise it should not be called.
 
bool isNumber () const
 Indicates if the given value represents a number.
 
bool asBool () const
 Returns the boolean that the value represents if it does, otherwise it should not be called.
 
bool isBool () const
 Indicates if the given value represents a boolean.
 
std::shared_ptr< JsObjectasJsObject () const
 Returns a JsObject if the value represents a boolean value.
 
std::shared_ptr< JsProxyObjectasJsProxyObject () const
 Returns a JsProxyObject if the value represents a boolean value.
 
 operator bool () const
 Indicates whether the value is empty.
 
JsValueoperator= (const JsValue &other)
 
JsValueoperator= (JsValue &&other)
 
 JsValue (const JsValue &other)
 
 JsValue (JsValue &&other)
 

Static Public Member Functions

template<class T >
static JsValue from (T &&value)
 Constructs a JavaScript value from the convertible C++ one.
 

Detailed Description

A JavaScript value.

This class stores C++ values that are convertible to JavaScript ones.

The type mapping rules are the following:

C++ JavaScript
double Double
std::string String
bool Boolean
std::shared_ptr<SomeJsObject> Object
std::shared_ptr<JsArray> Array
std::shared_ptr<SomeJsProxyObject> Proxy Object

where

Other types cannot be automatically converted to JavaScript values, and first must be converted to one of the types above.

Member Function Documentation

◆ from()

template<class T >
JsValue molybden::JsValue::from ( T &&  value)
static

Constructs a JavaScript value from the convertible C++ one.

Template Parameters
Tthe type of the C++ value.
Parameters
valuethe C++ value.
Returns
JsValue that represents the given C++ value.

The documentation for this class was generated from the following files: