jaulib v1.3.6
Jau Support Library (C++, Java, ..)
Loading...
Searching...
No Matches
jau::jni::shared_ptr_ref< T > Class Template Reference

A std::shared_ptr<T> storage instance to be copied from and released into a java object's long nativeInstance field. More...

#include <helper_jni.hpp>

Collaboration diagram for jau::jni::shared_ptr_ref< T >:

Public Member Functions

 shared_ptr_ref () noexcept
 Default constructor, nullptr.
 
 shared_ptr_ref (const shared_ptr_ref &o) noexcept
 Copy constructor.
 
 shared_ptr_ref (const std::shared_ptr< T > &ref)
 Constructs a new instance, copying the given std::shared_ptr<T>.
 
 shared_ptr_ref (jlong nativeInstance, const bool throw_on_nullptr=true)
 Constructs a new instance, copying the instance from the given java long nativeInstance value, representing a java object's shared_ptr<T> storage.
 
 shared_ptr_ref (JNIEnv *env, jobject obj, const bool throw_on_nullptr=true)
 Constructs a new instance, copying the instance from the java object's long nativeInstance field.
 
 shared_ptr_ref (shared_ptr_ref &&o) noexcept
 Move constructor.
 
 shared_ptr_ref (std::shared_ptr< T > &&ref) noexcept
 Constructs a new instance, moving the given std::shared_ptr<T>.
 
 shared_ptr_ref (T *ptr)
 Constructs a new instance, taking ownership of the given T pointer.
 
 ~shared_ptr_ref ()
 
bool is_null () const noexcept
 Returns true if either this instances shared_ptr<T> storage or the managed object reference is nullptr.
 
void null_check1 () const
 Throws an exception if this instances shared_ptr<T> storage is nullptr.
 
void null_check2 () const
 Throws an exception if either this instances shared_ptr<T> storage or the managed object reference is nullptr.
 
T & operator* ()
 Provides access to reference of stored T.
 
T * operator-> ()
 Provides access to pointer of stored T.
 
shared_ptr_refoperator= (const shared_ptr_ref &o)
 Assignment operator.
 
shared_ptr_refoperator= (const std::shared_ptr< T > &o)
 Assignment operator.
 
shared_ptr_refoperator= (shared_ptr_ref &&o) noexcept
 Move assignment operator.
 
std::shared_ptr< T > * pointer () noexcept
 Provides access to the shared_ptr<T> pointer, l-value of storage.
 
std::shared_ptr< T > * release () noexcept
 Release ownership and returns the shared_ptr<T> storage.
 
void release_into_object (JNIEnv *env, jobject obj)
 Deletes the std::shared_ptr<T> storage of the target java object if exists first and writes this instance's std::shared_ptr<T> storage pointer into its long nativeInstance field, then releases ownership, see release_to_jlong().
 
jlong release_to_jlong () noexcept
 Release ownership and return the jlong representation of the shared_ptr<T> storage.
 
const std::shared_ptr< T > & shared_ptr () const
 Provides access to const reference of shared_ptr<T>, r-value.
 
std::string toString () const noexcept
 

Detailed Description

template<typename T>
class jau::jni::shared_ptr_ref< T >

A std::shared_ptr<T> storage instance to be copied from and released into a java object's long nativeInstance field.

An instance holds a shared_ptr<T> storage pointer for a managed object T.

Using a shared_ptr<T> copy increments its reference counter and prohibits its destruction while in use.

We prefer using std::shared_ptr<T> instead of a naked pointer, this way we automatically preserve the native instance lifecycle while within a JNI method.

Template Parameters
Tthe managed object type

Definition at line 392 of file helper_jni.hpp.

Constructor & Destructor Documentation

◆ shared_ptr_ref() [1/8]

template<typename T>
jau::jni::shared_ptr_ref< T >::shared_ptr_ref ( )
inlinenoexcept

Default constructor, nullptr.

