8 #ifndef ATLAS_OBJECTS_SMARTPTR_H
9 #define ATLAS_OBJECTS_SMARTPTR_H
11 #include <Atlas/Exception.h>
14 namespace Atlas {
namespace Objects {
20 template<
class U>
friend
25 SmartPtr() noexcept : ptr(T::allocator.alloc()) {
33 SmartPtr(T *a_ptr) noexcept : ptr(a_ptr)
37 template<
class oldType>
41 template<
class oldType>
49 if (a.get() != this->get()) {
58 if (a.get() != this->get()) {
69 template<
class newType>
73 template<
class newType>
77 constexpr
bool isValid()
const noexcept {
78 return ptr !=
nullptr;
80 constexpr
bool operator!()
const noexcept {
81 return this->ptr ==
nullptr;
84 explicit constexpr
operator bool ()
const noexcept
86 return !this->operator!();
89 constexpr T& operator*()
const noexcept {
93 constexpr T* operator->()
const noexcept {
97 constexpr T* get()
const noexcept {
108 void decRef()
const noexcept {
109 if (ptr !=
nullptr) {
113 void incRef()
const noexcept {
114 if (ptr !=
nullptr) {
121 template<
typename returnPtrType,
class fromType>
124 return returnPtrType(
dynamic_cast<typename returnPtrType::DataT*
>(o.get()));
127 template<
typename returnPtrType,
class fromType>
128 returnPtrType smart_static_cast(
const SmartPtr<fromType> & o)
130 return returnPtrType((
typename returnPtrType::DataT *)o.get());