template <typename T>

class UniquePtr

Defined at line 920 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

A unique-pointer-like smart pointer type for holding objects that

correctly and safely deletes them, whether or not the objects owned by

protobuf `Arena`s. `UniquePtr` is used to hold either a newly created

object or a message released from a parent container.

In spirit, an `Arena::UniquePtr

<T

>` is akin to

`std::variant

<std

::unique_ptr

<T

>, Arena::Ptr

<T

>>`. It might semantically

contain either of those types, it can be constructed from them, and you can

extract them out as needed.

To create an `UniquePtr`, use the helper functions in `Arena` or release a

message from a parent using one of the release functions in

message_movers.h.

If using heap, this smart pointer will own its object and destroy it as

needed.

`UniquePtr` provides a similar interface to `std::unique_ptr` except that

it also provides access to the message's owning `Arena`, explicitly removes

the `reset(T*)` function (though it leaves `reset()` and `reset(nullptr)`),

and makes all constructors except the move-constructor private. Instead of

`reset(T*)` or a constructor, you should use move assignment and the

`MakeUnique`/`UnsafeWrapUniquePtr` functions.

Example Usage:

Arena* arena_ptr = ...;

UniquePtr

<MyMessage

> parent = Arena::MakeUnique

<MyMessage

>(arena_ptr);

...

UniquePtr

<ChildMessage

> ptr =

google::protobuf::ReleaseMessageField

<

"child_field">(parent);

...

ptr.reset(); // Will delete ChildMessage ptr if arena_ptr was nullptr.

CHECK(ptr == nullptr);

...

ModifyChildMessage(ptr.get());

ConsumeChildMessage(std::move(ptr));

Public Methods

void UniquePtr<T> ()

Public Constructors

Defined at line 929 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

void UniquePtr<T> (std::nullptr_t )

NOLINTNEXTLINE(google-explicit-constructor)

Defined at line 931 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

void UniquePtr<T> (std::unique_ptr<T> heap_owned)

Allow implicit conversion from `std::unique_ptr` with

`std::default_delete`.

This is always safe since `UniquePtr` can safely hold heap-allocated

pointers.

NOLINTNEXTLINE(google-explicit-constructor)

Defined at line 938 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

void UniquePtr<T> (Ptr<T> arena_owned)

Allow implicit conversion from `Ptr

<T

>`.

This is always safe since `Ptr` is statically known to be owned by an

arena. There is no "unique" ownership on it.

NOLINTNEXTLINE(google-explicit-constructor)

Defined at line 945 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

void ~UniquePtr<T> ()

Defined at line 948 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

void UniquePtr<T> (UniquePtr<T> && rhs)

Defined at line 950 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

template <typename U, typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
void UniquePtr<T> (UniquePtr<U> && rhs)

NOLINTNEXTLINE(google-explicit-constructor)

Defined at line 954 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

void UniquePtr<T> (T * ptr)

Use Arena::UnsafeWrapUniquePtr or Arena::MakeUnique

Defined at line 957 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

UniquePtr<T> & operator= (UniquePtr<T> && rhs)

Defined at line 959 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

UniquePtr<T> & operator= (std::nullptr_t )

Defined at line 960 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

template <typename U, typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
UniquePtr<T> & operator= (UniquePtr<U> && rhs)

Defined at line 966 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

void UniquePtr<T> (const UniquePtr<T> & rhs)

Delete the copy ctor and copy assignment operator.

Defined at line 972 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

UniquePtr<T> & operator= (const UniquePtr<T> & rhs)

Defined at line 973 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

absl::optional<std::unique_ptr<T>> try_heap_release ()

If heap allocated transfer ownership of the pointer to the caller, clearing

the `UniquePtr` instance.

Otherwise, return `absl::nullopt` and have no effect.

Defined at line 978 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

absl::optional<Ptr<T>> try_as_arena_ptr ()

If it contains an arena allocated object, return a `Ptr` to the caller.

Otherwise, return `absl::nullopt`.

This function has does not modify the `UniquePtr`.

Defined at line 988 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

void swap (UniquePtr<T> & other)

Defined at line 997 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

void reset ()

reset() the pointed to object to nullptr.

Defined at line 1001 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

void reset (std::nullptr_t )

Defined at line 1002 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

void reset (T * )

Defined at line 1005 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

pointer get ()

Defined at line 1007 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

pointer operator-> ()

Defined at line 1010 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

element_type & operator* ()

Defined at line 1013 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

bool operator bool ()

Defined at line 1017 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

Arena * GetOwningArena ()

Return a pointer to the Arena pointer that owns the pointed to message.

Defined at line 1020 of file ../../third_party/protobuf/src/src/google/protobuf/arena.h

Friends

template <typename U>
class UniquePtr
template <typename T>
class Arena
template <typename H>
H UniquePtr (H h, const UniquePtr<T> & u)
template <typename Sink>
void UniquePtr (Sink & sink, const UniquePtr<T> & ptr)
template <typename T>
void UniquePtr (UniquePtr<T> & aUniquePtr<T> & b)