v8toolkit  0.0.1
Utility library for embedding V8 Javascript engine in a c++ program
Classes | Namespaces | Macros | Functions | Variables
casts.hpp File Reference
#include <assert.h>
#include <type_traits>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <deque>
#include <array>
#include <memory>
#include <utility>
#include <set>
#include "v8.h"
#include "wrapped_class_base.h"
#include "v8helpers.h"
Include dependency graph for casts.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  v8toolkit::always_false< T >
 
struct  v8toolkit::is_wrapped_type< T, class >
 
struct  v8toolkit::is_wrapped_type< T, std::enable_if_t< std::is_base_of< v8toolkit::WrappedClassBase, T >::value > >
 
struct  v8toolkit::CastToNative< T, class >
 
struct  v8toolkit::cast_to_native_supports_default_value< T, class >
 
struct  v8toolkit::cast_to_native_supports_default_value< T, void_t< std::result_of_t< CastToNative< T >(v8::Isolate *)> > >
 
struct  v8toolkit::CastToNative< T, class >
 
struct  v8toolkit::CastToNative< void >
 
struct  v8toolkit::CastToNative< std::tuple< Ts... > >
 
struct  v8toolkit::CastToNative< T const, std::enable_if_t<!is_wrapped_type_v< T > > >
 
struct  v8toolkit::CastToNative< T const &, std::enable_if_t<!is_wrapped_type_v< T > > >
 
struct  v8toolkit::CastToNative< T &&, std::enable_if_t<!is_wrapped_type_v< T > > >
 
struct  v8toolkit::v8toolkit::CastToNative< std::pair< FirstT, SecondT > >
 
struct  v8toolkit::CastToNative< v8::Local< v8::Function > >
 
struct  v8toolkit::CastToNative< char * >
 
struct  v8toolkit::CastToNative< const char * >
 
struct  v8toolkit::CastToNative< std::vector< T, Rest... >, std::enable_if_t< std::is_copy_constructible< T >::value > >
 
struct  v8toolkit::CastToNative< std::vector< T, Rest... > &&, std::enable_if_t<!is_wrapped_type_v< std::vector< T, Rest... > > > >
 
struct  v8toolkit::CastToNative< std::set< T, Rest... >, std::enable_if_t<!is_wrapped_type_v< std::set< T, Rest... > > > >
 
struct  v8toolkit::value && !is_wrapped_type_v< T > >>
 
struct  v8toolkit::CastToNative< v8::Local< T > >
 
struct  v8toolkit::CastToNative< std::map< Key, Value, Args... > >
 
struct  v8toolkit::CastToNative< std::multimap< Key, Value, Args... > >
 
struct  v8toolkit::CastToJS< T, class >
 
struct  v8toolkit::CastToJS< T &, std::enable_if_t<!is_wrapped_type_v< T > > >
 
struct  v8toolkit::CastToJS< T *, std::enable_if_t<!is_wrapped_type_v< T > > >
 
struct  v8toolkit::CastToJS< T const, std::enable_if_t<!is_wrapped_type_v< T > > >
 
struct  v8toolkit::CastToJS< T ** >
 
struct  v8toolkit::CastToJS< std::function< R(Params...)> >
 
struct  v8toolkit::CastToJS< v8::Local< T > >
 
struct  v8toolkit::CastToJS< v8::Global< T > >
 
struct  v8toolkit::CastToJS< std::pair< T1, T2 > >
 
struct  v8toolkit::CastToJS< std::vector< T, Rest... > >
 
struct  v8toolkit::CastToJS< std::list< U, Rest... > >
 
struct  v8toolkit::CastToJS< std::map< KeyType, ValueType, Rest... > >
 
struct  v8toolkit::CastToJS< std::multimap< A, B, Rest... > >
 
struct  v8toolkit::CastToJS< std::unordered_map< A, B, Rest... > >
 
struct  v8toolkit::CastToJS< std::deque< T, Rest... > >
 
