-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDicomDirEntry.cpp
55 lines (44 loc) · 1.79 KB
/
DicomDirEntry.cpp
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
#include "DicomDirEntry.hpp"
#include "Arguments.hpp"
Nan::Persistent<v8::Function> bindings::DicomDirEntry::constructor;
void bindings::DicomDirEntry::Init(v8::Local<v8::Object> exports) {
auto tpl = Nan::New<v8::FunctionTemplate>(New);
tpl->SetClassName(Nan::New("DicomDirEntry").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
Nan::SetPrototypeMethod(tpl,"getNextEntry",GetNextEntry);
Nan::SetPrototypeMethod(tpl,"hasNextEntry",HasNextEntry);
constructor.Reset(Nan::GetFunction(tpl).ToLocalChecked());
Nan::Set(exports,Nan::New("DicomDirEntry").ToLocalChecked(),Nan::GetFunction(tpl).ToLocalChecked());
}
NAN_METHOD(bindings::DicomDirEntry::New) {
auto* e = new DicomDirEntry();
e->Wrap(info.This());
info.GetReturnValue().Set(info.This());
}
bindings::DicomDirEntry::DicomDirEntry(): value(nullptr) {
}
bindings::DicomDirEntry::~DicomDirEntry() {
delete value;
}
NAN_METHOD(bindings::DicomDirEntry::HasNextEntry){
DicomDirEntry *entry;
if(!Arguments::Unwrap(info.This(),entry)){
Nan::ThrowError("Method called under invalid context");
return;
}
info.GetReturnValue().Set(Nan::New(entry->value->hasNextEntry()));
}
NAN_METHOD(bindings::DicomDirEntry::GetNextEntry){
DicomDirEntry *entry, *nextEntry;
if(!Arguments::Unwrap(info.This(),entry)){
Nan::ThrowError("Method called under invalid context");
return;
}
auto nextEntryJs = Nan::NewInstance(Nan::New(bindings::DicomDirEntry::constructor),0,nullptr).ToLocalChecked();
if(!Arguments::Unwrap(nextEntryJs,nextEntry)){
Nan::ThrowError("Failed to create new DicomDirEntry instance");
return;
}
nextEntry->value = new imebra::DicomDirEntry(entry->value->getNextEntry());
info.GetReturnValue().Set(nextEntryJs);
}