3 #include <opals/config.hpp>
4 #include <opals/ObjectBase.hpp>
5 #include <opals/fwd.hpp>
13 OPALS_API
void shared_ptr_create(SharedPtrImpl *&,
void *obj,
void(*deleter)(
void *));
14 OPALS_API
void shared_ptr_create(SharedPtrImpl *&, ObjectBase *obj);
15 OPALS_API
void shared_ptr_inc(SharedPtrImpl *&);
16 OPALS_API
void shared_ptr_dec(SharedPtrImpl *&);
17 OPALS_API
unsigned int shared_ptr_get_count(SharedPtrImpl *
const &);
18 OPALS_API
void* shared_ptr_get(SharedPtrImpl *
const &);
19 OPALS_API
void* shared_ptr_release(SharedPtrImpl *&);
35 SharedPtrImpl *pimpl_;
42 SharedPtr(T *obj,
void(*deleter)(
void *)) noexcept : pimpl_(0) { shared_ptr_create(pimpl_, obj, deleter); }
43 SharedPtr(
const SharedPtr &ref) noexcept : pimpl_(ref.pimpl_) { shared_ptr_inc(pimpl_); }
45 ~SharedPtr() noexcept { shared_ptr_dec(pimpl_); }
47 SharedPtr &operator=(
const SharedPtr &h) {
64 void reset(T *obj,
void(*deleter)(
void *)) noexcept {
69 std::swap(pimpl_, h.pimpl_);
72 T*
get() const noexcept {
return (T *)shared_ptr_get(pimpl_); }
74 const T& operator*()
const {
return *get(); }
75 T& operator*() {
return *get(); }
77 const T* operator->()
const {
return get(); }
78 T* operator->() {
return get(); }
81 unsigned int use_count() const noexcept {
return shared_ptr_get_count(pimpl_); }
83 bool unique() const noexcept {
return (shared_ptr_get_count(pimpl_) == 1); }
85 operator bool() const noexcept {
return (pimpl_ != 0); }
92 return (T*)shared_ptr_release(pimpl_);
unsigned int use_count() const noexcept
get number of SharedPtr instances that reference the same object
Definition: SharedPtr.hpp:81
T * release()
release the controlled object This is only possible if the controlled object is only referenced by th...
Definition: SharedPtr.hpp:90
void reset(ObjectBase *obj) noexcept
put a new ObjectBase object under the shared pointer control
Definition: SharedPtr.hpp:59
bool unique() const noexcept
is the controlled object only referenced by this SharedPtr instance
Definition: SharedPtr.hpp:83
smart pointer class for opals objects
Definition: SharedPtr.hpp:33
Contains the public interface of OPALS.
Definition: AbsValueOrQuantile.hpp:8
T * get() const noexcept
get pointer to controlled object
Definition: SharedPtr.hpp:72
SharedPtr(ObjectBase *obj) noexcept
Put an object that is derived from ObjectBase under the control of the smart pointer class.
Definition: SharedPtr.hpp:40
void reset(T *obj, void(*deleter)(void *)) noexcept
put a new object under the shared pointer control (with the corresponding deleter function pointer)
Definition: SharedPtr.hpp:64
void reset() noexcept
reset shared pointer and delete controlled object if necessary
Definition: SharedPtr.hpp:54
SharedPtr(T *obj, void(*deleter)(void *)) noexcept
Put an object under the control of the smart pointer class with the corresponding deleter function po...
Definition: SharedPtr.hpp:42
base class for objects which are controlled using the SharedPtr class. the virutal Delete function is...
Definition: c++_api/inc/opals/ObjectBase.hpp:9