slot 0.0.1
A real time UI render framework
载入中...
搜索中...
未找到
Public 成员函数 | Private 属性 | 所有成员列表
facebook::yoga::vanillajni::ScopedGlobalRef< T > 模板类 参考

#include <ScopedGlobalRef.h>

类 facebook::yoga::vanillajni::ScopedGlobalRef< T > 继承关系图:
Inheritance graph
[图例]

Public 成员函数

 ScopedGlobalRef (T globalRef)
 
 ScopedGlobalRef ()
 
 ScopedGlobalRef (ScopedGlobalRef &&s) noexcept
 
ScopedGlobalRefoperator= (ScopedGlobalRef &&s) noexcept
 
 ~ScopedGlobalRef ()
 
void reset (T ptr=NULL)
 
release ()
 
get () const
 
 operator bool () const
 
 ScopedGlobalRef (const ScopedGlobalRef &ref)=delete
 
ScopedGlobalRefoperator= (const ScopedGlobalRef &other)=delete
 

Private 属性

mGlobalRef
 

详细描述

template<typename T>
class facebook::yoga::vanillajni::ScopedGlobalRef< T >

ScopedGlobalRef is a sort of smart reference that allows us to control the lifespan of a JNI global reference.

This class is designed so that when a ScopedGlobalRef goes out of scoped, its destructor will delete -JNIEnv->DeleteGlobalRef()- the underlying JNI reference.

This class should be used to wrap all the global references we create during normal JNI operations if we want reference to eventually go away (in JNI it is a common operation to cache some global references throughout the lifespan of a process, in which case using this class does not really make sense). The idea behind this is that in JNI we should be very explicit about the lifespan of global references. Global references can quickly get out of control if not freed properly, and the developer should always be very aware of the lifespan of each global reference that is created in JNI so that leaks are prevented.

This class is very explicit in its behavior, and it does not allow to perform unexpected conversions or unexpected ownership transfer. In practice, this class acts as a unique pointer where the underlying JNI reference can have one and just one owner. Transferring ownership is allowed but it is an explicit operation (implemented via move semantics and also via explicitly API calls).

Note that this class doesn't receive an explicit JNIEnv at construction time. At destruction time it uses vanillajni::getCurrentEnv() to retrieve the JNIEnv.

It is OK to cache a ScopedGlobalRef between different JNI native method calls.

构造及析构函数说明

◆ ScopedGlobalRef() [1/4]

template<typename T >
facebook::yoga::vanillajni::ScopedGlobalRef< T >::ScopedGlobalRef ( T globalRef)
inlineexplicit

Constructs a ScopedGlobalRef with a JNI global reference.

参数
globalRefthe global reference to wrap. Can be NULL.

◆ ScopedGlobalRef() [2/4]

template<typename T >
facebook::yoga::vanillajni::ScopedGlobalRef< T >::ScopedGlobalRef ( )
inlineexplicit

Equivalent to ScopedGlobalRef(NULL)

◆ ScopedGlobalRef() [3/4]

template<typename T >
facebook::yoga::vanillajni::ScopedGlobalRef< T >::ScopedGlobalRef ( ScopedGlobalRef< T > && s)
inlinenoexcept

Move construction is allowed.

◆ ~ScopedGlobalRef()

template<typename T >
facebook::yoga::vanillajni::ScopedGlobalRef< T >::~ScopedGlobalRef ( )
inline
函数调用图:

◆ ScopedGlobalRef() [4/4]

template<typename T >
facebook::yoga::vanillajni::ScopedGlobalRef< T >::ScopedGlobalRef ( const ScopedGlobalRef< T > & ref)
delete

成员函数说明

◆ get()

template<typename T >
T facebook::yoga::vanillajni::ScopedGlobalRef< T >::get ( ) const
inline

Returns the underlying JNI global reference.

这是这个函数的调用关系图:

◆ operator bool()

template<typename T >
facebook::yoga::vanillajni::ScopedGlobalRef< T >::operator bool ( ) const
inline

Returns true if the underlying JNI reference is not NULL.

◆ operator=() [1/2]

template<typename T >
ScopedGlobalRef & facebook::yoga::vanillajni::ScopedGlobalRef< T >::operator= ( const ScopedGlobalRef< T > & other)
delete

◆ operator=() [2/2]

template<typename T >
ScopedGlobalRef & facebook::yoga::vanillajni::ScopedGlobalRef< T >::operator= ( ScopedGlobalRef< T > && s)
inlinenoexcept

Move assignment is allowed.

函数调用图:

◆ release()

template<typename T >
T facebook::yoga::vanillajni::ScopedGlobalRef< T >::release ( )
inline

Makes this ScopedGlobalRef not own the underlying JNI global reference. After calling this method, the ScopedGlobalRef will not delete the JNI global reference when the ScopedGlobalRef goes out of scope.

◆ reset()

template<typename T >
void facebook::yoga::vanillajni::ScopedGlobalRef< T >::reset ( T ptr = NULL)
inline

Deletes the currently held reference and reassigns a new one to the ScopedGlobalRef.

函数调用图:
这是这个函数的调用关系图:

类成员变量说明

◆ mGlobalRef

template<typename T >
T facebook::yoga::vanillajni::ScopedGlobalRef< T >::mGlobalRef
private

该类的文档由以下文件生成: