当前位置: 首页>>代码示例>>C++>>正文


C++ JPType类代码示例

本文整理汇总了C++中JPType的典型用法代码示例。如果您正苦于以下问题:C++ JPType类的具体用法?C++ JPType怎么用?C++ JPType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了JPType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TRACE_IN

void JPField::setStaticAttribute(HostRef* val)
{
    TRACE_IN("JPField::setStaticAttribute");

    if (m_IsFinal)
    {
        stringstream err;
        err << "Field " << m_Name << " is read-only";
        RAISE(JPypeException, err.str().c_str());
    }

    JPType* type = JPTypeManager::getType(m_Type);
    if (type->canConvertToJava(val) <= _explicit)
    {
        stringstream err;
        err << "unable to convert to " << type->getName().getSimpleName();
        RAISE(JPypeException, err.str().c_str());
    }

    JPCleaner cleaner;
    jclass claz = m_Class->getClass();
    cleaner.addLocal(claz);

    type->setStaticValue(claz, m_FieldID, val);
    TRACE_OUT;
}
开发者ID:ktan2020,项目名称:python_stuff,代码行数:26,代码来源:jp_field.cpp

示例2: TRACE_IN

PyObject* JPypeJavaNio::convertToDirectBuffer(PyObject* self, PyObject* args)
{  
	TRACE_IN("convertStringToBuffer"); 

	// Use special method defined on the TypeConverter interface ...
	PyObject* src;

	JPyArg::parseTuple(args, "O", &src);

	PyObject* res = NULL;
	if (JPyObject::isMemoryView(src))
	{
		// converts to byte buffer ...
		JPTypeName tname = JPTypeName::fromType(JPTypeName::_byte);
		JPType* type = JPTypeManager::getType(tname);
		HostRef srcRef(src);

		TRACE1("Converting");
		HostRef* ref = type->convertToDirectBuffer(&srcRef);
		JPEnv::registerRef(ref, &srcRef);

		TRACE1("detaching result");
		res = detachRef(ref);
	}

	if (res != NULL)
	{
		return res;
	}

	RAISE(JPypeException, "Do not know how to convert to direct byte buffer, only memory view supported");

	return NULL;
	TRACE_OUT;
}
开发者ID:Eothred,项目名称:jpype,代码行数:35,代码来源:jpype_javanio.cpp

示例3: setRange

void JPArray::setRange(int start, int stop, vector<HostRef*>& val)
{
	JPCleaner cleaner;
	
	JPType* compType = m_Class->getComponentType();
	
	if(stop < start)
	{
		std::stringstream out;
		out << "Slice start (" << start << ") is greater than stop ("
			<< stop << ")";
		RAISE(JPypeException, out.str());
	}

	unsigned int len = stop-start;
	size_t plength = val.size();
	
	if (len != plength)
	{
		std::stringstream out;
		out << "Slice assignment must be of equal lengths : " << len << " != " << plength;
		RAISE(JPypeException, out.str());
	}

	for (size_t i = 0; i < plength; i++)
	{
		HostRef* v = val[i];
		if ( compType->canConvertToJava(v)<= _explicit)
		{
			RAISE(JPypeException, "Unable to convert.");
		}
	}	
			
	compType->setArrayRange(m_Object, start, stop-start, val);
}	
开发者ID:Kcrong,项目名称:speech_analysis,代码行数:35,代码来源:jp_array.cpp

示例4: 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;
}
开发者ID:jaheba,项目名称:jpype,代码行数:33,代码来源:jpype_python.cpp

示例5: TRACE_IN

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;
}
开发者ID:Eothred,项目名称:jpype,代码行数:32,代码来源:jp_methodoverload.cpp

示例6: getSequenceFromRange

PyObject* JPArray::getSequenceFromRange(int start, int stop)
{
//	TRACE_IN("JPArray::getSequenceFromRange");
	JPType* compType = m_Class->getComponentType();
//	TRACE2("Component type", compType->getName().getSimpleName());

	return compType->getArrayRangeToSequence(m_Object, start, stop);
}
开发者ID:jaheba,项目名称:jpype,代码行数:8,代码来源:jp_array.cpp

