JNIpp 1.0
JNI meets C++
jni::LObject Class Reference

Wrapper for local Java objects. More...

Inheritance diagram for jni::LObject:
jni::AbstractObject

List of all members.

Public Member Functions

 LObject ()
 Constructs empty object.
 LObject (const LObject &other)
 Copies Java object from other, adds local reference.
virtual ~LObject ()
 Deletes local reference from contained Java object.
void Swap (LObject &other)
 Swaps two instances.
virtual jobject GetJObject () const
 Returns contained Java object.
LObjectoperator= (const LObject &other)
 Copies Java object from other, adds local reference.
bool IsEmpty () const
 Returns true if object is empty (contains NULL Java object).
bool operator! () const
 Checks if object is empty (contains NULL Java object).
 operator ComparasionHelper * () const
 Comparasion helper.

Static Public Member Functions

static LObject Wrap (jobject object)
 Creates and returns LObject by adding a local reference to the object.
static LObject WrapLocal (jobject object)
 Creates and returns LObject, but DOES NOT add local reference.

Detailed Description

Wrapper for local Java objects.

Local objects are returned from functions like jni::NewObject() or jni::CallObjectMethod(). They have local references added to them and are valid only within native method that created them. See 5.1.1 Local References in JNI specification.

LObjects are just safe containers for local objects on their way from jni functions to wrapper classes like java::Object or java::String.

LObject supports the following usages:

  • if (lobject)
  • if (!lobject)
  • if (lobject1==lobject2)
  • if (lobject1!=lobject2)
Examples:

EmailValidator.h, LiveThread.cpp, LiveThread.h, NativeSound.cpp, and NativeSound.h.


Member Function Documentation

static LObject jni::LObject::WrapLocal ( jobject  object) [static]

Creates and returns LObject, but DOES NOT add local reference.

Use this method when you already have local reference added to the object (e.g. object is a result of calling JNIEnv::NewObject).