struct  v8toolkit::CastToJS< std::array< T, N > >
 
struct  v8toolkit::CastToJS< std::unique_ptr< T, Rest... >, std::enable_if_t<!is_wrapped_type_v< T > > >
 
struct  v8toolkit::CastToJS< std::unique_ptr< T, Rest... > &, std::enable_if_t<!is_wrapped_type_v< std::unique_ptr< T, Rest... > > > >
 
struct  v8toolkit::CastToJS< std::unique_ptr< T, Rest... > const &, std::enable_if_t<!is_wrapped_type_v< std::unique_ptr< T, Rest... > const > > >
 
struct  v8toolkit::CastToJS< std::shared_ptr< T > >
 
struct  v8toolkit::CastTupleToJS< position, T >
 
struct  v8toolkit::CastTupleToJS< 0, std::tuple< Args... > >
 
struct  v8toolkit::CastTupleToJS< position, std::tuple< Args... > >
 
struct  v8toolkit::CastToJS< std::tuple< Args... > >
 
struct  v8toolkit::CastToJS< std::set< T, Rest... > >
 
struct  v8toolkit::CastToNative< std::function< ReturnT(Args...)> >
 

Namespaces

 v8toolkit
 

Macros

#define V8TOOLKIT_COMMA   ,
 
#define HANDLE_FUNCTION_VALUES
 
#define CAST_TO_NATIVE_CLASS_ONLY(TYPE)
 
#define CAST_TO_NATIVE_CODE(TYPE, CODE)   TYPE CastToNative<TYPE>::operator()(v8::Isolate * isolate, v8::Local<v8::Value> value) const CODE
 
#define CAST_TO_NATIVE(TYPE, CODE)
 
#define CAST_TO_JS(TYPE, FUNCTION_BODY)
 

Functions

 v8toolkit::CAST_TO_NATIVE (bool,{HANDLE_FUNCTION_VALUES;return static_cast< bool >(value->ToBoolean() ->Value());})
 
 v8toolkit::CAST_TO_NATIVE (long long,{HANDLE_FUNCTION_VALUES;return static_cast< long long >(value->ToInteger() ->Value());})
 
 v8toolkit::CAST_TO_NATIVE (unsigned long long,{HANDLE_FUNCTION_VALUES;return static_cast< unsigned long long >(value->ToInteger() ->Value());})
 
 v8toolkit::CAST_TO_NATIVE (long,{HANDLE_FUNCTION_VALUES;return static_cast< long >(value->ToInteger() ->Value());})
 
 v8toolkit::CAST_TO_NATIVE (unsigned long,{HANDLE_FUNCTION_VALUES;return static_cast< unsigned long >(value->ToInteger() ->Value());})
 
 v8toolkit::CAST_TO_NATIVE (int,{HANDLE_FUNCTION_VALUES;return static_cast< int >(value->ToInteger() ->Value());})
 
 v8toolkit::CAST_TO_NATIVE (unsigned int,{HANDLE_FUNCTION_VALUES;return static_cast< unsigned int >(value->ToInteger() ->Value());})
 
 v8toolkit::CAST_TO_NATIVE (short,{HANDLE_FUNCTION_VALUES;return static_cast< short >(value->ToInteger() ->Value());})
 
 v8toolkit::CAST_TO_NATIVE (unsigned short,{HANDLE_FUNCTION_VALUES;return static_cast< unsigned short >(value->ToInteger() ->Value());})
 
 v8toolkit::CAST_TO_NATIVE (char,{HANDLE_FUNCTION_VALUES;return static_cast< char >(value->ToInteger() ->Value());})
 
 v8toolkit::CAST_TO_NATIVE (unsigned char,{HANDLE_FUNCTION_VALUES;return static_cast< unsigned char >(value->ToInteger() ->Value());})
 
 v8toolkit::CAST_TO_NATIVE (wchar_t,{HANDLE_FUNCTION_VALUES;return static_cast< wchar_t >(value->ToInteger() ->Value());})
 
 v8toolkit::CAST_TO_NATIVE (char16_t,{HANDLE_FUNCTION_VALUES;return static_cast< char16_t >(value->ToInteger() ->Value());})
 
 v8toolkit::CAST_TO_NATIVE (char32_t,{HANDLE_FUNCTION_VALUES;return static_cast< char32_t >(value->ToInteger() ->Value());})
 