示例7: setItem

void JPArray::setItem(int ndx, HostRef* val)
{
	JPType* compType = m_Class->getComponentType();
	if (compType->canConvertToJava(val) <= _explicit)
	{
		RAISE(JPypeException, "Unable to convert.");
	}	
	
	compType->setArrayItem(m_Object, ndx, val);
}
开发者ID:Kcrong,项目名称:speech_analysis,代码行数:10,代码来源:jp_array.cpp

示例8: TRACE_IN

vector<HostRef*> JPArray::getRange(int start, int stop)
{
	TRACE_IN("JPArray::getRange");
	JPType* compType = m_Class->getComponentType();
	TRACE2("Component type", compType->getName().getSimpleName());
	
	vector<HostRef*> res = compType->getArrayRange(m_Object, start, stop-start);
	
	return res;
	TRACE_OUT;
}	
开发者ID:Kcrong,项目名称:speech_analysis,代码行数:11,代码来源:jp_array.cpp

示例9: TRACE_IN

HostRef* JPObjectType::getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType) 
{
	TRACE_IN("JPObjectType::getInstanceValue");
	JPCleaner cleaner;
	jobject r = JPEnv::getJava()->GetObjectField(c, fid);
	cleaner.addLocal(r);

	jvalue v;
	v.l = r;
	
	JPTypeName name = JPJni::getClassName(v.l);
	JPType* type = JPTypeManager::getType(name);
	return type->asHostObject(v);

	TRACE_OUT;
}
开发者ID:Kcrong,项目名称:speech_analysis,代码行数:16,代码来源:jp_objecttypes.cpp

示例10: setRange

void JPArray::setRange(int start, int stop, PyObject* sequence)
{
	JPType* compType = m_Class->getComponentType();

	unsigned int len = stop-start;
	// check bounds of sequence which is to be assigned
	HostRef* ptr = new HostRef(sequence);
	unsigned int plength = JPEnv::getHost()->getSequenceLength(ptr);
	delete ptr;
	if (len != plength)
	{
		std::stringstream out;
		out << "Slice assignment must be of equal lengths : " << len << " != " << plength;
		RAISE(JPypeException, out.str());
	}

	compType->setArrayRange(m_Object, start, len, sequence);
}
开发者ID:jaheba,项目名称:jpype,代码行数:18,代码来源:jp_array.cpp

示例11: TRACE_IN

HostRef* JPClass::asHostObject(jvalue obj) 
{
	TRACE_IN("JPClass::asPyObject");
	if (obj.l == NULL)
	{
		return JPEnv::getHost()->getNone();
	}

	JPTypeName name = JPJni::getClassName(obj.l);
	if (name.getType() ==JPTypeName::_array)
	{
		JPType* arrayType = JPTypeManager::getType(name);
		return arrayType->asHostObject(obj);
	}
	
	return JPEnv::getHost()->newObject(new JPObject(name, obj.l));
	TRACE_OUT;
}
开发者ID:Kcrong,项目名称:speech_analysis,代码行数:18,代码来源:jp_class.cpp

示例12:

vector<HostRef*> JPObjectType::getArrayRange(jarray a, int start, int length)
{
	jobjectArray array = (jobjectArray)a;	
	JPCleaner cleaner;
	
	vector<HostRef*> res;
	
	jvalue v;
	for (int i = 0; i < length; i++)
	{
		v.l = JPEnv::getJava()->GetObjectArrayElement(array, i+start);
		cleaner.addLocal(v.l);

		JPTypeName name = JPJni::getClassName(v.l);
		JPType* t = JPTypeManager::getType(name);
		
		HostRef* pv = t->asHostObject(v);		

		res.push_back(pv);
	}
	
	return res;  
}
开发者ID:Kcrong,项目名称:speech_analysis,代码行数:23,代码来源:jp_objecttypes.cpp

示例13: Java_jpype_JPypeInvocationHandler_hostInvoke

