本文整理汇总了C++中Args::Length方法的典型用法代码示例。如果您正苦于以下问题:C++ Args::Length方法的具体用法?C++ Args::Length怎么用?C++ Args::Length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Args
的用法示例。
在下文中一共展示了Args::Length方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: str
std::string logArgs2String(const Args &args)
{
std::string message;
for (int i = 0; i < args.Length(); i++) {
::v8::HandleScope scope;
::v8::String::Utf8Value str(args[i]);
message += *str;
}
return message;
}
示例2: global
void Bindings::global(const Args& args)
{
Isolate* isolate(args.GetIsolate());
HandleScope scope(isolate);
if (args.Length() != 3)
{
throw std::runtime_error("Wrong number of arguments to global");
}
if (stageFactory)
{
throw std::runtime_error("Multiple global initializations attempted");
}
std::size_t i(0);
const auto& pathsArg(args[i++]);
const auto& cacheSizeArg(args[i++]);
const auto& arbiterArg(args[i++]);
std::string errMsg;
if (!pathsArg->IsArray()) errMsg += "\t'paths' must be an array";
if (!cacheSizeArg->IsNumber()) errMsg += "\t'cacheSize' must be a number";
if (!arbiterArg->IsString()) errMsg += "\t'arbiter' must be a string";
paths = parsePathList(isolate, pathsArg);
const std::size_t cacheSize(cacheSizeArg->NumberValue());
cache = entwine::makeUnique<entwine::Cache>(cacheSize);
const std::string arbiterString(
*v8::String::Utf8Value(arbiterArg->ToString()));
outerScope.getArbiter(entwine::parse(arbiterString));
signal(SIGSEGV, handler);
curl_global_init(CURL_GLOBAL_ALL);
stageFactory = entwine::makeUnique<pdal::StageFactory>();
}
示例3: create
void Bindings::create(const Args& args)
{
Isolate* isolate(args.GetIsolate());
HandleScope scope(isolate);
Bindings* obj = ObjectWrap::Unwrap<Bindings>(args.Holder());
if (args.Length() != 2)
{
throw std::runtime_error("Wrong number of arguments to create");
}
std::size_t i(0);
const auto& nameArg (args[i++]);
const auto& cbArg (args[i++]);
std::string errMsg;
if (!nameArg->IsString()) errMsg += "\t'name' must be a string";
if (!cbArg->IsFunction()) throw std::runtime_error("Invalid create CB");
UniquePersistent<Function> callback(isolate, Local<Function>::Cast(cbArg));
if (errMsg.size())
{
std::cout << "Client error: " << errMsg << std::endl;
Status status(400, errMsg);
const unsigned argc = 1;
Local<Value> argv[argc] = { status.toObject(isolate) };
Local<Function> local(Local<Function>::New(isolate, callback));
local->Call(isolate->GetCurrentContext()->Global(), argc, argv);
callback.Reset();
return;
}
const std::string name(*v8::String::Utf8Value(nameArg->ToString()));
// Store everything we'll need to perform initialization.
uv_work_t* req(new uv_work_t);
req->data = new CreateData(
obj->m_session,
name,
paths,
outerScope,
cache,
std::move(callback));
uv_queue_work(
uv_default_loop(),
req,
(uv_work_cb)([](uv_work_t *req)->void
{
CreateData* createData(static_cast<CreateData*>(req->data));
createData->safe([createData]()->void
{
if (!createData->session->initialize(
createData->name,
createData->paths,
createData->outerScope,
createData->cache))
{
createData->status.set(404, "Not found");
}
});
}),
(uv_after_work_cb)([](uv_work_t* req, int status)->void
{
Isolate* isolate(Isolate::GetCurrent());
HandleScope scope(isolate);
CreateData* createData(static_cast<CreateData*>(req->data));
const unsigned argc = 1;
Local<Value> argv[argc] = { createData->status.toObject(isolate) };
Local<Function> local(Local<Function>::New(
isolate,
createData->callback));
local->Call(isolate->GetCurrentContext()->Global(), argc, argv);
delete createData;
delete req;
})
);
}