本文整理汇总了C++中Handle::Length方法的典型用法代码示例。如果您正苦于以下问题:C++ Handle::Length方法的具体用法?C++ Handle::Length怎么用?C++ Handle::Length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Handle
的用法示例。
在下文中一共展示了Handle::Length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: prepare_import_results
void prepare_import_results(Local<Value> returned_value, sass_context_wrapper* ctx_w) {
NanScope();
if (returned_value->IsArray()) {
Handle<Array> array = Handle<Array>::Cast(returned_value);
ctx_w->imports = sass_make_import_list(array->Length());
for (size_t i = 0; i < array->Length(); ++i) {
Local<Value> value = array->Get(i);
if (!value->IsObject())
continue;
Local<Object> object = Local<Object>::Cast(value);
char* path = create_string(object->Get(NanNew<String>("file")));
char* contents = create_string(object->Get(NanNew<String>("contents")));
ctx_w->imports[i] = sass_make_import_entry(path, (!contents || contents[0] == '\0') ? 0 : strdup(contents), 0);
}
}
else if (returned_value->IsObject()) {
ctx_w->imports = sass_make_import_list(1);
Local<Object> object = Local<Object>::Cast(returned_value);
char* path = create_string(object->Get(NanNew<String>("file")));
char* contents = create_string(object->Get(NanNew<String>("contents")));
ctx_w->imports[0] = sass_make_import_entry(path, (!contents || contents[0] == '\0') ? 0 : strdup(contents), 0);
}
else {
ctx_w->imports = sass_make_import_list(1);
ctx_w->imports[0] = sass_make_import_entry(ctx_w->file, 0, 0);
}
}
示例2: if
Handle<Value> ImgHash(const Arguments& args) {
HandleScope scope;
if (args.Length() < 1)
return scope.Close(Undefined());
if (args[0]->IsArray()){
Handle<Array> arr = Local<Array>::Cast(args[0]);
Handle<Array> output = Array::New(arr->Length());
for (int i = 0; i < arr->Length(); i++){
if (arr->Get(i)->IsString()){
v8::String::Utf8Value str(arr->Get(i));
char* file1 = *str;
output->Set(i, hashImage(file1));
}
else
output->Set(i, Undefined());
}
return scope.Close(output);
}
else if (args[0]->IsString()){
v8::String::Utf8Value arg1(args[0]->ToString());
char* file1 = *arg1;
hash x;
cv::Mat m1 = cv::imread(file1);
if (!m1.data)
return scope.Close(Undefined());
imghash_algorithm(m1, x);
Local<Object> obj = Object::New();
hash2js(obj, x);
return scope.Close(hashImage(file1));
}
return scope.Close(Undefined());
}
示例3: getLinearRing
geos::geom::Polygon* GeoJSONReader::getPolygon(Handle<Value> coords) {
if (coords->IsArray()) {
Handle<Array> array = Handle<Array>::Cast(coords);
if (array->Length() == 0)
throw "The number of the linear rings must be >= 1";
geos::geom::LinearRing* shell = getLinearRing(array->Get(0));
uint32_t length = array->Length();
std::vector<geos::geom::Geometry*>* holes = new std::vector<geos::geom::Geometry*>();
try {
for (uint32_t i = 1; i < length; i++) {
geos::geom::LinearRing* g = getLinearRing(array->Get(i));
holes->push_back(g);
}
}
catch (...) {
delete shell;
unsigned size = holes->size();
for (unsigned int i = 0; i < size; i++)
delete (*holes)[i];
delete holes;
throw;
}
return geometryFactory->createPolygon(shell, holes);
}
return geometryFactory->createPolygon();
}
示例4:
/*! Queues up an array to be sent to the sound card */
void Audio::AudioEngine::queueOutputBuffer( Handle<Array> result ) {
// Reset our record of the number of cached output samples
m_uNumCachedOutputSamples[m_uCurrentWriteBuffer] = 0;
if( m_bInterleaved ) {
for( int iSample=0; iSample<m_uSamplesPerBuffer*m_uOutputChannels; ++iSample )
setSample( iSample, result->Get(iSample) );
m_uNumCachedOutputSamples[m_uCurrentWriteBuffer] = result->Length()/m_uOutputChannels;
} else {
// Validate the structure of the output buffer array
if( !result->Get(0)->IsArray() ) {
NanThrowTypeError("Output buffer not properly setup, 0th channel is not an array");
return;
}
Handle<Array> item;
for( int iChannel=0; iChannel<m_uOutputChannels; ++iChannel ) {
for( int iSample=0; iSample<m_uSamplesPerBuffer; ++iSample ) {
item = Handle<Array>::Cast( result->Get(iChannel) );
if( item->IsArray() ) {
if( item->Length() > m_uNumCachedOutputSamples[m_uCurrentWriteBuffer] )
m_uNumCachedOutputSamples[m_uCurrentWriteBuffer] = item->Length();
setSample( iSample, item->Get(iSample) );
}
} // end for each sample
} // end for each channel
}
m_uCurrentWriteBuffer = (m_uCurrentWriteBuffer + 1)%m_uNumBuffers;
} // end AudioEngine::queueOutputBuffer()
示例5: SerializePart
int SerializePart(google::protobuf::Message *message, Handle<Object> subj) {
Nan::HandleScope scope;
// get a reflection
const Reflection *r = message->GetReflection();
const Descriptor *d = message->GetDescriptor();
// build a list of required properties
vector<string> required;
for (int i = 0; i < d->field_count(); i++) {
const FieldDescriptor *field = d->field(i);
if (field->is_required())
required.push_back(field->name());
}
// build a reflection
// get properties of passed object
Handle<Array> properties = subj->GetPropertyNames();
uint32_t len = properties->Length();
// check that all required properties are present
for (uint32_t i = 0; i < required.size(); i++) {
Handle<String> key = Nan::New<String>(required.at(i).c_str()).ToLocalChecked();
if (!subj->Has(key))
return -1;
}
for (uint32_t i = 0; i < len; i++) {
Handle<Value> property = properties->Get(i);
Handle<String> property_s = property->ToString();
if (*property_s == NULL)
continue;
String::Utf8Value temp(property);
std::string propertyName = std::string(*temp);
const FieldDescriptor *field = d->FindFieldByName(propertyName);
if (field == NULL) continue;
Handle<Value> val = subj->Get(property);
if (field->is_repeated()) {
if (!val->IsArray())
continue;
Handle<Array> array = val.As<Array>();
int len = array->Length();
for (int i = 0; i < len; i++)
SerializeField(message, r, field, array->Get(i));
} else {
SerializeField(message, r, field, val);
}
}
return 0;
}
示例6: GLESglBufferSubDataCallback
//Accepts GL_UNSIGNED_SHORT and GL_FLOAT as types
//TODO(nico): deal with interleaved data
Handle<Value> GLESglBufferSubDataCallback(const Arguments& args) {
if (args.Length() != 4)
return v8::Undefined();
unsigned int target = args[0]->Uint32Value();
unsigned int offset = args[1]->Uint32Value();
unsigned int type = args[3]->Uint32Value();
void* ans;
if(args[2]->IsArray()) {
Handle<Array> data = Handle<Array>::Cast(args[2]);
unsigned int len = data->Length();
switch(type) {
case GL_FLOAT:
{
GLfloat* arg1 = new GLfloat[len];
for (unsigned j = 0; j < data->Length(); j++) {
Handle<Value> arg(data->Get(Integer::New(j)));
arg1[j] = (GLfloat)arg->NumberValue();
}
ans = (void *)arg1;
}
break;
case GL_UNSIGNED_SHORT:
{
GLushort* arg1 = new GLushort[len];
for (unsigned j = 0; j < data->Length(); j++) {
Handle<Value> arg(data->Get(Integer::New(j)));
arg1[j] = (GLushort)arg->Uint32Value();
}
ans = (void *)arg1;
}
break;
default: return v8::Undefined();
}
glBufferSubData((GLenum)target,
(GLintptr)offset,
(GLsizeiptr)len,
(const void*)ans);
//should I delete[] ans?
}
Handle<Object> res(GlesFactory::self_);
return res;
}
示例7: getPolygon
geos::geom::MultiPolygon* GeoJSONReader::getMultiPolygon(Handle<Value> coords) {
if (coords->IsArray()) {
Handle<Array> array = Handle<Array>::Cast(coords);
uint32_t length = array->Length();
std::vector<geos::geom::Geometry*>* geoms = new std::vector<geos::geom::Geometry*>();
try {
for (uint32_t i = 0; i < length; i++) {
geos::geom::Polygon* g = getPolygon(array->Get(i));
geoms->push_back(g);
}
}
catch (...) {
unsigned size = geoms->size();
for (unsigned int i = 0; i < size; i++)
delete (*geoms)[i];
delete geoms;
throw;
}
return geometryFactory->createMultiPolygon(geoms);
}
return geometryFactory->createMultiPolygon();
}
示例8: catch
geos::geom::CoordinateSequence* GeoJSONReader::getCoordinates(Handle<Value> value) {
if (!value->IsArray())
throw "A coordinate sequence must be an instance of Array";
Handle<Array> array = Handle<Array>::Cast(value);
uint32_t length = array->Length();
geos::geom::CoordinateSequence* sequence = coordinateSequenceFactory->create(length, 3);
try {
for (uint32_t i = 0; i < length; i++) {
sequence->setAt(getCoordinate(array->Get(i)), (std::size_t)i);
}
}
catch (...) {
delete sequence;
throw;
}
return sequence;
}
示例9: NODE_THROW
Handle<Value> Dataset::setGeoTransform(const Arguments& args)
{
Dataset *ds = ObjectWrap::Unwrap<Dataset>(args.This());
if(!ds->this_) return NODE_THROW("Dataset object has already been destroyed");
Handle<Array> transform;
NODE_ARG_ARRAY(0, "transform", transform);
if (transform->Length() != 6) {
return NODE_THROW("Transform array must have 6 elements")
}
double buffer[6];
for (int i = 0; i < 6; i++) {
Local<Value> val = transform->Get(i);
if (!val->IsNumber()) {
return NODE_THROW("Transform array must only contain numbers");
}
buffer[i] = val->NumberValue();
}
CPLErr err = ds->this_->SetGeoTransform(buffer);
if (err) return NODE_THROW_CPLERR(err);
return Undefined();
}
示例10: _memcached_mget
/**
* @function memcached.mget
*
* ### Synopsis:
*
* var o = memcache.get(handle, array_of_keys);
*
* Get multiple values, identified by an array of keys, from memcached.
*
* The returned object is a hash of returned values, indexed by the key.
*
* For each of these keys, the value is an object in the form described at the top of this page.
*
* @param {object} handle - handle to memcached connection.
* @param {array} keys - array of keys of data to get from memcached
* @return {object} o - has of objects of the form described at top of the page, or false if an error occurred.
*/
JSVAL _memcached_mget (JSARGS args) {
HandleScope scope;
M* handle = HANDLE(args[0]);
Handle<Array> aKeys = Handle<Array>::Cast(args[1]);
int numKeys = aKeys->Length();
char *keys[numKeys];
size_t key_lengths[numKeys];
for (int i = 0; i < numKeys; i++) {
String::Utf8Value k(aKeys->Get(i));
keys[i] = *k;
key_lengths[i] = strlen(keys[i]);
}
R rc = memcached_mget(handle, keys, key_lengths, numKeys);
if (rc != MEMCACHED_SUCCESS) {
return String::New(memcached_strerror(handle, rc));
}
char return_key[MEMCACHED_MAX_KEY];
size_t return_key_length;
char *return_value;
size_t return_value_length;
uint32_t flags;
JSOBJ result = Object::New();
while ((return_value = memcached_fetch(handle, return_key, &return_key_length, &return_value_length, &flags, &rc))) {
JSOBJ o = Object::New();
o->Set(String::New("value"), String::New(return_value));
o->Set(String::New("flags"), Integer::New(flags));
o->Set(String::New("rc"), Integer::New(rc));
free(return_value);
result->Set(String::New(return_key), o);
}
return scope.Close(result);
}
示例11: read_league_table_file
void league_table::read_league_table_file(Handle<Array> leagueDat)
{
// The file doesn't have to exist (if it doesn't, a new table is
// created). But if it exists, it must be in correct format
//
if (leagueDat->Length())
{
HandleScope scope;
Handle<Array> tokens;
for(int i=0, l=leagueDat->Length(); i<l; ++i)
{
tokens = Handle<Array>::Cast(leagueDat->Get(i));
// The structure of a line must be:
//
// PLACE TEAMNAME+ PL W D L GF GA GD PTS
//
// TEAMNAME may be multiple tokens, so we count from the
// end ! The first token is PLACE, the last 8 tokens are
// as specified, and everything between the first and
// the last 8 is the team name.
//
// Note: when the team name is restructured from the
// tokens, each token is separated by one space
//
unsigned num_tokens = tokens->Length();
if (num_tokens < 10)
die("The following line in leaguedat has too few tokens%s");
int points = tokens->Get(9)->IntegerValue();
int goal_difference = tokens->Get(8)->IntegerValue();
int goals_against = tokens->Get(7)->IntegerValue();
int goals_for = tokens->Get(6)->IntegerValue();
int lost = tokens->Get(5)->IntegerValue();
int drawn = tokens->Get(4)->IntegerValue();
int won = tokens->Get(3)->IntegerValue();
int played = tokens->Get(2)->IntegerValue();
char name[64];
toAscii(tokens->Get(1)->ToString(), name);
add_new_team(string(name), played, won, drawn, lost, goals_for, goals_against,
goal_difference, points);
}
}
}
示例12: to_ruby
/*
* call-seq:
* ary.push(value) => value
* ary << value => value
*
* Appends given value to referenced array.
*
*/
static VALUE rb_v8_array_push(VALUE self, VALUE value)
{
HandleScope scope;
Handle<Value> _value = to_v8(value);
Handle<Array> ary = unwrap(self);
ary->Set(ary->Length(), _value);
return to_ruby(_value);
}
示例13: writeTo
void CustomExternalStringResource::writeTo(Handle<String> str, MDB_val *val) {
unsigned int l = str->Length() + 1;
uint16_t *d = new uint16_t[l];
str->Write(d);
d[l - 1] = 0;
val->mv_data = d;
val->mv_size = l * sizeof(uint16_t);
}
示例14: Undefined
Handle<Value> DebugDrawManagerAddLines(const Arguments& args)
{
dtEntity::DebugDrawInterface* ddm = dtEntity::GetDebugDrawInterface();
if(!ddm->IsEnabled() )
{
return Undefined();
}
if(args.Length() < 1 || !args[0]->IsArray())
{
return ThrowError("usage: addLines(Array(Vec3) lines,[Vec4 color, Int lineWidth, Number duration, bool useDepthTest])");
}
std::vector<dtEntity::Vec3f> lines;
HandleScope scope;
Handle<Array> arr = Handle<Array>::Cast(args[0]);
unsigned int l = arr->Length();
for(unsigned int i = 0; i < l; ++i)
{
lines.push_back(UnwrapVec3(arr->Get(i)));
}
dtEntity::Vec4f color(1,0,0,1);
if(args.Length() > 1 && IsVec4(args[1]))
{
color = UnwrapVec4(args[1]);
}
int linewidth = 1;
if(args.Length() > 2)
{
linewidth = args[2]->Int32Value();
if(linewidth == 0)
{
linewidth = 1;
}
}
float duration = 0;
if(args.Length() > 3)
{
duration = args[3]->NumberValue();
}
bool depth = true;
if(args.Length() > 4)
{
depth = args[4]->BooleanValue();
}
ddm->AddLines(lines, color, linewidth, duration, depth);
return Undefined();
}
示例15:
void V8Util::objectExtend(Handle<Object> dest, Handle<Object> src)
{
Handle<Array> names = src->GetOwnPropertyNames();
int length = names->Length();
for (int i = 0; i < length; ++i) {
Handle<Value> name = names->Get(i);
Handle<Value> value = src->Get(name);
dest->Set(name, value);
}
}