Definition at line 423 of file helper_jni.hpp.

Here is the caller graph for this function:

◆ shared_ptr_ref() [2/8]

template<typename T>
jau::jni::shared_ptr_ref< T >::shared_ptr_ref ( const shared_ptr_ref< T > & o)
inlinenoexcept

Copy constructor.

Definition at line 428 of file helper_jni.hpp.

◆ shared_ptr_ref() [3/8]

template<typename T>
jau::jni::shared_ptr_ref< T >::shared_ptr_ref ( shared_ptr_ref< T > && o)
inlinenoexcept

Move constructor.

Definition at line 433 of file helper_jni.hpp.

◆ ~shared_ptr_ref()

template<typename T>
jau::jni::shared_ptr_ref< T >::~shared_ptr_ref ( )
inline

Definition at line 461 of file helper_jni.hpp.

◆ shared_ptr_ref() [4/8]

template<typename T>
jau::jni::shared_ptr_ref< T >::shared_ptr_ref ( T * ptr)
inline

Constructs a new instance, taking ownership of the given T pointer.

Definition at line 468 of file helper_jni.hpp.

◆ shared_ptr_ref() [5/8]

template<typename T>
jau::jni::shared_ptr_ref< T >::shared_ptr_ref ( const std::shared_ptr< T > & ref)
inline

Constructs a new instance, copying the given std::shared_ptr<T>.

Definition at line 473 of file helper_jni.hpp.

◆ shared_ptr_ref() [6/8]

template<typename T>
jau::jni::shared_ptr_ref< T >::shared_ptr_ref ( std::shared_ptr< T > && ref)
inlinenoexcept

Constructs a new instance, moving the given std::shared_ptr<T>.

Definition at line 478 of file helper_jni.hpp.

◆ shared_ptr_ref() [7/8]

template<typename T>
jau::jni::shared_ptr_ref< T >::shared_ptr_ref ( jlong nativeInstance,
const bool throw_on_nullptr = true )
inline

Constructs a new instance, copying the instance from the given java long nativeInstance value, representing a java object's shared_ptr<T> storage.

Using a shared_ptr<T> copy increments its reference counter and prohibits its destruction while in use.

If throw_on_nullptr is true, throws an exception if either this instances shared_ptr<T> storage or the managed object reference is nullptr.

Parameters
nativeInstancethe jlong representation of another shared_ptr<T> storage
throw_on_nullptrif true, throws an exception if either this instances shared_ptr<T> storage or the managed object reference is nullptr.

Definition at line 528 of file helper_jni.hpp.

◆ shared_ptr_ref() [8/8]

template<typename T>
jau::jni::shared_ptr_ref< T >::shared_ptr_ref ( JNIEnv * env,
jobject obj,
const bool throw_on_nullptr = true )
inline

Constructs a new instance, copying the instance from the java object's long nativeInstance field.

representing its shared_ptr<T> storage

Using a shared_ptr<T> copy increments its reference counter and prohibits its destruction while in use.

If throw_on_nullptr is true, throws an exception if either this instances shared_ptr<T> storage or the managed object reference is nullptr.

Parameters
envdenoting the JVM
objdenoting the java object holding the long nativeInstance field, representing its shared_ptr<T> storage. Maybe nullptr, see throw_on_nullptr.
throw_on_nullptrif true, throws an exception if either this instances shared_ptr<T> storage or the managed object reference is nullptr.

Definition at line 553 of file helper_jni.hpp.

Member Function Documentation

◆ operator=() [1/3]

template<typename T>
shared_ptr_ref & jau::jni::shared_ptr_ref< T >::operator= ( const shared_ptr_ref< T > & o)
inline

Assignment operator.

Definition at line 440 of file helper_jni.hpp.

◆ operator=() [2/3]

template<typename T>
shared_ptr_ref & jau::jni::shared_ptr_ref< T >::operator= ( shared_ptr_ref< T > && o)
inlinenoexcept

