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


C++ JPCleaner类代码示例

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


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

示例1: getMethods

vector<jobject> getMethods(jclass clazz)
{
	JPCleaner cleaner;
	jobjectArray methods = (jobjectArray)JPEnv::getJava()->CallObjectMethod(clazz, getMethodsID);
	cleaner.addLocal(methods);

	int len = JPEnv::getJava()->GetArrayLength(methods);
	vector<jobject> res;
	for (int i = 0; i < len; i++)
	{
		jobject c = JPEnv::getJava()->GetObjectArrayElement(methods, i);
		res.push_back(c);
	}

	return res;
}
开发者ID:baztian,项目名称:jpype,代码行数:16,代码来源:jp_jniutil.cpp

示例2: setArrayRange

void JPObjectType::setArrayRange(jarray a, int start, int length, vector<HostRef*>& vals)
{
	jobjectArray array = (jobjectArray)a;	
	JPCleaner cleaner;
	
	jvalue v;
	for (int i = 0; i < length; i++)
	{
		HostRef* pv = vals[i];
		
		v = convertToJava(pv);
		cleaner.addLocal(v.l);

		JPEnv::getJava()->SetObjectArrayElement(array, i+start, v.l);
	}
}
开发者ID:Kcrong,项目名称:speech_analysis,代码行数:16,代码来源:jp_objecttypes.cpp

示例3: 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

示例4: getInterfaces

vector<jclass> getInterfaces(jclass clazz)
{
	JPCleaner cleaner;
	jobjectArray interfaces = (jobjectArray)JPEnv::getJava()->CallObjectMethod(clazz, getInterfacesID);
	cleaner.addLocal(interfaces);

	int len = JPEnv::getJava()->GetArrayLength(interfaces);
	vector<jclass> res;
	for (int i = 0; i < len; i++)
	{
		jclass c = (jclass)JPEnv::getJava()->GetObjectArrayElement(interfaces, i);
		res.push_back(c);
	}

	return res;
}
开发者ID:baztian,项目名称:jpype,代码行数:16,代码来源:jp_jniutil.cpp

示例5: TRACE_IN

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

示例6: TRACE_IN

void JPProxy::init()
{
	TRACE_IN("JPProxy::init");

	// build the proxy class ...
	jobject cl = JPJni::getSystemClassLoader();
	JPCleaner cleaner;

	jclass handler = JPEnv::getJava()->DefineClass("jpype/JPypeInvocationHandler", cl, JPypeInvocationHandler, getJPypeInvocationHandlerLength());
	handlerClass = (jclass)JPEnv::getJava()->NewGlobalRef(handler);
	cleaner.addLocal(handler);
	
	JNINativeMethod method[1];
	method[0].name = (char*) "hostInvoke";
	method[0].signature =(char*) "(Ljava/lang/String;J[Ljava/lang/Object;[Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/Object;";
	method[0].fnPtr = (void*) &Java_jpype_JPypeInvocationHandler_hostInvoke;


	hostObjectID = JPEnv::getJava()->GetFieldID(handler, "hostObject", "J");
	invocationHandlerConstructorID = JPEnv::getJava()->GetMethodID(handler, "<init>", "()V");

	JPEnv::getJava()->RegisterNatives(handlerClass, method, 1);

	// Not quite the right area ... but I;m doing similar here already so let's register the other classes too
	jclass reference = JPEnv::getJava()->DefineClass("jpype/ref/JPypeReference", cl, JPypeReference, getJPypeReferenceLength());
	jclass referenceQueue = JPEnv::getJava()->DefineClass("jpype/ref/JPypeReferenceQueue", cl, JPypeReferenceQueue, getJPypeReferenceQueueLength());
	referenceClass = (jclass)JPEnv::getJava()->NewGlobalRef(reference);
	referenceQueueClass = (jclass)JPEnv::getJava()->NewGlobalRef(referenceQueue);

	//Required due to bug in jvm
	//See: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6493522
	jmethodID refQConstr = JPEnv::getJava()->GetMethodID(referenceQueue, "<init>", "()V");

	cleaner.addLocal(reference);
	cleaner.addLocal(referenceQueue);

	JNINativeMethod method2[1];
	method2[0].name = (char*) "removeHostReference";
	method2[0].signature = (char*) "(J)V";
	method2[0].fnPtr = (void*)&Java_jpype_ref_JPypeReferenceQueue_removeHostReference;

	JPEnv::getJava()->RegisterNatives(referenceQueueClass, method2, 1);

	TRACE_OUT;

}
开发者ID:Sunyifan,项目名称:jpype,代码行数:46,代码来源:jp_proxy.cpp

示例7: if