JNIEXPORT jobject JNICALL Java_jpype_JPypeInvocationHandler_hostInvoke(
	JNIEnv *env, jclass clazz, jstring name, 
	jlong hostObj, jobjectArray args, 
	jobjectArray types, jclass returnType)
{
	TRACE_IN("Java_jpype_JPypeInvocationHandler_hostInvoke");

	void* callbackState = JPEnv::getHost()->prepareCallbackBegin();

	JPCleaner cleaner;

	try {
		string cname = JPJni::asciiFromJava(name);

		HostRef* hostObjRef = (HostRef*)hostObj;

		HostRef* callable = JPEnv::getHost()->getCallableFrom(hostObjRef, cname);
		cleaner.add(callable);

		if (callable == NULL || callable->isNull() || JPEnv::getHost()->isNone(callable))
		{
			JPEnv::getJava()->ThrowNew(JPJni::s_NoSuchMethodErrorClass, cname.c_str());
			JPEnv::getHost()->prepareCallbackFinish(callbackState);
			return NULL;
		}
					
		// convert the arguments into a python list
		jsize argLen = JPEnv::getJava()->GetArrayLength(types);
		vector<HostRef*> hostArgs;
		std::vector<JPTypeName> argTypes;

		for (jsize j = 0; j < argLen; j++)
		{
			jclass c = (jclass)JPEnv::getJava()->GetObjectArrayElement(types, j);
			cleaner.addLocal(c);
			JPTypeName tn = JPJni::getName(c);
			argTypes.push_back(tn);
		}

		for (int i = 0; i < argLen; i++)
		{
			jobject obj = JPEnv::getJava()->GetObjectArrayElement(args, i);
			cleaner.addLocal(obj);
			JPTypeName t = argTypes[i];

			jvalue v;
			v.l = obj;

			HostRef* o = JPTypeManager::getType(t)->asHostObjectFromObject(v);
			cleaner.add(o);
			hostArgs.push_back(o);

		}

		HostRef* returnValue = JPEnv::getHost()->callObject(callable, hostArgs);
		cleaner.add(returnValue);

		JPTypeName returnT = JPJni::getName(returnType);

		if (returnValue == NULL || returnValue->isNull() || JPEnv::getHost()->isNone(returnValue))
		{
			if (returnT.getType() != JPTypeName::_void && returnT.getType() < JPTypeName::_object)
			{
				JPEnv::getJava()->ThrowNew(JPJni::s_RuntimeExceptionClass, "Return value is None when it cannot be");
				JPEnv::getHost()->prepareCallbackFinish(callbackState);
				return NULL;
			}
		}

		if (returnT.getType() == JPTypeName::_void)
		{
			JPEnv::getHost()->prepareCallbackFinish(callbackState);
			return NULL;
		}

		JPType* rt = JPTypeManager::getType(returnT);
		if (rt->canConvertToJava(returnValue) == _none)
		{
			JPEnv::getJava()->ThrowNew(JPJni::s_RuntimeExceptionClass, "Return value is not compatible with required type.");
			JPEnv::getHost()->prepareCallbackFinish(callbackState);
			return NULL;
		}
		
		jobject returnObj = rt->convertToJavaObject(returnValue);

		JPEnv::getHost()->prepareCallbackFinish(callbackState);

		return returnObj;

	}
	catch(HostException* ex) 
	{ 
		JPEnv::getHost()->clearError();
		if (JPEnv::getHost()->isJavaException(ex))
		{
			JPCleaner cleaner;
			HostRef* javaExcRef = JPEnv::getHost()->getJavaException(ex);
			JPObject* javaExc = JPEnv::getHost()->asObject(javaExcRef);
			cleaner.add(javaExcRef);
			jobject obj = javaExc->getObject();
//.........这里部分代码省略.........
开发者ID:Koblaid,项目名称:jpype,代码行数:101,代码来源:jp_proxy.cpp

示例14: buildObjectWrapper

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;
}
开发者ID:Kcrong,项目名称:speech_analysis,代码行数:93,代码来源:jp_class.cpp

示例15: getItem

HostRef* JPArray::getItem(int ndx)
{
	JPType* compType = m_Class->getComponentType();

	return compType->getArrayItem(m_Object, ndx);
}
开发者ID:Kcrong,项目名称:speech_analysis,代码行数:6,代码来源:jp_array.cpp


注:本文中的JPType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。