template<class... Ts, std::size_t... Is>
std::tuple< Ts... > v8toolkit::cast_to_native_tuple_helper (v8::Isolate *isolate, v8::Local< v8::Array > array, std::tuple< Ts... >, std::index_sequence< Is... >)
 
template<template< class, class > class ContainerTemplate, class FirstT , class SecondT >
ContainerTemplate< FirstT, SecondT > v8toolkit::pair_type_helper (v8::Isolate *isolate, v8::Local< v8::Value > value)
 
 v8toolkit::CAST_TO_NATIVE (float,{HANDLE_FUNCTION_VALUES;return static_cast< float >(value->ToNumber() ->Value());})
 
 v8toolkit::CAST_TO_NATIVE (double,{HANDLE_FUNCTION_VALUES;return static_cast< double >(value->ToNumber() ->Value());})
 
 v8toolkit::CAST_TO_NATIVE (long double,{HANDLE_FUNCTION_VALUES;return static_cast< long double >(value->ToNumber() ->Value());})
 
 v8toolkit::CAST_TO_NATIVE (std::string,{HANDLE_FUNCTION_VALUES;return std::string(*v8::String::Utf8Value(value));})
 
template<template< class, class... > class VectorTemplate, class T , class... Rest>
auto v8toolkit::vector_type_helper (v8::Isolate *isolate, v8::Local< v8::Value > value) -> VectorTemplate< std::remove_reference_t< std::result_of_t< CastToNative< T >(v8::Isolate *, v8::Local< v8::Value >)>>, Rest... >
 
template<template< class, class... > class SetTemplate, class T , class... Rest>
auto v8toolkit::set_type_helper (v8::Isolate *isolate, v8::Local< v8::Value > value) -> SetTemplate< std::remove_reference_t< std::result_of_t< CastToNative< T >(v8::Isolate *, v8::Local< v8::Value >)>>, Rest... >
 
template<template< class, class, class... > class ContainerTemplate, class Key , class Value , class... Rest>
ContainerTemplate< Key, Value, Rest... > v8toolkit::map_type_helper (v8::Isolate *isolate, v8::Local< v8::Value > value)
 
template<template< class, class, class... > class ContainerTemplate, class Key , class Value , class... Rest>
ContainerTemplate< Key, Value, Rest... > v8toolkit::multimap_type_helper (v8::Isolate *isolate, v8::Local< v8::Value > value)
 
 v8toolkit::CAST_TO_JS (bool,{return v8::Boolean::New(isolate, value);})
 
 v8toolkit::CAST_TO_JS (char,{return v8::Integer::New(isolate, value);})
 
 v8toolkit::CAST_TO_JS (unsigned char,{return v8::Integer::New(isolate, value);})
 
 v8toolkit::CAST_TO_JS (wchar_t,{return v8::Number::New(isolate, value);})
 
 v8toolkit::CAST_TO_JS (char16_t,{return v8::Integer::New(isolate, value);})
 
 v8toolkit::CAST_TO_JS (char32_t,{return v8::Integer::New(isolate, value);})
 
 v8toolkit::CAST_TO_JS (short,{return v8::Integer::New(isolate, value);})
 
 v8toolkit::CAST_TO_JS (int,{return v8::Number::New(isolate, value);})
 
 v8toolkit::CAST_TO_JS (unsigned int,{return v8::Number::New(isolate, value);})
 
 v8toolkit::CAST_TO_JS (long,{return v8::Number::New(isolate, value);})
 
 v8toolkit::CAST_TO_JS (long long,{return v8::Number::New(isolate, static_cast< double >(value));})
 
 v8toolkit::CAST_TO_JS (unsigned long long,{return v8::Number::New(isolate, static_cast< double >(value));})
 
 v8toolkit::CAST_TO_JS (float,{return v8::Number::New(isolate, value);})
 
 v8toolkit::CAST_TO_JS (double,{return v8::Number::New(isolate, value);})
 
 v8toolkit::CAST_TO_JS (std::string,{return v8::String::NewFromUtf8(isolate, value.c_str(), v8::String::kNormalString, value.length());})
 
 v8toolkit::CAST_TO_JS (char *,{return v8::String::NewFromUtf8(isolate, value);})
 
 v8toolkit::CAST_TO_JS (char const *,{return v8::String::NewFromUtf8(isolate, value);})
 
