Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
Public Member Functions | List of all members
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. More...
 
 shared_ptr_ref (const shared_ptr_ref &o) noexcept
 Copy constructor. More...
 
 shared_ptr_ref (const std::shared_ptr< T > &ref) noexcept
 Constructs a new instance, copying the given std::shared_ptr<T>. More...
 
 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. More...
 
 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. More...
 
 shared_ptr_ref (shared_ptr_ref &&o) noexcept
 Move constructor. More...
 
 shared_ptr_ref (std::shared_ptr< T > &&ref) noexcept
 Constructs a new instance, moving the given std::shared_ptr<T>. More...
 
 shared_ptr_ref (T *ptr) noexcept
 Constructs a new instance, taking ownership of the given T pointer. More...
 
 ~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. More...
 
void null_check1 () const
 Throws an exception if this instances shared_ptr<T> storage is nullptr. More...
 
void null_check2 () const
 Throws an exception if either this instances shared_ptr<T> storage or the managed object reference is nullptr. More...
 
T & operator* ()
 Provides access to reference of stored T. More...
 
T * operator-> ()
 Provides access to pointer of stored T. More...
 
shared_ptr_refoperator= (const shared_ptr_ref &o)
 Assignment operator. More...
 
shared_ptr_refoperator= (const std::shared_ptr< T > &o)
 Assignment operator. More...
 
shared_ptr_refoperator= (shared_ptr_ref &&o) noexcept
 Move assignment operator. More...
 
std::shared_ptr< T > * pointer () noexcept
 Provides access to the shared_ptr<T> pointer, l-value of storage. More...
 
std::shared_ptr< T > * release () noexcept
 Release ownership and returns the shared_ptr<T> storage. More...
 
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(). More...
 
jlong release_to_jlong () noexcept
 Release ownership and return the jlong representation of the shared_ptr<T> storage. More...
 
const std::shared_ptr< T > & shared_ptr () const
 Provides access to const reference of shared_ptr<T>, r-value. More...
 
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 393 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 424 of file helper_jni.hpp.

◆ 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 429 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 434 of file helper_jni.hpp.

◆ ~shared_ptr_ref()

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

Definition at line 462 of file helper_jni.hpp.

◆ shared_ptr_ref() [4/8]

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

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

Definition at line 469 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)
inlinenoexcept

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

Definition at line 474 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 479 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 529 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 554 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 441 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 453 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 484 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 498 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 508 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 563 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 574 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 593 of file helper_jni.hpp.

Here is the caller graph for this function:

◆ 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 614 of file helper_jni.hpp.

Here is the caller graph for this function:

◆ 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 621 of file helper_jni.hpp.

Here is the caller graph for this function:

◆ 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 630 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 641 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 652 of file helper_jni.hpp.

◆ toString()

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

Definition at line 657 of file helper_jni.hpp.

Here is the caller graph for this function:

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