forked from udarrr/opencv4nodejs-prebuilt-install
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCvBinding.h
49 lines (39 loc) · 1.1 KB
/
CvBinding.h
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
#include "NativeNodeUtils.h"
#include <functional>
#ifndef __FF_CV_BINDING_H__
#define __FF_CV_BINDING_H__
class CvBinding : public FF::BindingBase, public FF::ISyncWorker, public FF::IAsyncWorker {
public:
std::string execute() {
try {
executeBinding();
return "";
}
catch (std::exception &e) {
return std::string(e.what());
}
}
bool applyUnwrappers(Nan::NAN_METHOD_ARGS_TYPE info) {
return FF::BindingBase::applyUnwrappers(info);
}
v8::Local<v8::Value> getReturnValue() {
return FF::BindingBase::getReturnValue();
}
v8::Local<v8::Value> getReturnValue(Nan::NAN_METHOD_ARGS_TYPE info) {
return getReturnValue();
}
protected:
std::function<void(void)> executeBinding = [](){};
};
template<class TClass>
class CvClassMethodBinding : public CvBinding {
public:
void setup() {
createBinding(req<typename TClass::Converter>());
}
void setup(typename TClass::Converter::Type self) {
createBinding(std::make_shared<FF::Value<typename TClass::Converter::Type>>(self));
}
virtual void createBinding(std::shared_ptr<FF::Value<typename TClass::Converter::Type>> self) = 0;
};
#endif