PyObject* JPypeJavaArray::getArraySlice(PyObject* self, PyObject* arg)
{
	PyObject* arrayObject;
	int lo = -1;
	int hi = -1;
	try
	{

		JPyArg::parseTuple(arg, "O!ii", &PyCapsule_Type, &arrayObject, &lo, &hi);
		JPArray* a = (JPArray*)JPyCObject::asVoidPtr(arrayObject);
		int length = a->getLength();
		// stolen from jcc, to get nice slice support
		if (lo < 0) lo = length + lo;
		if (lo < 0) lo = 0;
		else if (lo > length) lo = length;
		if (hi < 0) hi = length + hi;
		if (hi < 0) hi = 0;
		else if (hi > length) hi = length;
		if (lo > hi) lo = hi;

		const JPTypeName& componentName = a->getType()->getObjectType().getComponentName();
		const string& name = componentName.getNativeName();
		if(is_primitive(name[0]))
		{
			// for primitive types, we have fast sequence generation available
			return a->getSequenceFromRange(lo, hi);
		}
		else
		{
			// slow wrapped access for non primitives
			vector<HostRef*> values = a->getRange(lo, hi);

			JPCleaner cleaner;
			PyObject* res = JPySequence::newList((int)values.size());
			for (unsigned int i = 0; i < values.size(); i++)
			{
				JPySequence::setItem(res, i, (PyObject*)values[i]->data());
				cleaner.add(values[i]);
			}

			return res;
		}
	} PY_STANDARD_CATCH

	return NULL;
}
开发者ID:baztian,项目名称:jpype,代码行数:46,代码来源:jpype_javaarray.cpp

示例8: loadSuperClass

void JPClass::loadSuperClass() 
{	
	JPCleaner cleaner;

	// base class .. if any
	if (!m_IsInterface && m_Name.getSimpleName() != "java.lang.Object")
	{
		jclass baseClass = JPEnv::getJava()->GetSuperclass(m_Class);
		cleaner.addLocal(baseClass);

		if (baseClass != NULL) 
		{
			JPTypeName baseClassName = JPJni::getName(baseClass);		
			m_SuperClass = JPTypeManager::findClass(baseClassName);
		}
	}
}
开发者ID:Kcrong,项目名称:speech_analysis,代码行数:17,代码来源:jp_class.cpp

示例9: convertToJavaObject

jobject JPPrimitiveType::convertToJavaObject(HostRef* obj)
{
	JPCleaner cleaner;
	JPTypeName tname = getObjectType();
	JPClass* c = JPTypeManager::findClass(tname);

	jclass jc = c->getClass();
	cleaner.addLocal(jc);

	vector<HostRef*> args(1);
	args[0] = obj;

	JPObject* o = c->newInstance(args);
	jobject res = o->getObject();
	delete o;

	return res;
}
开发者ID:tcalmant,项目名称:jpype-py3,代码行数:18,代码来源:jp_primitivetypes.cpp

示例10: loadMethods

void JPClass::loadMethods() 
{	
	JPCleaner cleaner;
	JPCleaner pcleaner;

	// methods
	vector<jobject> methods = JPJni::getDeclaredMethods(m_Class);
	cleaner.addAllLocal(methods);

	for (vector<jobject>::iterator it = methods.begin(); it != methods.end(); it++)
	{
		string name = JPJni::getMemberName(*it);

		if (JPJni::isMemberPublic(*it) && !JPJni::isMemberAbstract(*it) )
		{
			JPMethod* method = getMethod(name);
			if (method == NULL)
			{
				method = new JPMethod(m_Class, name, false);
				m_Methods[name] = method; 
			}
			
			method->addOverload(this, *it);			
		
		
		}

		
	}

	// add previous overloads to methods defined in THIS class
	if (m_SuperClass != NULL)
	{
		for (map<string, JPMethod*>::iterator cur = m_Methods.begin(); cur != m_Methods.end(); cur ++)
		{
			string name = cur->first;
			JPMethod* superMethod = m_SuperClass->getMethod(name);
			if (superMethod != NULL)
			{
				cur->second->addOverloads(superMethod);
			}
		}
	}		
}
开发者ID:Kcrong,项目名称:speech_analysis,代码行数:44,代码来源:jp_class.cpp

示例11: registerRef

void registerRef(jobject refQueue, jobject obj, jlong hostRef)
{
	TRACE_IN("registerRef");
	// create the ref ...
	jvalue args[2];
	args[0].l = obj;
	args[1].l = refQueue;

	JPCleaner cleaner;

	jobject refObj = JPEnv::getJava()->NewObjectA(JPypeReferenceClass, JPypeReferenceConstructorMethod, args);
	cleaner.addLocal(refObj);

	args[0].l = refObj;
	args[1].j = hostRef;

	JPEnv::getJava()->CallVoidMethodA(refQueue, JPypeReferenceQueueRegisterMethod, args);
	TRACE_OUT;
}
开发者ID:baztian,项目名称:jpype,代码行数:19,代码来源:jp_jniutil.cpp

