Molybden API
Loading...
Searching...
No Matches
js_accessible_method_impl.hpp
1// Copyright (c) 2000-2023 TeamDev Ltd. All rights reserved.
2// TeamDev PROPRIETARY and CONFIDENTIAL.
3// Use is subject to license terms.
4
5#include <tuple>
6#include <vector>
7
8#include "molybden/js/js_return_value.hpp"
9
10namespace molybden {
11namespace internal {
12
13template <class C, class R, class... T>
14using MethodSignature = R (C::*)(T...);
15
16template <class C, class R, class... T>
17class JsAccessibleMethodImplBase : public JsAccessibleMethod {
18 public:
19 JsAccessibleMethodImplBase(C* object, MethodSignature<C, R, T...> method);
20
21 // JsAccessibleMethod
22 JsReturnValue call(const std::vector<JsValue>& values) override;
23
24 protected:
25 R callInternal(T... args);
26
27 private:
28 template <std::size_t... I>
29 JsReturnValue checkedCall(const std::vector<JsValue>& values,
30 index_sequence<I...>);
31 virtual JsValue wrappedCall(T... args) = 0;
32
33 private:
34 MethodSignature<C, R, T...> call_;
35 C* object_;
36};
37
38template <class C, class R, class... T>
39class JsAccessibleMethodImpl : public JsAccessibleMethodImplBase<C, R, T...> {
40 public:
41 JsAccessibleMethodImpl(C* object, MethodSignature<C, R, T...> method);
42
43 // JsAccessibleMethodImplBase<C, R, T...>
44 JsValue wrappedCall(T... args) override;
45};
46
47template <class C, class... T>
48class JsAccessibleMethodImpl<C, void, T...>
49 : public JsAccessibleMethodImplBase<C, void, T...> {
50 public:
51 JsAccessibleMethodImpl(C* object, MethodSignature<C, void, T...> method);
52
53 // JsAccessibleMethodImplBase<C, void, T...>
54 JsValue wrappedCall(T... args) override;
55};
56
57} // namespace internal
58} // namespace molybden