本文整理汇总了C++中nan::FunctionCallbackInfo::Length方法的典型用法代码示例。如果您正苦于以下问题:C++ FunctionCallbackInfo::Length方法的具体用法?C++ FunctionCallbackInfo::Length怎么用?C++ FunctionCallbackInfo::Length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nan::FunctionCallbackInfo
的用法示例。
在下文中一共展示了FunctionCallbackInfo::Length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Rank
/**
* Rank:
* Return matrix rank of array using SVD method
* Rank of the array is the number of SVD singular values of the array that are greater than threshold(info[3]).
*
* arguments:
* info[0]: Buffer(object created by smalloc) represent the numjs.Matrix object to be inverted.
* Must be square, i.e. M.rows == M.cols.
* info[1]: Number represent the number of rows of the matrix.
* info[2]: Number represent the number of columns of the matrix.
* info[3]: Optional - Number represent the threshold which SVD values are considered zero.
* If this arg is not given, and S is an array with singular values for M,
* and eps is the epsilon value for datatype of S, then tol is set to S.max() * max(M.shape) * eps
*
* Return value: a Number represent the matrix rank of the given matrix .
*/
void Rank(const Nan::FunctionCallbackInfo<v8::Value>& info){
using CMd = Eigen::Map <const Eigen::MatrixXd >;
using Md = Eigen::Map <Eigen::MatrixXd >;
if (info.Length() < 3) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}
if (!info[1]->IsNumber() || !info[2]->IsNumber()) {
Nan::ThrowTypeError("Wrong arguments");
return;
}
Local<Object> matrixBuffer = info[0].As<Object>();
if (matrixBuffer->HasIndexedPropertiesInExternalArrayData()) {
double *refMatrixData = static_cast<double*>(matrixBuffer->GetIndexedPropertiesExternalArrayData());
size_t rowsMatrix(info[1]->Uint32Value());
size_t colsMatrix(info[2]->Uint32Value());
Md inputMat(refMatrixData, rowsMatrix, colsMatrix);
Eigen::JacobiSVD<Eigen::MatrixXd> svd(inputMat);
if (info.Length() == 4 && info[3]->IsNumber()){
svd.setThreshold((float)info[3]->NumberValue());
}
v8::Local<v8::Number> num = Nan::New((int)svd.rank());
info.GetReturnValue().Set(num);
}
else{
Nan::ThrowTypeError("Wrong arguments");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
示例2: Rank
/**
* Rank:
* Return matrix rank of array using SVD method
* Rank of the array is the number of SVD singular values of the array that are greater than threshold(info[3]).
*
* arguments:
* info[0]: Buffer(object created by Float64Array) represent the numjs.Matrix object to be inverted.
* Must be square, i.e. M.rows == M.cols.
* info[1]: Number represent the number of rows of the matrix.
* info[2]: Number represent the number of columns of the matrix.
* info[3]: Optional - Number represent the threshold which SVD values are considered zero.
* If this arg is not given, and S is an array with singular values for M,
* and eps is the epsilon value for datatype of S, then tol is set to S.max() * max(M.shape) * eps
*
* Return value: a Number represent the matrix rank of the given matrix .
*/
void Rank(const Nan::FunctionCallbackInfo<v8::Value>& info){
using CMd = Eigen::Map <const Eigen::MatrixXd >;
using Md = Eigen::Map <Eigen::MatrixXd >;
if (info.Length() < 3) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}
if (!info[1]->IsNumber() || !info[2]->IsNumber()) {
Nan::ThrowTypeError("Wrong arguments");
return;
}
if (info[0]->IsFloat64Array()) {
double *refMatrixData = *(Nan::TypedArrayContents<double>(info[0]));
size_t rowsMatrix(info[1]->Uint32Value());
size_t colsMatrix(info[2]->Uint32Value());
Md inputMat(refMatrixData, rowsMatrix, colsMatrix);
Eigen::JacobiSVD<Eigen::MatrixXd> svd(inputMat);
if (info.Length() == 4 && info[3]->IsNumber()){
svd.setThreshold((float)info[3]->NumberValue());
}
v8::Local<v8::Number> num = Nan::New((int)svd.rank());
info.GetReturnValue().Set(num);
}
else{
Nan::ThrowTypeError("Wrong arguments");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
示例3: Find
void Find(const Nan::FunctionCallbackInfo<v8::Value>& args) {
Nan::HandleScope scope;
int vid = 0;
int pid = 0;
v8::Local<v8::Function> callback;
if (args.Length() == 0) {
return Nan::ThrowTypeError("First argument must be a function");
}
if (args.Length() == 3) {
if (args[0]->IsNumber() && args[1]->IsNumber()) {
vid = (int) args[0]->NumberValue();
pid = (int) args[1]->NumberValue();
}
// callback
if(!args[2]->IsFunction()) {
return Nan::ThrowTypeError("Third argument must be a function");
}
callback = args[2].As<v8::Function>();
}
if (args.Length() == 2) {
if (args[0]->IsNumber()) {
vid = (int) args[0]->NumberValue();
}
// callback
if(!args[1]->IsFunction()) {
return Nan::ThrowTypeError("Second argument must be a function");
}
callback = args[1].As<v8::Function>();
}
if (args.Length() == 1) {
// callback
if(!args[0]->IsFunction()) {
return Nan::ThrowTypeError("First argument must be a function");
}
callback = args[0].As<v8::Function>();
}
ListBaton* baton = new ListBaton();
strcpy(baton->errorString, "");
baton->callback = new Nan::Callback(callback);
baton->vid = vid;
baton->pid = pid;
uv_work_t* req = new uv_work_t();
req->data = baton;
uv_queue_work(uv_default_loop(), req, EIO_Find, (uv_after_work_cb)EIO_AfterFind);
}
示例4: Det
/**
* Det:
* Compute the determinant of an array.
*
* arguments:
* info[0]: Buffer(object created by Float64Array) represent the numjs.Matrix object to be inverted.
* Must be square, i.e. M.rows == M.cols.
* info[1]: Number represent the number of rows of the matrix.
* info[2]: Number represent the number of columns of the matrix.
*
* Return value: a Number represent the determinant of the given matrix.
*/
void Det(const Nan::FunctionCallbackInfo<v8::Value>& info){
using CMd = Eigen::Map <const Eigen::MatrixXd >;
using Md = Eigen::Map <Eigen::MatrixXd >;
if (info.Length() < 3) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}
if (!info[1]->IsNumber() || !info[2]->IsNumber()) {
Nan::ThrowTypeError("Wrong arguments");
return;
}
if (info[0]->IsFloat64Array()) {
double *refMatrixData = *(Nan::TypedArrayContents<double>(info[0]));
size_t rowsMatrix(info[1]->Uint32Value());
size_t colsMatrix(info[2]->Uint32Value());
Md inputMat(refMatrixData, rowsMatrix, colsMatrix);
v8::Local<v8::Number> num = Nan::New(inputMat.determinant());
info.GetReturnValue().Set(num);
}
else{
Nan::ThrowTypeError("Wrong arguments");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
示例5: New
void SecureCellSeal::New(const Nan::FunctionCallbackInfo<v8::Value>& args)
{
if (args.IsConstructCall()) {
if (args.Length() < 1) {
ThrowParameterError("Secure Cell (Seal) constructor",
"not enough arguments, expected master key");
args.GetReturnValue().SetUndefined();
return;
}
if (!args[0]->IsUint8Array()) {
ThrowParameterError("Secure Cell (Seal) constructor",
"master key is not a byte buffer, use ByteBuffer or Uint8Array");
args.GetReturnValue().SetUndefined();
return;
}
if (node::Buffer::Length(args[0]) == 0) {
ThrowParameterError("Secure Cell (Seal) constructor", "master key is empty");
args.GetReturnValue().SetUndefined();
return;
}
std::vector<uint8_t> key((uint8_t*)(node::Buffer::Data(args[0])),
(uint8_t*)(node::Buffer::Data(args[0]) + node::Buffer::Length(args[0])));
SecureCellSeal* obj = new SecureCellSeal(key);
obj->Wrap(args.This());
args.GetReturnValue().Set(args.This());
} else {
const int argc = 1;
v8::Local<v8::Value> argv[argc] = {args[0]};
v8::Local<v8::Function> cons = Nan::New<v8::Function>(constructor);
args.GetReturnValue().Set(Nan::NewInstance(cons, argc, argv).ToLocalChecked());
}
}
示例6: Eye
/**
* Eye:
* Creates a new nXm matrix with ones on the diagonal
* and zeros elsewhere.
*
* arguments:
* info[0]: Number n which represents the number of rows in the newly built matrix
* info[1]: Number m which represents the number of cols in the newly built matrix
* info[2]: Buffer(object created by Float64Array) for return value(eye matrix nXm).
*/
void Eye(const Nan::FunctionCallbackInfo<v8::Value>& info){
using CMd = Eigen::Map <const Eigen::MatrixXd >;
using Md = Eigen::Map <Eigen::MatrixXd >;
if (info.Length() < 3) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}
if (!info[0]->IsNumber() || !info[1]->IsNumber()) {
Nan::ThrowTypeError("Wrong argument given, should be a number");
return;
}
if (info[2]->IsFloat64Array()) {
size_t rowsMatrix(info[0]->Uint32Value());
size_t colsMatrix(info[1]->Uint32Value());
double *refResData = *(Nan::TypedArrayContents<double>(info[2]));
Md res(refResData, rowsMatrix, colsMatrix);
res = Md::Identity(rowsMatrix, colsMatrix);
Local<Boolean> b = Nan::New(true);
info.GetReturnValue().Set(b);
}
else{
Nan::ThrowTypeError("Wrong arguments2");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
示例7: ParseAsync
void ParseAsync(const Nan::FunctionCallbackInfo<Value> &args) {
Isolate *isolate = args.GetIsolate();
int args_length = args.Length();
if (args_length < 2) {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments")));
return;
}
Local<Value> input = args[0];
if (!ValidateInput(input, isolate)) {
return;
}
if (!args[1]->IsFunction()) {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Second parameter must be a callback")));
return;
}
Nan::Callback *callback = new Nan::Callback(args[1].As<Function>());
anitomyJs::Worker *worker = new anitomyJs::Worker(callback);
if (args_length >= 3) {
Local<Value> options = args[2];
if (!ValidateOptions(options, isolate) ||
!worker->GetAnitomy()->SetOptions(options->ToObject(isolate->GetCurrentContext()).ToLocalChecked(), isolate)) {
return;
}
}
worker->GetAnitomy()->SetInput(input, isolate);
Nan::AsyncQueueWorker(worker);
args.GetReturnValue().Set(Nan::Undefined());
}
示例8: ParseSync
void ParseSync(const Nan::FunctionCallbackInfo<Value> &args) {
Isolate *isolate = args.GetIsolate();
int args_length = args.Length();
if (args_length < 1) {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments")));
return;
}
Local<Value> input = args[0];
if (!ValidateInput(input, isolate)) {
return;
}
anitomyJs::AnitomyJs anitomy;
if (args_length >= 2) {
Local<Value> options = args[1];
if (!ValidateOptions(options, isolate) ||
!anitomy.SetOptions(options->ToObject(isolate->GetCurrentContext()).ToLocalChecked(), isolate)) {
return;
}
}
anitomy.SetInput(input, isolate);
anitomy.Parse();
args.GetReturnValue().Set(anitomy.ParsedResult(isolate));
}
示例9: MatrixPower
/**
* MatrixPower:
* Raise a square matrix to the (integer) power n.
*
* arguments:
* info[0]: Buffer(object created by smalloc) represent the numjs.Matrix object to be "powered".
* Must be square, i.e. M.rows == M.cols.
* info[1]: Number represent the number of rows of the matrix.
* info[2]: Number represent the number of columns of the matrix.
* info[3]: Number m represent the exponent. Can be any integer or long integer, positive, negative, or zero.
* info[4]: Buffer(object created by smalloc) for return value(M**m).
If the exponent is positive or zero then the type of the elements is the same as those of M.
If the exponent is negative the elements are floating-point.
*/
void MatrixPower(const Nan::FunctionCallbackInfo<v8::Value>& info){
using CMd = Eigen::Map <const Eigen::MatrixXd >;
using Md = Eigen::Map <Eigen::MatrixXd >;
if (info.Length() < 5) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}
if (!info[1]->IsNumber() || !info[2]->IsNumber() || !info[3]->IsNumber()) {
Nan::ThrowTypeError("Wrong arguments");
return;
}
Local<Object> matrixBuffer = info[0].As<Object>();
if (matrixBuffer->HasIndexedPropertiesInExternalArrayData()) {
double *refMatrixData = static_cast<double*>(matrixBuffer->GetIndexedPropertiesExternalArrayData());
size_t rowsMatrix(info[1]->Uint32Value());
size_t colsMatrix(info[2]->Uint32Value());
double expParam(info[3]->NumberValue());
Md inputMat(refMatrixData, rowsMatrix, colsMatrix);
Local<Object> resBuffer = info[4].As<Object>();
if (resBuffer->HasIndexedPropertiesInExternalArrayData()) {
double *refResData = static_cast<double*>(resBuffer->GetIndexedPropertiesExternalArrayData());
Md res(refResData, rowsMatrix, colsMatrix);
if(expParam == 0){
res = inputMat.Identity(rowsMatrix, colsMatrix);
}
else{
res = inputMat;
if(expParam < 0){
res = res.inverse();
}
for (int i=1; i< abs(expParam); i++)
{
res *= inputMat;
}
}
Local<Boolean> b = Nan::New(true);
info.GetReturnValue().Set(b);
}
else{
Nan::ThrowTypeError("Wrong arguments2");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
else{
Nan::ThrowTypeError("Wrong arguments3");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
示例10: MatrixPower
/**
* MatrixPower:
* Raise a square matrix to the (integer) power n.
*
* arguments:
* info[0]: Buffer(object created by Float64Array) represent the numjs.Matrix object to be "powered".
* Must be square, i.e. M.rows == M.cols.
* info[1]: Number represent the number of rows of the matrix.
* info[2]: Number represent the number of columns of the matrix.
* info[3]: Number m represent the exponent. Can be any integer or long integer, positive, negative, or zero.
* info[4]: Buffer(object created by Float64Array) for return value(M**m).
If the exponent is positive or zero then the type of the elements is the same as those of M.
If the exponent is negative the elements are floating-point.
*/
void MatrixPower(const Nan::FunctionCallbackInfo<v8::Value>& info){
using CMd = Eigen::Map <const Eigen::MatrixXd >;
using Md = Eigen::Map <Eigen::MatrixXd >;
if (info.Length() < 5) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}
if (!info[1]->IsNumber() || !info[2]->IsNumber() || !info[3]->IsNumber()) {
Nan::ThrowTypeError("Wrong arguments");
return;
}
if (info[0]->IsFloat64Array()) {
double *refMatrixData = *(Nan::TypedArrayContents<double>(info[0]));
size_t rowsMatrix(info[1]->Uint32Value());
size_t colsMatrix(info[2]->Uint32Value());
double expParam(info[3]->NumberValue());
Md inputMat(refMatrixData, rowsMatrix, colsMatrix);
if (info[4]->IsFloat64Array()) {
double *refResData = *(Nan::TypedArrayContents<double>(info[4]));
Md res(refResData, rowsMatrix, colsMatrix);
if(expParam == 0){
res = inputMat.Identity(rowsMatrix, colsMatrix);
}
else{
res = inputMat;
if(expParam < 0){
res = res.inverse();
}
for (int i=1; i< abs(expParam); i++)
{
res *= inputMat;
}
}
Local<Boolean> b = Nan::New(true);
info.GetReturnValue().Set(b);
}
else{
Nan::ThrowTypeError("Wrong arguments2");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
else{
Nan::ThrowTypeError("Wrong arguments3");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
示例11: RegisterRemoved
void RegisterRemoved(const Nan::FunctionCallbackInfo<v8::Value>& args) {
Nan::HandleScope scope;
v8::Local<v8::Function> callback;
if (args.Length() == 0) {
return Nan::ThrowTypeError("First argument must be a function");
}
if (args.Length() == 1) {
// callback
if(!args[0]->IsFunction()) {
return Nan::ThrowTypeError("First argument must be a function");
}
callback = args[0].As<v8::Function>();
}
removedCallback = new Nan::Callback(callback);
isRemovedRegistered = true;
}
示例12: GetClipDatabase
void GetClipDatabase(const Nan::FunctionCallbackInfo<v8::Value>& info) {
if ((info.Length() < 1) || (info.Length() > 1)) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}
if (!info[0]->IsNumber()) {
Nan::ThrowTypeError("Wrong arguments");
return;
}
int sizeOfData = 0;
char* clipDatabase = GetClipDatabase(sizeOfData);
v8::Local<v8::String> v8ClipDatabase = v8::String::New(clipDatabase, sizeOfData);
v8::Local<v8::Object> obj = Nan::New<v8::Object>();
obj->Set(Nan::New("msg").ToLocalChecked(), v8ClipDatabase);
info.GetReturnValue().Set(obj);
FreeClipDatabase(clipDatabase);
}
示例13: VerifyMail
void VerifyMail(const Nan::FunctionCallbackInfo<v8::Value>& info) {
if (info.Length() < 3) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}
Nan::Utf8String infile(info[0]->ToString());
Nan::Utf8String outfile(info[1]->ToString());
Nan::Utf8String recipfile(info[2]->ToString());
int ret = verify_mime(*infile, *outfile, *recipfile);
v8::Local<v8::Number> res = Nan::New(ret);
info.GetReturnValue().Set(res);
}
示例14: DecryptCMSMail
void DecryptCMSMail(const Nan::FunctionCallbackInfo<v8::Value>& info) {
if (info.Length() < 4) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}
Nan::Utf8String recipfile(info[0]->ToString());
Nan::Utf8String pass(info[1]->ToString());
Nan::Utf8String infile(info[2]->ToString());
Nan::Utf8String outfile(info[3]->ToString());
int ret = decrypt_cms(*recipfile, *pass, *infile, *outfile);
v8::Local<v8::Number> res = Nan::New(ret);
info.GetReturnValue().Set(res);
}
示例15: Triu
/**
* Triu:
* Creates a copy of a given matrix with all elements below the diagonal zeroed
*
* arguments:
* info[0]: Buffer(object created by Float64Array) represent the numjs.Matrix object to be converted to lower diagonal matrix
* info[1]: Number represent the number of rows of the matrix.
* info[2]: Number represent the number of columns of the matrix.
* info[3]: Buffer(object created by Float64Array) for return value(M**m).
*/
void Triu(const Nan::FunctionCallbackInfo<v8::Value>& info){
using CMd = Eigen::Map <const Eigen::MatrixXd >;
using Md = Eigen::Map <Eigen::MatrixXd >;
if (info.Length() < 4) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}
if (!info[1]->IsNumber() || !info[2]->IsNumber()) {
Nan::ThrowTypeError("Wrong arguments");
return;
}
if (info[0]->IsFloat64Array()) {
double *refMatrixData = *(Nan::TypedArrayContents<double>(info[0]));
size_t rowsMatrix(info[1]->Uint32Value());
size_t colsMatrix(info[2]->Uint32Value());
Md inputMat(refMatrixData, rowsMatrix, colsMatrix);
if (info[3]->IsFloat64Array()) {
double *refResData = *(Nan::TypedArrayContents<double>(info[3]));
Md res(refResData, rowsMatrix, colsMatrix);
for (int i = 0; i < rowsMatrix; i++) {
for (int j = 0; j < colsMatrix; j++) {
if (j < i) {
res(i, j) = 0;
} else {
res(i, j) = inputMat(i, j);
}
}
}
Local<Boolean> b = Nan::New(true);
info.GetReturnValue().Set(b);
}
else{
Nan::ThrowTypeError("Wrong argument - output matrix data should be float64array");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}
else{
Nan::ThrowTypeError("Wrong argument - input matrix data should be float64array");
Local<Boolean> b = Nan::New(false);
info.GetReturnValue().Set(b);
}
}