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::shared_ref< JniType > Class Template Reference

#include <shared_ref.h>

Public Types

typedef JniType ThisType::* UnspecifiedBoolType
 

Public Member Functions

 shared_ref ()
 Construct a default shared_ref with a null raw JNI pointer.
 
 shared_ref (AZStd::nullptr_t)
 Explicit construction of shared_ref with a null raw JNI pointer.
 
 shared_ref (JniType javaObject)
 
template<typename Allocator >
 shared_ref (JniType javaObject, const Allocator &allocator)
 
 shared_ref (const shared_ref &rhs)
 
template<typename Y >
 shared_ref (const shared_ref< Y > &rhs, typename AZStd::enable_if< AZStd::is_convertible< Y, JniType >::value, Y >::type=AZStd::nullptr_t())
 
 shared_ref (shared_ref &&rhs)
 
template<typename Y >
 shared_ref (shared_ref< Y > &&rhs)
 
shared_refoperator= (const shared_ref &rhs)
 
template<typename Y >
shared_refoperator= (const shared_ref< Y > &rhs)
 
shared_refoperator= (shared_ref &&rhs)
 
template<typename Y >
shared_refoperator= (shared_ref< Y > &&rhs)
 
template<typename Y >
bool operator== (const shared_ref< Y > &rhs) const
 
template<typename Y >
bool operator!= (const shared_ref< Y > &rhs) const
 
bool operator! () const
 
 operator UnspecifiedBoolType () const
 
JniType get () const
 
bool unique () const
 
long use_count () const
 Get the number of reference held on the raw JNI pointer.
 
void swap (shared_ref &lhs)
 
void reset ()
 Default reset of the internal reference to nullptr.
 
void reset (JniType javaObject)
 

Detailed Description

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

A shared_ref works in the same way a AZStd::shared_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 once the last shared_ref pointing to is released.

Constructor & Destructor Documentation

◆ shared_ref() [1/6]

template<typename JniType >
AZ::Android::JNI::shared_ref< JniType >::shared_ref ( JniType  javaObject)
inlineexplicit

Only allow explicit construction from the raw pointer to the java object reference. Will use the AZ::SytemAllocator for the shared count allocations

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

◆ shared_ref() [2/6]

template<typename JniType >
template<typename Allocator >
AZ::Android::JNI::shared_ref< JniType >::shared_ref ( JniType  javaObject,
const Allocator &  allocator 
)
inline

Create a shared_ref with a custom allocator. NOTE: The custom allocator is only used for allocating the shared_count

Parameters
javaObjectRaw pointer to the java object. Currently only supports Local and Global reference types. Weak Global reference are NOT supported.
allocatorCustom allocator for usage within the shared count.

◆ shared_ref() [3/6]

template<typename JniType >
AZ::Android::JNI::shared_ref< JniType >::shared_ref ( const shared_ref< JniType > &  rhs)
inlineexplicit

Make a copy of the shared_ref, increase the reference count

Parameters
rhsThe shared_ref to copy

◆ shared_ref() [4/6]

template<typename JniType >
template<typename Y >
AZ::Android::JNI::shared_ref< JniType >::shared_ref ( const shared_ref< Y > &  rhs,
typename AZStd::enable_if< AZStd::is_convertible< Y, JniType >::value, Y >::type  = AZStd::nullptr_t() 
)
inline

Polymorphic copy of a shared_ref

Parameters
rhsThe shared_ref of a derived JNI pointer type to be copied

◆ shared_ref() [5/6]

template<typename JniType >
AZ::Android::JNI::shared_ref< JniType >::shared_ref ( shared_ref< JniType > &&  rhs)
inline

Move the shared_ref from one shared_ref to another, Ctor

Parameters
rhsThe shared_ref to be moved

◆ shared_ref() [6/6]

template<typename JniType >
template<typename Y >
AZ::Android::JNI::shared_ref< JniType >::shared_ref ( shared_ref< Y > &&  rhs)
inline

Polymorphic move the shared_ref from one shared_ref to another, Ctor

Parameters
rhsThe shared_ref to be moved

Member Function Documentation

◆ get()

template<typename JniType >
JniType AZ::Android::JNI::shared_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::shared_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::shared_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).

◆ operator!=()

template<typename JniType >
template<typename Y >
bool AZ::Android::JNI::shared_ref< JniType >::operator!= ( const shared_ref< Y > &  rhs) const
inline

Determine if two shared_refs are not the same

Parameters
rhsThe shared_ref to compare against, may be of another JNI pointer type
Returns
True if the raw pointers are the same, False otherwise

◆ operator=() [1/4]

template<typename JniType >
shared_ref & AZ::Android::JNI::shared_ref< JniType >::operator= ( const shared_ref< JniType > &  rhs)
inline

Make a copy of the shared_ref, increase the reference count

Parameters
rhsThe shared_ref to copy

◆ operator=() [2/4]

template<typename JniType >
template<typename Y >
shared_ref & AZ::Android::JNI::shared_ref< JniType >::operator= ( const shared_ref< Y > &  rhs)
inline

Make a polymorphic copy of the shared_ref, increase the reference count

Parameters
rhsThe shared_ref to copy

◆ operator=() [3/4]

template<typename JniType >
shared_ref & AZ::Android::JNI::shared_ref< JniType >::operator= ( shared_ref< JniType > &&  rhs)
inline

Move the shared_ref from one shared_ref to another

Parameters
rhsThe shared_ref to be moved

◆ operator=() [4/4]

template<typename JniType >
template<typename Y >
shared_ref & AZ::Android::JNI::shared_ref< JniType >::operator= ( shared_ref< Y > &&  rhs)
inline

Polymorphic move of a shared_ref from one shared_ref to another

Parameters
rhsThe shared_ref to be moved

◆ operator==()

template<typename JniType >
template<typename Y >
bool AZ::Android::JNI::shared_ref< JniType >::operator== ( const shared_ref< Y > &  rhs) const
inline

Determine if two shared_refs are the same

Parameters
rhsThe shared_ref to compare against, may be of another JNI pointer type
Returns
True if the raw pointers are the same, False otherwise

◆ reset()

template<typename JniType >
void AZ::Android::JNI::shared_ref< JniType >::reset ( JniType  javaObject)
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::shared_ref< JniType >::swap ( shared_ref< JniType > &  lhs)
inline

Swap the internal reference with another shared_ref of the same type

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

◆ unique()

template<typename JniType >
bool AZ::Android::JNI::shared_ref< JniType >::unique ( ) const
inline

Check to see if the shared_ref is the only one holding on to the raw JNI pointer

Returns
True if the only refernece, False othewise

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