18#ifndef __SHAREDPTR_H__
19#define __SHAREDPTR_H__
26#include "platform/mbed_atomic.h"
92 if (_ptr !=
nullptr) {
93 _counter =
new uint32_t(1);
115 if (_ptr !=
nullptr) {
128 source._ptr =
nullptr;
129 source._counter =
nullptr;
140 if (
this != &source) {
146 _counter = source.get_counter();
149 if (_ptr !=
nullptr) {
165 if (
this != &source) {
171 _counter = source._counter;
173 source._ptr =
nullptr;
174 source._counter =
nullptr;
190 if (ptr !=
nullptr) {
192 _counter =
new uint32_t(1);
226 if (_ptr !=
nullptr) {
227 return core_util_atomic_load_u32(_counter);
255 operator bool()
const
257 return _ptr !=
nullptr;
265 uint32_t *get_counter()
const
276 void decrement_counter()
278 if (_ptr !=
nullptr) {
296template <
class T,
class U>
299 return (lhs.
get() == rhs.
get());
302template <
class T,
typename U>
305 return (lhs.
get() == (T *) rhs);
308template <
class T,
typename U>
311 return ((T *) lhs == rhs.
get());
316template <
class T,
class U>
319 return (lhs.
get() != rhs.
get());
322template <
class T,
typename U>
325 return (lhs.
get() != (T *) rhs);
328template <
class T,
typename U>
331 return ((T *) lhs != rhs.
get());
336#ifndef MBED_NO_GLOBAL_USING_DIRECTIVE
SharedPtr operator=(SharedPtr &&source)
Move assignment operator.
T & operator*() const
Dereference object operator.
void reset(T *ptr)
Replaces the managed pointer with a new unmanaged pointer.
constexpr SharedPtr(std::nullptr_t)
Create empty SharedPtr not pointing to anything.
T * operator->() const
Dereference object member operator.
SharedPtr(SharedPtr &&source)
Move constructor.
constexpr SharedPtr()
Create empty SharedPtr not pointing to anything.
void reset()
Replace the managed pointer with a null pointer.
SharedPtr(const SharedPtr &source)
Copy constructor.
T * get() const
Raw pointer accessor.
uint32_t use_count() const
Reference count accessor.
SharedPtr operator=(const SharedPtr &source)
Copy assignment operator.
SharedPtr(T *ptr)
Create new SharedPtr.