-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbrowniangenerators.cpp
More file actions
97 lines (73 loc) · 2.23 KB
/
browniangenerators.cpp
File metadata and controls
97 lines (73 loc) · 2.23 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
Copyright (C) 2016 -2017 Jerry Jin
*/
#include <nan.h>
#include <string.h>
#include "browniangenerators.hpp"
#include <qlo/qladdindefines.hpp>
#include <qlo/browniangenerators.hpp>
#include <oh/objecthandler.hpp>
#include <oh/conversions/getobjectvector.hpp>
#include <qlo/valueobjects/vo_all.hpp>
#include <qlo/conversions/all.hpp>
#include "../loop.hpp"
void MTBrownianGeneratorFactoryWorker::Execute(){
try{
// Construct the Value Object
boost::shared_ptr<ObjectHandler::ValueObject> valueObject(
new QuantLibAddin::ValueObjects::qlMTBrownianGeneratorFactory(
mObjectID,
mSeed,
false
));
// Construct the Object
boost::shared_ptr<ObjectHandler::Object> object(
new QuantLibAddin::MTBrownianGeneratorFactory(
valueObject,
mSeed,
false
));
// Store the Object in the Repository
mReturnValue = ObjectHandler::Repository::instance().storeObject(mObjectID, object, false, valueObject);
}catch(const std::exception &e){
mError = e.what();
}catch (...){
mError = "unkown error";
}
}
void MTBrownianGeneratorFactoryWorker::HandleOKCallback(){
Nan::HandleScope scope;
Local<v8::Value> argv[2] = {
Nan::New<String>(mError).ToLocalChecked(),
Nan::New<String>(mReturnValue).ToLocalChecked()
};
callback->Call(2, argv);
}
NAN_METHOD(QuantLibNode::MTBrownianGeneratorFactory) {
// validate js arguments
if (info.Length() == 0 || !info[0]->IsString()) {
return Nan::ThrowError("ObjectID is required.");
}
if (info.Length() == 1 || !info[1]->IsNumber()) {
return Nan::ThrowError("Seed is required.");
}
// convert js argument to c++ type
String::Utf8Value strObjectID(info[0]->ToString());
string ObjectIDCpp(strdup(*strObjectID));
// convert js argument to c++ type
long SeedCpp = Nan::To<int32_t>(info[1]).FromJust();
// declare callback
Nan::Callback *callback = new Nan::Callback(info[2].As<Function>());
// launch Async worker
Nan::AsyncQueueWorker(new MTBrownianGeneratorFactoryWorker(
callback
,ObjectIDCpp
,SeedCpp
));
}
//MTBrownianGeneratorFactoryWorker::~MTBrownianGeneratorFactoryWorker(){
//
//}
//void MTBrownianGeneratorFactoryWorker::Destroy(){
//
//}