本文整理汇总了C++中Local::IsNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ Local::IsNumber方法的具体用法?C++ Local::IsNumber怎么用?C++ Local::IsNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Local
的用法示例。
在下文中一共展示了Local::IsNumber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: build_http_msg_buffer
void Msg_Struct::build_http_msg_buffer(Isolate* isolate, v8::Local<v8::Object> object, std::string &str) {
std::stringstream stream;
for(std::vector<Field_Info>::const_iterator iter = field_vec().begin();
iter != field_vec().end(); iter++) {
stream.str("");
stream << "\"" << iter->field_name << "\":";
Local<Value> value = object->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, iter->field_name.c_str(), NewStringType::kNormal).ToLocalChecked()).ToLocalChecked();
if(iter->field_type == "int8" || iter->field_type == "int16" ||
iter->field_type == "int32") {
int32_t val = 0;
if (value->IsInt32()) {
val = value->Int32Value(isolate->GetCurrentContext()).FromJust();
}
stream << val << ",";
}
else if(iter->field_type == "int64") {
int64_t val = 0;
if (value->IsNumber()) {
val = value->NumberValue(isolate->GetCurrentContext()).FromJust();
}
stream << val << ",";
}
else if(iter->field_type == "double") {
double val = 0;
if (value->IsNumber()) {
val = value->NumberValue(isolate->GetCurrentContext()).FromJust();
}
stream << val << ",";
}
else if(iter->field_type == "bool") {
bool val = 0;
if (value->IsBoolean()) {
val = value->BooleanValue(isolate->GetCurrentContext()).FromJust();
}
stream << val << ",";
}
else if(iter->field_type == "string") {
if (value->IsString()) {
String::Utf8Value str(value->ToString(isolate->GetCurrentContext()).ToLocalChecked());
stream << "\"" << ToCString(str) << "\",";
} else {
stream << "\"\",";
}
}
else {
LOG_ERROR("Can not find the field_type:%s, struct_name:%s", iter->field_type.c_str(), struct_name().c_str());
}
str += stream.str();
}
}
示例2: setVectorY
void vectorTemplate::setVectorY(Local<String> property, Local<Value> value, const AccessorInfo &info){
Local<External> data = Local<External>::Cast(info.Data());
vector<double> *vect = reinterpret_cast<vector<double> *>(data->Value());
if(value->IsNumber()){
vect->y = value->ToNumber()->Value();
}
}
示例3: ThrowException
Handle<Value> Texture::On(const Arguments &args)
{
HandleScope scope;
Local<Value> Event;
Local<Value> Options;
Local<Value> Callback;
ClutterActor *instance = ObjectWrap::Unwrap<Texture>(args.This())->_actor;
#if 0
/* Check arguments */
if (args.Length() == 2) {
Event = args[0];
Callback = args[1];
} else if (args.Length() == 3) {
Event = args[0];
Options = args[1];
Callback = args[2];
} else
return args.This();
if (!Event->IsNumber()) {
return ThrowException(Exception::TypeError(
String::New("first argument must be integer")));
}
if (!Callback->IsFunction()) {
return ThrowException(Exception::TypeError(
String::New("Second argument must be a callback function")));
}
#endif
Actor::On(args);
return args.This();
}
示例4: setSharedRAM
/* Set the shared PRU RAM to an input array
* Takes an integer array as input, writes it to PRU shared memory
* Not much error checking here, don't pass in large arrays or seg faults will happen
* TODO: error checking and allow user to select range to set
*/
Handle<Value> setSharedRAM(const Arguments& args) {
HandleScope scope;
//Check we have a single argument
if (args.Length() != 1) {
ThrowException(Exception::TypeError(String::New("Wrong number of arguments")));
return scope.Close(Undefined());
}
//Check that it's an array
if (!args[0]->IsArray()) {
ThrowException(Exception::TypeError(String::New("Argument must be array")));
return scope.Close(Undefined());
}
//Get array
Local<Array> a = Array::Cast(*args[0]);
//Iterate over array
for (unsigned int i = 0; i<a->Length(); i++) {
//Get element and check it's numeric
Local<Value> element = a->Get(i);
if (!element->IsNumber()) {
ThrowException(Exception::TypeError(String::New("Array must be integer")));
return scope.Close(Undefined());
}
//Set corresponding memory bytes
sharedMem_int[OFFSET_SHAREDRAM + i] = (unsigned int) element->NumberValue();
}
//Return nothing
return scope.Close(Undefined());
};
示例5: TryConvertToJavaLong
bool ArgConverter::TryConvertToJavaLong(const Local<Value>& value, jlong& javaLong)
{
bool success = false;
if (!value.IsEmpty())
{
if (value->IsNumber() || value->IsNumberObject())
{
javaLong = (jlong)value->IntegerValue();
success = true;
}
else if (value->IsObject())
{
auto obj = Local<Object>::Cast(value);
auto isJavaLongValue = obj->GetHiddenValue(V8StringConstants::GetJavaLong());
if (!isJavaLongValue.IsEmpty() && isJavaLongValue->BooleanValue())
{
javaLong = (jlong)ConvertToJavaLong(value);
success = true;
}
}
}
return success;
}
示例6: 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();
}
示例7: if
void
encodeArray(bson_buffer *bb, const char *name, const Local<Value> element) {
Local<Array> a = Array::Cast(*element);
bson_buffer *arr = bson_append_start_array(bb, name);
for (int i = 0, l=a->Length(); i < l; i++) {
Local<Value> val = a->Get(Number::New(i));
stringstream keybuf;
string keyval;
keybuf << i << endl;
keybuf >> keyval;
if (val->IsString()) {
encodeString(arr, keyval.c_str(), val);
}
else if (val->IsInt32()) {
encodeInteger(arr, keyval.c_str(), val);
}
else if (val->IsNumber()) {
encodeNumber(arr, keyval.c_str(), val);
}
else if (val->IsBoolean()) {
encodeBoolean(arr, keyval.c_str(), val);
}
else if (val->IsArray()) {
encodeArray(arr, keyval.c_str(), val);
}
else if (val->IsObject()) {
bson bson(encodeObject(val));
bson_append_bson(arr, keyval.c_str(), &bson);
bson_destroy(&bson);
}
}
bson_append_finish_object(arr);
}
示例8: SetState
void UiWindow::SetState(Local<String> property, Local<Value> value, const PropertyCallbackInfo<void>& info) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
UiWindow* _this = Unwrap<UiWindow>(info.This());
if (value->IsNumber()) {
WINDOW_STATE state = (WINDOW_STATE)value->Int32Value();
_this->SetState(state);
}
}
示例9: FetchModeSetter
void ODBCResult::FetchModeSetter(Local<String> property, Local<Value> value, const AccessorInfo &info) {
HandleScope scope;
ODBCResult *obj = ObjectWrap::Unwrap<ODBCResult>(info.Holder());
if (value->IsNumber()) {
obj->m_fetchMode = value->Int32Value();
}
}
示例10: SpacingSetter
void BoxLayout::SpacingSetter(Local<String> name, Local<Value> value, const AccessorInfo& info)
{
HandleScope scope;
if (value->IsNumber()) {
ClutterActor *instance = ObjectWrap::Unwrap<BoxLayout>(info.This())->_actor;
mx_box_layout_set_spacing(MX_BOX_LAYOUT(instance), value->ToInteger()->Value());
}
}
示例11: FilterQualitySetter
void Texture::FilterQualitySetter(Local<String> name, Local<Value> value, const AccessorInfo& info)
{
HandleScope scope;
if (value->IsNumber()) {
ClutterActor *instance = ObjectWrap::Unwrap<Actor>(info.This())->_actor;
clutter_texture_set_filter_quality(CLUTTER_TEXTURE(instance), (ClutterTextureQuality)value->ToInteger()->Value());
}
}
示例12: ScaleModeSetter
void Image::ScaleModeSetter(Local<String> name, Local<Value> value, const AccessorInfo& info)
{
HandleScope scope;
if (value->IsNumber()) {
ClutterActor *instance = ObjectWrap::Unwrap<Image>(info.This())->_actor;
mx_image_set_scale_mode(MX_IMAGE(instance), (MxImageScaleMode)value->ToInteger()->Value());
}
}
示例13: ColumnSpacingSetter
void Table::ColumnSpacingSetter(Local<String> name, Local<Value> value, const AccessorInfo& info)
{
HandleScope scope;
if (value->IsNumber()) {
ClutterActor *instance = ObjectWrap::Unwrap<Table>(info.This())->_actor;
mx_table_set_column_spacing(MX_TABLE(instance), value->ToInteger()->Value());
}
}
示例14: ThrowException
Handle<Value> Feature::addAttributes(const Arguments& args)
{
HandleScope scope;
Feature* fp = ObjectWrap::Unwrap<Feature>(args.This());
if (args.Length() > 0 ) {
Local<Value> value = args[0];
if (value->IsNull() || value->IsUndefined()) {
return ThrowException(Exception::TypeError(String::New("object expected")));
} else {
Local<Object> attr = value->ToObject();
try
{
Local<Array> names = attr->GetPropertyNames();
uint32_t i = 0;
uint32_t a_length = names->Length();
boost::scoped_ptr<mapnik::transcoder> tr(new mapnik::transcoder("utf8"));
while (i < a_length) {
Local<Value> name = names->Get(i)->ToString();
Local<Value> value = attr->Get(name);
if (value->IsString()) {
UnicodeString ustr = tr->transcode(TOSTR(value));
boost::put(*fp->get(),TOSTR(name),ustr);
} else if (value->IsNumber()) {
double num = value->NumberValue();
// todo - round
if (num == value->IntegerValue()) {
int integer = value->IntegerValue();
boost::put(*fp->get(),TOSTR(name),integer);
} else {
double dub_val = value->NumberValue();
boost::put(*fp->get(),TOSTR(name),dub_val);
}
} else {
std::clog << "unhandled type for property: " << TOSTR(name) << "\n";
}
i++;
}
}
catch (const std::exception & ex )
{
return ThrowException(Exception::Error(
String::New(ex.what())));
}
catch (...) {
return ThrowException(Exception::Error(
String::New("Unknown exception happended - please report bug")));
}
}
}
return Undefined();
}
示例15: zSetter
void Point::zSetter(Local<String> property, Local<Value> value, const AccessorInfo &info)
{
Point *geom = ObjectWrap::Unwrap<Point>(info.This());
if (!value->IsNumber()) {
NODE_THROW("z must be a number");
return;
}
double z = value->NumberValue();
((OGRPoint* )geom->this_)->setZ(z);
}