Commit Graph

4 Commits

Author SHA1 Message Date
Jonathan Hui 9c467a23ae [clang-format] apply v14 changes (#8490) 2022-12-07 16:23:20 -08:00
Abtin Keshavarzian f6f3a932fc [owned-ptr] add method PassOwnership() (#7684) 2022-05-12 10:14:07 -07:00
Abtin Keshavarzian 4acdf1d0fb [common] add Ptr to use as base of OwnedPtr and RetainPtr (#7195)
This commit adds a new class `Ptr<Type>` which represents a wrapper
over a raw pointer. This is then used as the base class of `OwnedPtr`
and `RetainPtr` providing the common simple methods (avoiding repeating
the same code in each smart pointter). The new `Ptr` class also adds
overloads of `==` and `!=` allowing `Ptr` to be compared with a given
raw pointer or another `Ptr` instance.
2021-11-24 21:14:49 -08:00
Abtin Keshavarzian c127d99668 [common] adding OwnedPtr and RetainPtr classes (#7171)
This commit adds two smart pointer types `OwnedPtr` and `RetainPtr`.

`OwnedPtr` acts as the sole owner of the object it manages. It is
non-copyable but the ownership can be transferred from one `OwnedPtr`
to another using move semantics.

`RetainPtr` is an intrusive reference counted smart pointer allowing
multiple pointers to share management of the same object. It requires
the underlying `Type` object to provide mechanism to track the
current retain count. This may be realized by the `Type` itself
providing this or by having it be a sub-class of the newly added
`RetainCountable` class.

This commit also add a unit test `test_smart_ptr` validating the
behavior of newly added classes.
2021-11-19 10:33:19 -08:00