-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTagId.cpp
More file actions
77 lines (62 loc) · 2.33 KB
/
TagId.cpp
File metadata and controls
77 lines (62 loc) · 2.33 KB
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
#include "TagId.hpp"
#include "Arguments.hpp"
#include "imebra.hpp"
#include "DicomDefinitions.hpp"
using namespace bindings;
Nan::Persistent<v8::Function> TagId::constructor;
void TagId::Init(v8::Local<v8::Object> exports) {
auto tpl = Nan::New<v8::FunctionTemplate>(New);
tpl->SetClassName(Nan::New("TagId").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
Nan::SetPrototypeMethod(tpl,"getTagId",GetTagId);
Nan::SetPrototypeMethod(tpl,"getGroupId",GetGroupId);
Nan::SetPrototypeMethod(tpl,"getGroupOrder",GetGroupOrder);
constructor.Reset(Nan::GetFunction(tpl).ToLocalChecked());
Nan::Set(exports,Nan::New("TagId").ToLocalChecked(),Nan::GetFunction(tpl).ToLocalChecked());
}
NAN_METHOD(TagId::New) {
imebra::tagId_t id;
TagId* t;
if(DicomDefinitions::Decode(info[0],id)) {
t = new TagId(id);
} else {
uint_fast32_t groupId, groupOrder, tagId;
if(!Arguments::GetUint32(info[0],groupId)){
Nan::ThrowError("First argument must be a valid unsigned 32-bit integer");
return;
}
if(!Arguments::GetUint32(info[1],groupOrder)){
Nan::ThrowError("Second argument must be a valid unsigned 32-bit integer");
return;
}
if(!Arguments::GetUint32(info[2],tagId)){
Nan::ThrowError("Third argument must be a valid unsigned 32-bit integer");
return;
}
try {
t = new TagId(groupId,groupOrder,tagId);
} catch(std::exception& e){
Nan::ThrowError(e.what());
return;
}
}
t->Wrap(info.This());
info.GetReturnValue().Set(info.This());
}
NAN_METHOD(TagId::GetTagId){
UNWRAP(info.This(),TagId,tagId);
info.GetReturnValue().Set(Nan::New(tagId->value.getTagId()));
}
NAN_METHOD(TagId::GetGroupId){
UNWRAP(info.This(),TagId,tagId);
info.GetReturnValue().Set(Nan::New(tagId->value.getGroupId()));
}
NAN_METHOD(TagId::GetGroupOrder){
UNWRAP(info.This(),TagId,tagId);
info.GetReturnValue().Set(Nan::New(tagId->value.getGroupOrder()));
}
TagId::TagId(uint_fast32_t groupId, uint_fast32_t groupOrder, uint_fast32_t tagId): value(groupId,groupOrder,tagId){}
TagId::TagId(uint_fast32_t groupId, uint_fast32_t tagId): value(uint16_t(groupId),uint16_t(tagId)) {
}
TagId::TagId(imebra::tagId_t id): value(id) {
}