Open 3D Engine AzCore API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::Android::JNI::scoped_ref< JniType > Class Template Reference

#include <scoped_ref.h>

Public Types

typedef JniType ThisType::* UnspecifiedBoolType
 

Public Member Functions

 scoped_ref (JniType javaObject=nullptr)
 
 ~scoped_ref ()
 
bool operator! () const
 
 operator UnspecifiedBoolType () const
 
JniType get () const
 
void swap (scoped_ref &lhs)
 
void reset (JniType javaObject=nullptr)
 

Detailed Description

template<typename JniType>
class AZ::Android::JNI::scoped_ref< JniType >

A scoped_ref works in the same way a AZStd::scoped_ptr except it's specificially designed for the opaque pointer JNI types (e.g. jobject, jarray, etc.). Guarantees the java object is released from the JNI environment when the scoped_ref falls out of scope.

Constructor & Destructor Documentation

◆ scoped_ref()

template<typename JniType >
AZ::Android::JNI::scoped_ref< JniType >::scoped_ref ( JniType  javaObject = nullptr)
inlineexplicit

Only explicit scoped_refs are allowed to be constructed

Parameters
javaObjectRaw pointer to the java object. Currently only supports Local and Global reference types. Weak Global reference are NOT supported.

◆ ~scoped_ref()

template<typename JniType >
AZ::Android::JNI::scoped_ref< JniType >::~scoped_ref ( )
inline

Automatically release the reference with the JNI environment when the object goes out of scope

Member Function Documentation

◆ get()

template<typename JniType >
JniType AZ::Android::JNI::scoped_ref< JniType >::get ( ) const
inline

Explicit accessor of the raw pointer to the java reference.

Returns
The raw pointer to the java object reference

◆ operator UnspecifiedBoolType()

template<typename JniType >
AZ::Android::JNI::scoped_ref< JniType >::operator UnspecifiedBoolType ( ) const
inline

Operator for implicit bool conversions

Returns
'True' if internal reference is valid, False otherwise

◆ operator!()

template<typename JniType >
bool AZ::Android::JNI::scoped_ref< JniType >::operator! ( ) const
inline

Compatibilty with the 'not' operator for validity checks. Only checkes for raw pointer validity, NOT if it's pointing to a null reference (weak global ref).

◆ reset()

template<typename JniType >
void AZ::Android::JNI::scoped_ref< JniType >::reset ( JniType  javaObject = nullptr)
inline

Reset the internal reference with a new pointer

Parameters
javaObjectRaw pointer to the java object. Must be of same type.

◆ swap()

template<typename JniType >
void AZ::Android::JNI::scoped_ref< JniType >::swap ( scoped_ref< JniType > &  lhs)
inline

Swap the internal reference with another scoped_ref of the same type

Parameters
lhsThe scoped_ref (of same type) to be swaped with

The documentation for this class was generated from the following file: