ndk::impl::ScopedAResource

#include <binder_auto_utils.h>

This baseclass owns a single object, used to make various classes RAII.

Summary

Constructors and Destructors

ScopedAResource(T t)
Takes ownership of t.
ScopedAResource(const ScopedAResource &)
ScopedAResource(ScopedAResource && other)
~ScopedAResource()
This deletes the underlying object if it exists.

Public functions

get()
T
This returns the underlying object to be modified but does not affect ownership.
get() const
const T
This returns the const underlying object but does not affect ownership.
getR()
T *
This allows the value in this class to be set from beneath it.
operator=(const ScopedAResource &)=delete
operator=(ScopedAResource && other) noexcept
release()
T
Release the underlying resource.
set(T t)
void
Takes ownership of t.

Public functions

ScopedAResource

 ScopedAResource(
  T t
)

Takes ownership of t.

ScopedAResource

 ScopedAResource(
  const ScopedAResource &
)=delete

ScopedAResource

 ScopedAResource(
  ScopedAResource && other
) noexcept

get

T get()

This returns the underlying object to be modified but does not affect ownership.

get

const T get() const 

This returns the const underlying object but does not affect ownership.

getR

T * getR()

This allows the value in this class to be set from beneath it.

If you call this method and then change the value of T*, you must take ownership of the value you are replacing and add ownership to the object that is put in here.

Recommended use is like this: ScopedAResource a; // will be nullptr SomeInitFunction(a.getR()); // value is initialized with refcount

Other usecases are discouraged.

operator=

ScopedAResource & operator=(
  const ScopedAResource &
)=delete

operator=

ScopedAResource & operator=(
  ScopedAResource && other
) noexcept

release

T release()

Release the underlying resource.

set

void set(
  T t
)

Takes ownership of t.

~ScopedAResource

 ~ScopedAResource()

This deletes the underlying object if it exists.

See set.