FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
devisPattern/src/devisPattern.cpp at master · Devisjs/devisPattern · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
Devisjs
/
devisPattern
Public
Notifications
You must be signed in to change notification settings
Fork
2
Star
10
Code
Issues
0
Pull requests
25
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
devisPattern
/
src
/
devisPattern.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
123 lines (100 loc) · 3.9 KB
Breadcrumbs
devisPattern
/
src
/
devisPattern.cpp
Copy path
File metadata and controls
123 lines (100 loc) · 3.9 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
Copyright (c) 2016 Devis, MIT License
*/
#
include
"
node.h
"
#
include
"
devisPattern.hpp
"
//
TStrStrMap devisPattern::devisPattern::tMap;
namespace
devisPattern
{
using
v8::Context;
using
v8::Function;
using
v8::FunctionCallbackInfo;
using
v8::FunctionTemplate;
using
v8::Isolate;
using
v8::Local;
using
v8::Number;
using
v8::Object;
using
v8::Persistent;
using
v8::String;
using
v8::Value;
Persistent<Function> devisPattern::constructor;
devisPattern::devisPattern
(){
}
devisPattern::~devisPattern
() {
}
void
devisPattern::Init
(Local<Object> exports) {
Isolate* isolate = exports->
GetIsolate
();
Local<FunctionTemplate> tpl =
FunctionTemplate::New
(isolate, New);
tpl->
SetClassName
(
String::NewFromUtf8
(isolate,
"
devisPattern
"
));
tpl->
InstanceTemplate
()->
SetInternalFieldCount
(
1
);
NODE_SET_PROTOTYPE_METHOD
(tpl,
"
add
"
, add);
NODE_SET_PROTOTYPE_METHOD
(tpl,
"
list
"
, list);
NODE_SET_PROTOTYPE_METHOD
(tpl,
"
find
"
, find);
constructor.
Reset
(isolate, tpl->
GetFunction
());
exports->
Set
(
String::NewFromUtf8
(isolate,
"
devisPattern
"
),
tpl->
GetFunction
());
}
void
devisPattern::New
(
const
FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.
GetIsolate
();
if
(args.
IsConstructCall
()) {
devisPattern* obj =
new
devisPattern
();
obj->
Wrap
(args.
This
());
args.
GetReturnValue
().
Set
(args.
This
());
}
else
{
const
int
argc =
1
;
Local<Value> argv[argc] = { args[
0
] };
Local<Function> cons = Local<Function>::
New
(isolate, constructor);
Local<Context> context = isolate->
GetCurrentContext
();
Local<Object> instance =
cons->
NewInstance
(context, argc, argv).
ToLocalChecked
();
args.
GetReturnValue
().
Set
(instance);
}
}
void
devisPattern::NewInstance
(
const
FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.
GetIsolate
();
const
unsigned
argc =
1
;
Local<Value> argv[argc] = { args[
0
] };
Local<Function> cons = Local<Function>::
New
(isolate, constructor);
Local<Context> context = isolate->
GetCurrentContext
();
Local<Object> instance =
cons->
NewInstance
(context, argc, argv).
ToLocalChecked
();
args.
GetReturnValue
().
Set
(instance);
}
TStrStrMap::const_iterator
FindPath
(
const
TStrStrMap& map,
const
string& path) {
TStrStrMap::const_iterator i = map.
find
(path);
//
std::this_thread::sleep_for(std::chrono::seconds(1));
return
i;
}
string
liste
(TStrStrMap& tMap)
{
string res=
"
[
"
;
for
(it_type iterator = tMap.
begin
(); iterator != tMap.
end
(); iterator++) {
if
(iterator!=tMap.
begin
()) res+=
"
,
"
;
res+=iterator->
first
;
}
res+=
"
]
"
;
return
res;
}
int
TFind
(
const
TStrStrMap& map,
const
string& path) {
auto
i =
FindPath
(map, path);
if
(i != map.
end
())
return
i->
second
;
return
-
1
;
}
void
devisPattern::find
(
const
v8::FunctionCallbackInfo<v8::Value>& args)
{
int
data;
v8::String::Utf8Value
_path
(args[
0
]->
ToString
());
auto
ptr = Unwrap<devisPattern>(args.
Holder
());
data=
TFind
(ptr->
tMap
, *_path);
args.
GetReturnValue
().
Set
(data);
}
void
devisPattern::list
(
const
v8::FunctionCallbackInfo<v8::Value>& args)
{
Isolate* isolate=
Isolate::GetCurrent
();
auto
ptr = Unwrap<devisPattern>(args.
Holder
());
args.
GetReturnValue
().
Set
(
String::NewFromUtf8
(isolate,
liste
(ptr->
tMap
).
c_str
()));
}
void
devisPattern::add
(
const
FunctionCallbackInfo<Value>& args) {
auto
id=args[
1
]->
Int32Value
();
auto
ptr = Unwrap<devisPattern>(args.
Holder
());
v8::String::Utf8Value
_path
(args[
0
]->
ToString
());
ptr->
tMap
.
insert
(
TStrStrPair
(*_path,id));
}
}
Back
|
FazBrowse Home
|
New Git URL