示例12: setArrayItem

PyObject* JPypeJavaArray::setArrayItem(PyObject* self, PyObject* arg)
{
	try {
		PyObject* arrayObject;
		int ndx;
		PyObject* value;
		JPyArg::parseTuple(arg, "O!iO", &PyCObject_Type, &arrayObject, &ndx, &value);
		JPArray* a = (JPArray*)JPyCObject::asVoidPtr(arrayObject);

		JPCleaner cleaner;
		HostRef* v = new HostRef(value);
		cleaner.add(v);

		a->setItem(ndx, v);
		Py_RETURN_NONE;
	}
	PY_STANDARD_CATCH

	return NULL;
}
开发者ID:jaheba,项目名称:jpype,代码行数:20,代码来源:jpype_javaarray.cpp

示例13: loadFields

void JPClass::loadFields() 
{	
	JPCleaner cleaner;
	// fields
	vector<jobject> fields = JPJni::getDeclaredFields(m_Class);
	cleaner.addAllLocal(fields);

	for (vector<jobject>::iterator it = fields.begin(); it != fields.end(); it++)
	{
		JPField* field = new JPField(this, *it);
		if (field->isStatic())
		{
			m_StaticFields[field->getName()] = field;  
		}
		else
		{
			m_InstanceFields[field->getName()] = field;  
		}			
	}	
}
开发者ID:Kcrong,项目名称:speech_analysis,代码行数:20,代码来源:jp_class.cpp

示例14: synchronized

PyObject* JPypeModule::synchronized(PyObject* obj, PyObject* args)
{
	JPCleaner cleaner;
	TRACE_IN("synchronized");
	try {
		PyObject* o;
		
		JPyArg::parseTuple(args, "O!", &PyCObject_Type, &o);
		string desc = (char*)JPyCObject::getDesc(o);

		jobject obj;
		if (desc == "JPObject")
		{
			JPObject* jpo = (JPObject*)JPyCObject::asVoidPtr(o);
			obj = jpo->getObject();
			cleaner.addLocal(obj);
		}
		else if (desc == "JPClass")
		{
			JPClass* jpo = (JPClass*)JPyCObject::asVoidPtr(o);
			obj = jpo->getClass();
			cleaner.addLocal(obj);
		}
		else if (desc == "JPArray")
		{
			JPArray* jpo = (JPArray*)JPyCObject::asVoidPtr(o);
			obj = jpo->getObject();
			cleaner.addLocal(obj);
		}
		else if (desc == "JPArrayClass")
		{
			JPArrayClass* jpo = (JPArrayClass*)JPyCObject::asVoidPtr(o);
			obj = jpo->getClass();
			cleaner.addLocal(obj);
		}
		else if (hostEnv->isWrapper(o) && hostEnv->getWrapperTypeName(o).isObjectType())
		{
			obj = hostEnv->getWrapperValue(o).l;
			cleaner.addLocal(obj);
		}
		// TODO proxy		
		else 
		{
			RAISE(JPypeException, "method only accepts object values.");
		}

		PyJPMonitor* c = PyJPMonitor::alloc(new JPMonitor(obj));

		return (PyObject*)c;
	}
	PY_STANDARD_CATCH;

	PyErr_Clear();

	Py_INCREF(Py_None);
	return Py_None;

	TRACE_OUT;
}
开发者ID:Koblaid,项目名称:jpype,代码行数:59,代码来源:jpype_module.cpp

示例15: getStackTrace

string getStackTrace(jthrowable th)
{

	JPCleaner cleaner;
	jobject strWriter = JPEnv::getJava()->NewObject(stringWriterClass, stringWriterID);
	cleaner.addLocal(strWriter);

	jvalue v;
	v.l = strWriter;
	jobject printWriter = JPEnv::getJava()->NewObjectA(printWriterClass, printWriterID, &v);
	cleaner.addLocal(printWriter);

	v.l = printWriter;
	JPEnv::getJava()->CallVoidMethodA(th, printStackTraceID, &v);

	JPEnv::getJava()->CallVoidMethod(printWriter, flushID);

	jstring res = toString(strWriter);
	cleaner.addLocal(res);

	return asciiFromJava(res);
}
开发者ID:baztian,项目名称:jpype,代码行数:22,代码来源:jp_jniutil.cpp


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