Move assignment operator.

Definition at line 452 of file helper_jni.hpp.

◆ operator=() [3/3]

template<typename T>
shared_ptr_ref & jau::jni::shared_ptr_ref< T >::operator= ( const std::shared_ptr< T > & o)
inline

Assignment operator.

Definition at line 483 of file helper_jni.hpp.

◆ null_check1()

template<typename T>
void jau::jni::shared_ptr_ref< T >::null_check1 ( ) const
inline

Throws an exception if this instances shared_ptr<T> storage is nullptr.

The managed object reference may be nullptr.

Definition at line 497 of file helper_jni.hpp.

Here is the caller graph for this function:

◆ null_check2()

template<typename T>
void jau::jni::shared_ptr_ref< T >::null_check2 ( ) const
inline

Throws an exception if either this instances shared_ptr<T> storage or the managed object reference is nullptr.

Definition at line 507 of file helper_jni.hpp.

Here is the caller graph for this function:

◆ release()

template<typename T>
std::shared_ptr< T > * jau::jni::shared_ptr_ref< T >::release ( )
inlinenoexcept

Release ownership and returns the shared_ptr<T> storage.

This instance shall not be used anymore.

Definition at line 562 of file helper_jni.hpp.

◆ release_to_jlong()

template<typename T>
jlong jau::jni::shared_ptr_ref< T >::release_to_jlong ( )
inlinenoexcept

Release ownership and return the jlong representation of the shared_ptr<T> storage.

This instance shall not be used anymore.

Definition at line 573 of file helper_jni.hpp.

Here is the caller graph for this function:

◆ release_into_object()

template<typename T>
void jau::jni::shared_ptr_ref< T >::release_into_object ( JNIEnv * env,
jobject obj )
inline

Deletes the std::shared_ptr<T> storage of the target java object if exists first and writes this instance's std::shared_ptr<T> storage pointer into its long nativeInstance field, then releases ownership, see release_to_jlong().

This instance shall not be used anymore.

Throws an exception if either this instances shared_ptr<T> storage or the managed object reference is nullptr.

Parameters
env
objthe target java object

Definition at line 592 of file helper_jni.hpp.

◆ is_null()

template<typename T>
bool jau::jni::shared_ptr_ref< T >::is_null ( ) const
inlinenoexcept

Returns true if either this instances shared_ptr<T> storage or the managed object reference is nullptr.

Definition at line 613 of file helper_jni.hpp.

◆ pointer()

template<typename T>
std::shared_ptr< T > * jau::jni::shared_ptr_ref< T >::pointer ( )
inlinenoexcept

Provides access to the shared_ptr<T> pointer, l-value of storage.

Definition at line 620 of file helper_jni.hpp.

◆ shared_ptr()

template<typename T>
const std::shared_ptr< T > & jau::jni::shared_ptr_ref< T >::shared_ptr ( ) const
inline

Provides access to const reference of shared_ptr<T>, r-value.

Throws an exception if this instances shared_ptr<T> storage is nullptr.

Definition at line 629 of file helper_jni.hpp.

Here is the caller graph for this function:

◆ operator*()

template<typename T>
T & jau::jni::shared_ptr_ref< T >::operator* ( )
inline

Provides access to reference of stored T.

Throws an exception if either this instances shared_ptr<T> storage or the managed object reference is nullptr.

Definition at line 640 of file helper_jni.hpp.

◆ operator->()

template<typename T>
T * jau::jni::shared_ptr_ref< T >::operator-> ( )
inline

Provides access to pointer of stored T.

Throws an exception if either this instances shared_ptr<T> storage or the managed object reference is nullptr.

Definition at line 651 of file helper_jni.hpp.

◆ toString()

template<typename T>
std::string jau::jni::shared_ptr_ref< T >::toString ( ) const
inlinenoexcept

Definition at line 656 of file helper_jni.hpp.


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