本文整理汇总了C++中Handle::Int32Value方法的典型用法代码示例。如果您正苦于以下问题:C++ Handle::Int32Value方法的具体用法?C++ Handle::Int32Value怎么用?C++ Handle::Int32Value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Handle
的用法示例。
在下文中一共展示了Handle::Int32Value方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SerializeField
void SerializeField(google::protobuf::Message *message, const Reflection *r, const FieldDescriptor *field, Handle<Value> val) {
const EnumValueDescriptor *enumValue = NULL;
bool repeated = field->is_repeated();
switch (field->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32:
SET_VALUE(Int32, val->Int32Value());
break;
case FieldDescriptor::CPPTYPE_INT64:
SET_VALUE(Int64, val->NumberValue());
break;
case FieldDescriptor::CPPTYPE_UINT32:
SET_VALUE(UInt32, val->Uint32Value());
break;
case FieldDescriptor::CPPTYPE_UINT64:
SET_VALUE(UInt64, val->NumberValue());
break;
case FieldDescriptor::CPPTYPE_DOUBLE:
SET_VALUE(Double, val->NumberValue());
break;
case FieldDescriptor::CPPTYPE_FLOAT:
SET_VALUE(Float, val->NumberValue());
break;
case FieldDescriptor::CPPTYPE_BOOL:
SET_VALUE(Bool, val->BooleanValue());
break;
case FieldDescriptor::CPPTYPE_ENUM:
enumValue = val->IsNumber() ?
field->enum_type()->FindValueByNumber(val->Int32Value()) :
field->enum_type()->FindValueByName(*String::AsciiValue(val));
if (enumValue != NULL)
SET_VALUE(Enum, enumValue);
break;
case FieldDescriptor::CPPTYPE_MESSAGE:
if (val->IsObject()) {
Type* type = protobuf->GetType(field->message_type());
type->SerializePart(repeated ?
r->AddMessage(message, field) :
r->MutableMessage(message, field), val.As<Object>());
}
break;
case FieldDescriptor::CPPTYPE_STRING:
if (Buffer::HasInstance(val)) {
Local<Object> buf = val->ToObject();
SET_VALUE(String, std::string(Buffer::Data(buf), Buffer::Length(buf)));
} else {
String::Utf8Value utf8(val);
SET_VALUE(String, std::string(*utf8, utf8.length()));
}
break;
}
}
示例2: setField
inline bool setField(OGRFeature* f, int field_index, Handle<Value> val){
if (val->IsInt32()) {
f->SetField(field_index, val->Int32Value());
} else if (val->IsNumber()) {
f->SetField(field_index, val->NumberValue());
} else if (val->IsString()) {
std::string str = *NanUtf8String(val);
f->SetField(field_index, str.c_str());
} else if(val->IsNull() || val->IsUndefined()) {
f->UnsetField(field_index);
} else {
return true;
}
return false;
}
示例3: ToJavaString
int Conv::ToJavaString(JNIEnv *jniEnv, Handle<Value> val, jstring *jVal) {
Handle<String> vString;
Handle<Value> empty, vRes;
jstring ob;
char buf[64];
switch(GetNaturalType(val)) {
default: {
if(val->IsObject()) {
/* call ToString() in javascript */
Handle<Object> oVal = val->ToObject();
Handle<Value> vToString = oVal->Get(sToString);
if(!vToString.IsEmpty() && vToString->IsFunction()) {
Handle<Function> fToString = Handle<Function>::Cast(vToString);
vRes = fToString->CallAsFunction(oVal, 0, &empty);
if(!vRes.IsEmpty() && (vRes->IsString() || vRes->IsStringObject())) {
return ToJavaString(jniEnv, vRes->ToString(), jVal);
}
}
}
return ErrorType;
}
case TYPE_UNDEFINED:
case TYPE_NULL:
*jVal = 0;
return OK;
case TYPE_BOOL:
return ToJavaString(jniEnv, (val->BooleanValue() ? "true" : "false"), jVal);
case TYPE_INT:
sprintf(buf, "%d", val->Int32Value());
return ToJavaString(jniEnv, buf, jVal);
case TYPE_LONG:
sprintf(buf, "%lld", val->IntegerValue());
return ToJavaString(jniEnv, buf, jVal);
case TYPE_DOUBLE:
sprintf(buf, "%g", val->NumberValue());
return ToJavaString(jniEnv, buf, jVal);
case TYPE_STRING:
return ToJavaString(jniEnv, val->ToString(), (jstring *)jVal);
}
if(ob) {
*jVal = ob;
return OK;
}
if(jniEnv->ExceptionCheck())
jniEnv->ExceptionClear();
return ErrorVM;
}
示例4: rr_v82rb
VALUE rr_v82rb(Handle<Value> value) {
if (value.IsEmpty()) {
return rr_v8_value_empty();
}
if (value->IsUndefined() || value->IsNull()) {
return Qnil;
}
if (value->IsExternal()) {
return rr_reflect_v8_external(value);
}
if (value->IsUint32()) {
return UINT2NUM(value->Uint32Value());
}
if (value->IsInt32()) {
return INT2FIX(value->Int32Value());
}
if (value->IsBoolean()) {
return value->BooleanValue() ? Qtrue : Qfalse;
}
if (value->IsNumber()) {
return rb_float_new(value->NumberValue());
}
if (value->IsString()) {
return rr_reflect_v8_string(value);
}
if (value->IsFunction()) {
return rr_reflect_v8_function(value);
}
if (value->IsArray()) {
return rr_reflect_v8_array(value);
}
if (value->IsDate()) {
return rr_reflect_v8_date(value);
}
if (value->IsObject()) {
return rr_reflect_v8_object(value);
}
return rr_wrap_v8_value(value);
}
示例5: if
jsvalue JsEngine::AnyFromV8(Handle<Value> value, Handle<Object> thisArg)
{
jsvalue v;
// Initialize to a generic error.
v.type = JSVALUE_TYPE_UNKNOWN_ERROR;
v.length = 0;
v.value.str = 0;
if (value->IsNull() || value->IsUndefined()) {
v.type = JSVALUE_TYPE_NULL;
}
else if (value->IsBoolean()) {
v.type = JSVALUE_TYPE_BOOLEAN;
v.value.i32 = value->BooleanValue() ? 1 : 0;
}
else if (value->IsInt32()) {
v.type = JSVALUE_TYPE_INTEGER;
v.value.i32 = value->Int32Value();
}
else if (value->IsUint32()) {
v.type = JSVALUE_TYPE_INDEX;
v.value.i64 = value->Uint32Value();
}
else if (value->IsNumber()) {
v.type = JSVALUE_TYPE_NUMBER;
v.value.num = value->NumberValue();
}
else if (value->IsString()) {
v = StringFromV8(value);
}
else if (value->IsDate()) {
v.type = JSVALUE_TYPE_DATE;
v.value.num = value->NumberValue();
}
else if (value->IsArray()) {
Handle<Array> object = Handle<Array>::Cast(value->ToObject());
v.length = object->Length();
jsvalue* array = new jsvalue[v.length];
if (array != NULL) {
for(int i = 0; i < v.length; i++) {
array[i] = AnyFromV8(object->Get(i));
}
v.type = JSVALUE_TYPE_ARRAY;
v.value.arr = array;
}
}
else if (value->IsFunction()) {
Handle<Function> function = Handle<Function>::Cast(value);
jsvalue* array = new jsvalue[2];
if (array != NULL) {
array[0].value.ptr = new Persistent<Object>(Persistent<Function>::New(function));
array[0].length = 0;
array[0].type = JSVALUE_TYPE_WRAPPED;
if (!thisArg.IsEmpty()) {
array[1].value.ptr = new Persistent<Object>(Persistent<Object>::New(thisArg));
array[1].length = 0;
array[1].type = JSVALUE_TYPE_WRAPPED;
} else {
array[1].value.ptr = NULL;
array[1].length = 0;
array[1].type = JSVALUE_TYPE_NULL;
}
v.type = JSVALUE_TYPE_FUNCTION;
v.value.arr = array;
}
}
else if (value->IsObject()) {
Handle<Object> obj = Handle<Object>::Cast(value);
if (obj->InternalFieldCount() == 1)
v = ManagedFromV8(obj);
else
v = WrappedFromV8(obj);
}
return v;
}
示例6: ToJavaObject
int Conv::ToJavaObject(JNIEnv *jniEnv, Handle<Value> val, int expectedType, jobject *jVal) {
/* empty, null and undefined convert to null for any nullable type */
if((expectedType >= TYPE__OB_START) && (val.IsEmpty() || val->IsNull() || val->IsUndefined())) {
*jVal = 0;
return OK;
}
if(isSequence(expectedType))
return ToJavaSequence(jniEnv, val, getComponentType(expectedType), (jarray *)jVal);
if(isArray(expectedType))
return arrayConv->ToJavaArray(jniEnv, val, getComponentType(expectedType), jVal);
if(isMap(expectedType))
return ToJavaMap(jniEnv, val, getComponentType(expectedType), jVal);
if(isInterface(expectedType))
return ToJavaInterface(jniEnv, val, getClassId(expectedType), jVal);
if(isDict(expectedType))
return ToJavaDict(jniEnv, val, getClassId(expectedType), jVal);
HandleScope scope;
jobject ob;
switch(expectedType) {
default:
return ErrorType;
case TYPE_BOOL: {
bool isVoid = val.IsEmpty() ? false : val->BooleanValue();
ob = jniEnv->CallStaticObjectMethod(jni.anode.js.JSValue_Bool.class_, jni.anode.js.JSValue_Bool.ctor, isVoid);
break;
}
case TYPE_BYTE:
case TYPE_INT: {
jint intValue = val.IsEmpty() ? 0 : val->Int32Value();
ob = jniEnv->CallStaticObjectMethod(jni.anode.js.JSValue_Long.class_, jni.anode.js.JSValue_Long.ctor, (jlong)intValue);
break;
}
case TYPE_LONG: {
jlong longValue = val.IsEmpty() ? 0 : val->IntegerValue();
ob = jniEnv->CallStaticObjectMethod(jni.anode.js.JSValue_Long.class_, jni.anode.js.JSValue_Long.ctor, longValue);
break;
}
case TYPE_DOUBLE: {
jdouble doubleValue = val.IsEmpty() ? 0 : val->NumberValue();
ob = jniEnv->CallStaticObjectMethod(jni.anode.js.JSValue_Double.class_, jni.anode.js.JSValue_Double.ctor, doubleValue);
break;
}
case TYPE_STRING:
return ToJavaString(jniEnv, val, (jstring *)jVal);
case TYPE_DATE:
return ToJavaDate(jniEnv, val, jVal);
case TYPE_OBJECT:
return ToNaturalJavaObject(jniEnv, val, jVal);
case TYPE_OBJECT|TYPE_BOOL: {
bool isVoid = val->BooleanValue();
ob = jniEnv->NewObject(jni.java.lang.Boolean.class_, jni.java.lang.Boolean.ctor, isVoid);
break;
}
case TYPE_OBJECT|TYPE_BYTE: {
jbyte byteValue = val->Int32Value();
ob = jniEnv->NewObject(jni.java.lang.Byte.class_, jni.java.lang.Byte.ctor, byteValue);
break;
}
case TYPE_OBJECT|TYPE_INT: {
jint intValue = val->Int32Value();
ob = jniEnv->NewObject(jni.java.lang.Integer.class_, jni.java.lang.Integer.ctor, intValue);
break;
}
case TYPE_OBJECT|TYPE_LONG: {
jlong longValue = val->IntegerValue();
ob = jniEnv->NewObject(jni.java.lang.Long.class_, jni.java.lang.Long.ctor, longValue);
break;
}
case TYPE_OBJECT|TYPE_DOUBLE: {
jdouble doubleValue = val->NumberValue();
ob = jniEnv->NewObject(jni.java.lang.Double.class_, jni.java.lang.Double.ctor, doubleValue);
break;
}
}
if(ob) {
*jVal = ob;
return OK;
}
if(jniEnv->ExceptionCheck())
jniEnv->ExceptionClear();
return ErrorVM;
}
示例7: SerializeField
void SerializeField(google::protobuf::Message *message, const Reflection *r, const FieldDescriptor *field, Handle<Value> val) {
const EnumValueDescriptor *enumValue = NULL;
bool repeated = field->is_repeated();
if (*val != NULL) {
if (field->is_optional() && (val->IsNull() || val->IsUndefined()))
return;
switch (field->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32: {
if (repeated)
r->AddInt32(message, field, val->Int32Value());
else
r->SetInt32(message, field, val->Int32Value());
break;
}
case FieldDescriptor::CPPTYPE_INT64:
if (repeated)
if (preserve_int64 && val->IsArray()) {
Local<Object> n64_array = val->ToObject();
uint64 n64;
uint32 hi = n64_array->Get(0)->Uint32Value(), lo = n64_array->Get(1)->Uint32Value();
n64 = ((uint64)hi << 32) + (uint64)lo;
r->AddInt64(message, field, n64);
} else
r->AddInt64(message, field, val->NumberValue());
else
if (preserve_int64 && val->IsArray()) {
Local<Object> n64_array = val->ToObject();
uint64 n64;
uint32 hi = n64_array->Get(0)->Uint32Value(), lo = n64_array->Get(1)->Uint32Value();
n64 = ((uint64)hi << 32) + (uint64)lo;
r->SetInt64(message, field, n64);
} else
r->SetInt64(message, field, val->NumberValue());
break;
case FieldDescriptor::CPPTYPE_UINT32:
if (repeated)
r->AddUInt32(message, field, val->Uint32Value());
else
r->SetUInt32(message, field, val->Uint32Value());
break;
case FieldDescriptor::CPPTYPE_UINT64:
if (repeated)
if (preserve_int64 && val->IsArray()) {
Local<Object> n64_array = val->ToObject();
uint64 n64;
uint32 hi = n64_array->Get(0)->Uint32Value(), lo = n64_array->Get(1)->Uint32Value();
n64 = ((uint64)hi << 32) + (uint64)lo;
r->AddUInt64(message, field, n64);
} else
r->AddUInt64(message, field, val->NumberValue());
else
if (preserve_int64 && val->IsArray()) {
Local<Object> n64_array = val->ToObject();
uint64 n64;
uint32 hi = n64_array->Get(0)->Uint32Value(), lo = n64_array->Get(1)->Uint32Value();
n64 = ((uint64)hi << 32) + (uint64)lo;
r->SetUInt64(message, field, n64);
} else
r->SetUInt64(message, field, val->NumberValue());
break;
case FieldDescriptor::CPPTYPE_DOUBLE:
if (repeated)
r->AddDouble(message, field, val->NumberValue());
else
r->SetDouble(message, field, val->NumberValue());
break;
case FieldDescriptor::CPPTYPE_FLOAT:
if (repeated)
r->AddFloat(message, field, val->NumberValue());
else
r->SetFloat(message, field, val->NumberValue());
break;
case FieldDescriptor::CPPTYPE_BOOL:
if (repeated)
r->AddBool(message, field, val->BooleanValue());
else
r->SetBool(message, field, val->BooleanValue());
break;
case FieldDescriptor::CPPTYPE_ENUM:
// TODO: possible memory leak?
enumValue =
val->IsNumber() ?
field->enum_type()->FindValueByNumber(val->Int32Value()) :
field->enum_type()->FindValueByName(*NanAsciiString(val));
if (enumValue != NULL) {
if (repeated)
r->AddEnum(message, field, enumValue);
else
r->SetEnum(message, field, enumValue);
}
break;
case FieldDescriptor::CPPTYPE_MESSAGE:
if (val->IsObject()) {
if (repeated)
SerializePart(r->AddMessage(message, field), val.As<Object>());
else
SerializePart(r->MutableMessage(message, field), val.As<Object>());
//.........这里部分代码省略.........
示例8:
int32_t Get<int32_t> (Handle<Value> value) {
return value->Int32Value();
}