-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathenums.cpp
More file actions
46 lines (38 loc) · 782 Bytes
/
enums.cpp
File metadata and controls
46 lines (38 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "enums.hpp"
#include "util.hpp"
#include <napi_bind.hpp>
using napi_bind::ok;
using napi_bind::set_function;
enum unscoped_enum_t
{
A = 0,
B = 1,
C = 2,
// Intentional gap
E = 4,
Count
};
enum class scoped_enum_t
{
red = 20,
green,
blue
};
bool is_B(unscoped_enum_t value)
{
return value == unscoped_enum_t::B;
}
bool is_red(scoped_enum_t value)
{
return value == scoped_enum_t::red;
}
napi_value create_enums(napi_env env)
{
napi_value value;
ok(env, napi_create_object(env, &value));
set_function(env, value, "identity_unscoped", identity<unscoped_enum_t>);
set_function(env, value, "identity_scoped", identity<scoped_enum_t>);
set_function(env, value, "is_B", is_B);
set_function(env, value, "is_red", is_red);
return value;
}