本文整理汇总了C++中JPType::convertToJava方法的典型用法代码示例。如果您正苦于以下问题:C++ JPType::convertToJava方法的具体用法?C++ JPType::convertToJava怎么用?C++ JPType::convertToJava使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JPType
的用法示例。
在下文中一共展示了JPType::convertToJava方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: convertToJValue
PyObject* convertToJValue(PyObject* self, PyObject* arg)
{
try {
char* tname;
PyObject* value;
JPyArg::parseTuple(arg, "sO", &tname, &value);
JPTypeName name = JPTypeName::fromSimple(tname);
JPType* type = JPTypeManager::getType(name);
HostRef ref(value);
jvalue v = type->convertToJava(&ref);
jvalue* pv = new jvalue();
*pv = v;
PyObject* res;
if (type->isObjectType())
{
res = JPyCObject::fromVoidAndDesc((void*)pv, (void*)"object jvalue", PythonHostEnvironment::deleteObjectJValueDestructor);
}
else
{
res = JPyCObject::fromVoidAndDesc((void*)pv, (void*)"jvalue", PythonHostEnvironment::deleteJValueDestructor);
}
return res;
}
PY_STANDARD_CATCH
return NULL;
}
示例2: invokeConstructor
JPObject* JPMethodOverload::invokeConstructor(jclass claz, vector<HostRef*>& arg)
{
TRACE_IN("JPMethodOverload::invokeConstructor");
size_t len = arg.size();
JPCleaner cleaner;
JPMallocCleaner<jvalue> v(len);
for (unsigned int i = 0; i < len; i++)
{
HostRef* obj = arg[i];
// TODO the following can easily be optimized ... or at least cached
JPType* t = JPTypeManager::getType(m_Arguments[i]);
v[i] = t->convertToJava(obj);
if (t->isObjectType())
{
cleaner.addLocal(v[i].l);
}
}
jvalue val;
val.l = JPEnv::getJava()->NewObjectA(claz, m_MethodID, v.borrow());
cleaner.addLocal(val.l);
TRACE1("Object created");
JPTypeName name = JPJni::getName(claz);
return new JPObject(name, val.l);
TRACE_OUT;
}
示例3: invokeInstance
HostRef* JPMethodOverload::invokeInstance(vector<HostRef*>& args)
{
TRACE_IN("JPMethodOverload::invokeInstance");
HostRef* res;
{
JPCleaner cleaner;
// Arg 0 is "this"
HostRef* self = args[0];
JPObject* selfObj = JPEnv::getHost()->asObject(self);
size_t len = args.size();
JPMallocCleaner<jvalue> v(len-1);
for (unsigned int i = 1; i < len; i++)
{
HostRef* obj = args[i];
JPType* type = JPTypeManager::getType(m_Arguments[i]);
v[i-1] = type->convertToJava(obj);
// below seems not to be necessary, since jvalues are clean by jpmalloccleaner
// if (type->isObjectType())
// {
// //TODO : investigate: this is not valid for either local or global ref
// // add hostref to garbage collection
// cleaner.add(v[i-1].l);
// }
}
JPType* retType = JPTypeManager::getType(m_ReturnType);
jobject c = selfObj->getObject();
cleaner.addLocal(c);
jclass clazz = m_Class->getClass();
cleaner.addGlobal(clazz);
res = retType->invoke(c, clazz, m_MethodID, v.borrow());
TRACE1("Call finished");
}
TRACE1("Call successfull");
return res;
TRACE_OUT;
}
示例4: convertToJava
jvalue JPClass::convertToJava(HostRef* obj)
{
jvalue res;
JPCleaner cleaner;
res.l = NULL;
// assume it is convertible;
if (JPEnv::getHost()->isNone(obj))
{
res.l = NULL;
}
string simpleName = m_Name.getSimpleName();
if (JPEnv::getHost()->isInt(obj) && (simpleName == "java.lang.Byte" || simpleName == "java.lang.Short" ||
simpleName == "java.lang.Integer"))
{
return buildObjectWrapper(obj);
}
if ((JPEnv::getHost()->isInt(obj) || JPEnv::getHost()->isLong(obj)) && simpleName == "java.lang.Long" && JPEnv::getHost()->isLong(obj))
{
return buildObjectWrapper(obj);
}
if (JPEnv::getHost()->isFloat(obj) && (simpleName == "java.lang.Float" || simpleName == "java.lang.Double"))
{
if (JPEnv::getHost()->isFloat(obj))
{
return buildObjectWrapper(obj);
}
}
if (JPEnv::getHost()->isString(obj))
{
JPTypeName name = JPTypeName::fromSimple("java.lang.String");
JPType* type = JPTypeManager::getType(name);
return type->convertToJava(obj);
}
if (JPEnv::getHost()->isObject(obj))
{
JPObject* ref = JPEnv::getHost()->asObject(obj);
res.l = ref->getObject();
}
if (JPEnv::getHost()->isProxy(obj))
{
JPProxy* proxy = JPEnv::getHost()->asProxy(obj);
res.l = proxy->getProxy();
}
if (JPEnv::getHost()->isWrapper(obj))
{
res = JPEnv::getHost()->getWrapperValue(obj);
}
if (JPEnv::getHost()->isInt(obj))
{
JPTypeName tname = JPTypeName::fromType(JPTypeName::_int);
JPType* t = JPTypeManager::getType(tname);
res.l = t->convertToJavaObject(obj);
}
if (JPEnv::getHost()->isLong(obj))
{
JPTypeName tname = JPTypeName::fromType(JPTypeName::_long);
JPType* t = JPTypeManager::getType(tname);
res.l = t->convertToJavaObject(obj);
}
if (JPEnv::getHost()->isFloat(obj))
{
JPTypeName tname = JPTypeName::fromType(JPTypeName::_double);
JPType* t = JPTypeManager::getType(tname);
res.l = t->convertToJavaObject(obj);
}
if (JPEnv::getHost()->isBoolean(obj))
{
JPTypeName tname = JPTypeName::fromType(JPTypeName::_boolean);
JPType* t = JPTypeManager::getType(tname);
res.l = t->convertToJavaObject(obj);
}
if (JPEnv::getHost()->isArray(obj) && simpleName == "java.lang.Object")
{
JPArray* a = JPEnv::getHost()->asArray(obj);
res = a->getValue();
}
return res;
}