• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright JS Foundation and other contributors, http://js.foundation
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef _JERRYSCRIPT_MBED_EVENT_LOOP_BOUND_CALLBACK_H
16 #define _JERRYSCRIPT_MBED_EVENT_LOOP_BOUND_CALLBACK_H
17 
18 #include "Callback.h"
19 
20 namespace mbed {
21 namespace js {
22 
23 template<typename T>
24 class BoundCallback;
25 
26 template<typename R, typename A0>
27 class BoundCallback<R(A0)> {
28  public:
BoundCallback(Callback<R (A0)> cb,A0 a0)29     BoundCallback(Callback<R(A0)> cb, A0 a0) : a0(a0), cb(cb) { }
30 
call()31     void call() {
32         cb(a0);
33     }
34 
35     operator Callback<void()>() {
36         Callback<void()> cb(this, &BoundCallback::call);
37         return cb;
38     }
39 
40  private:
41     A0 a0;
42     Callback<R(A0)> cb;
43 };
44 
45 template<typename R, typename A0, typename A1>
46 class BoundCallback<R(A0, A1)> {
47  public:
BoundCallback(Callback<R (A0,A1)> cb,A0 a0,A1 a1)48     BoundCallback(Callback<R(A0, A1)> cb, A0 a0, A1 a1) : a0(a0), a1(a1), cb(cb) { }
49 
call()50     void call() {
51         cb(a0, a1);
52     }
53 
54     operator Callback<void()>() {
55         Callback<void()> cb(this, &BoundCallback::call);
56         return cb;
57     }
58 
59  private:
60     A0 a0;
61     A0 a1;
62 
63     Callback<R(A0, A1)> cb;
64 };
65 
66 template<typename R, typename A0, typename A1, typename A2>
67 class BoundCallback<R(A0, A1, A2)> {
68  public:
BoundCallback(Callback<R (A0,A1,A2)> cb,A0 a0,A1 a1,A2 a2)69     BoundCallback(Callback<R(A0, A1, A2)> cb, A0 a0, A1 a1, A2 a2) : a0(a0), a1(a1), a2(a2), cb(cb) { }
70 
call()71     void call() {
72         cb(a0, a1, a2);
73     }
74 
75     operator Callback<void()>() {
76         Callback<void()> cb(this, &BoundCallback::call);
77         return cb;
78     }
79 
80  private:
81     A0 a0;
82     A1 a1;
83     A2 a2;
84 
85     Callback<R(A0, A1, A2)> cb;
86 };
87 
88 template<typename R, typename A0, typename A1, typename A2, typename A3>
89 class BoundCallback<R(A0, A1, A2, A3)> {
90  public:
BoundCallback(Callback<R (A0,A1,A2,A3)> cb,A0 a0,A1 a1,A2 a2,A3 a3)91     BoundCallback(Callback<R(A0, A1, A2, A3)> cb, A0 a0, A1 a1, A2 a2, A3 a3) : a0(a0), a1(a1), a2(a2), a3(a3), cb(cb) { }
92 
call()93     void call() {
94         cb(a0, a1, a2, a3);
95     }
96 
97     operator Callback<void()>() {
98         Callback<void()> cb(this, &BoundCallback::call);
99         return cb;
100     }
101 
102  private:
103     A0 a0;
104     A1 a1;
105     A2 a2;
106     A3 a3;
107 
108     Callback<R(A0, A1, A2, A3)> cb;
109 };
110 
111 }  // namespace js
112 }  // namespace mbed
113 
114 #endif  // _JERRYSCRIPT_MBED_EVENT_LOOP_BOUND_CALLBACK_H
115