template<template< class, class, class... > class MapTemplate, class KeyType , class ValueType , class ReferenceTypeIndicator , class... Rest>
v8::Local< v8::Value > v8toolkit::cast_to_js_map_helper (v8::Isolate *isolate, MapTemplate< KeyType, ValueType, Rest... > const &map)
 
template<template< class... > class VectorTemplate, class ValueType , class... Rest>
v8::Local< v8::Value > v8toolkit::cast_to_js_vector_helper (v8::Isolate *isolate, VectorTemplate< std::remove_reference_t< ValueType >, Rest... > const &vector)
 
template<template< class, class, class... > class MultiMapLike, class A , class B , class... Rest>
v8::Local< v8::Object > v8toolkit::casttojs_multimaplike (v8::Isolate *isolate, MultiMapLike< A, B, Rest... > const &map)
 

Variables

template<class T >
constexpr bool v8toolkit::always_false_v = always_false<T>::value
 
template<class T >
constexpr bool v8toolkit::is_wrapped_type_v = is_wrapped_type<T>::value
 
template<class T >
constexpr bool v8toolkit::cast_to_native_supports_default_value_v = cast_to_native_supports_default_value<T>::value
 
template<class T >
constexpr bool v8toolkit::is_wrapped_typeish_v
 

Class Documentation

struct v8toolkit::CastToJS

template<typename T, class = void>
struct v8toolkit::CastToJS< T, class >

Casts from a native type to a boxed Javascript type

Definition at line 507 of file casts.hpp.

struct v8toolkit::CastTupleToJS

template<int position, class T>
struct v8toolkit::CastTupleToJS< position, T >

Definition at line 906 of file casts.hpp.

Macro Definition Documentation

#define V8TOOLKIT_COMMA   ,

Definition at line 65 of file casts.hpp.

#define HANDLE_FUNCTION_VALUES
#define CAST_TO_NATIVE_CLASS_ONLY (   TYPE)
Value:
template<> \
TYPE operator()(v8::Isolate * isolate, v8::Local<v8::Value> value) const; \
static constexpr bool callable(){return true;} /* It wouldn't be selected if it weren't callable */ \
};

Definition at line 77 of file casts.hpp.

#define CAST_TO_NATIVE_CODE (   TYPE,
  CODE 
)    TYPE CastToNative<TYPE>::operator()(v8::Isolate * isolate, v8::Local<v8::Value> value) const CODE

Definition at line 85 of file casts.hpp.

#define CAST_TO_NATIVE (   TYPE,
  CODE 
)
Value:
inline CAST_TO_NATIVE_CODE(TYPE, CODE)
#define CAST_TO_NATIVE_CODE(TYPE, CODE)
Definition: casts.hpp:85
#define CAST_TO_NATIVE_CLASS_ONLY(TYPE)
Definition: casts.hpp:77

Definition at line 89 of file casts.hpp.

#define CAST_TO_JS (   TYPE,
  FUNCTION_BODY 
)
Value:
template<> \
v8::Local<v8::Value> operator()(v8::Isolate * isolate, TYPE const & value) const FUNCTION_BODY \
};

Definition at line 96 of file casts.hpp.