29 template<
typename type_t>
30 class shared_ptr_object :
public xtd::object,
public xtd::icomparable<shared_ptr_object<type_t>>,
public xtd::iequatable<shared_ptr_object<type_t >> {
36 using base_type = std::shared_ptr<type_t>;
38 using element_type =
typename base_type::element_type;
40 using weak_type =
typename base_type::weak_type;
47 static const shared_ptr_object
empty;
54 shared_ptr_object() noexcept = default;
57 shared_ptr_object(xtd::null_ptr null) noexcept : ptr_ {
null} {}
60 shared_ptr_object(shared_ptr_object&& value) noexcept : ptr_ {std::move(
value.ptr_)} {}
63 shared_ptr_object(
const shared_ptr_object& value) noexcept : ptr_ {
value.ptr_} {}
66 template<
typename po
inter_t>
67 explicit shared_ptr_object(pointer_t* ptr) noexcept : ptr_ {
ptr} {}
70 template<
typename value_t>
71 shared_ptr_object(shared_ptr_object<value_t>&& value) noexcept : ptr_ {std::move(
value.ptr_)} {}
74 template<
typename value_t>
75 shared_ptr_object(
const shared_ptr_object<value_t>& value) noexcept : ptr_ {
value.ptr_} {}
78 shared_ptr_object(
const base_type& value) noexcept : ptr_ {
value} {}
81 shared_ptr_object(base_type&& value) noexcept : ptr_ {std::move(value)} {}
84 template<
typename value_t>
85 shared_ptr_object(
const std::shared_ptr<value_t>& value) noexcept : ptr_ {
value} {}
88 template<
typename value_t>
89 explicit shared_ptr_object(
const std::weak_ptr<value_t>& value) noexcept : ptr_ {
value} {}
92 template<
typename value_t,
typename deleter_t>
93 shared_ptr_object(xtd::unique_ptr_object<value_t, deleter_t>&& value) : ptr_ {std::move(
value.
pointer())} {}
96 template<
typename value_t,
typename deleter_t>
97 shared_ptr_object(std::unique_ptr<value_t, deleter_t>&& value) : ptr_ {std::move(
value)} {}
105 [[nodiscard]]
auto is_unique() const noexcept ->
bool {
return use_count() ==
xtd::usize {1};}
110 template<
typename value_t>
111 [[nodiscard]]
auto owner_before(
const shared_ptr_object<value_t>& other)
const noexcept ->
bool {
return ptr_.owner_before(
other.ptr_);}
115 template<
typename value_t>
116 [[nodiscard]]
auto owner_before(
const std::shared_ptr<value_t>& other)
const noexcept ->
bool {
return ptr_.owner_before(other);}
120 template<
typename value_t>
121 [[nodiscard]]
auto owner_before(
const std::weak_ptr<value_t>& other)
const noexcept ->
bool {
return ptr_.owner_before(other);}
125 [[nodiscard]]
auto pointer() const noexcept -> const base_type& {
return ptr_;}
129 [[nodiscard]]
auto pointer() noexcept -> base_type& {
return ptr_;}
133 [[nodiscard]]
auto use_count() const noexcept -> xtd::usize {
return static_cast<xtd::usize>(ptr_.use_count());}
149 [[nodiscard]]
auto compare_to(
const shared_ptr_object& obj)
const noexcept ->
xtd::int32 override {
return to_pointer() < obj.to_pointer() ? -1 : to_pointer() > obj.to_pointer() ? 1 : 0;}
154 [[nodiscard]]
auto equals(
const xtd::object& value)
const noexcept ->
bool override {
return dynamic_cast<const shared_ptr_object*
>(&
value) &&
equals(
static_cast<const shared_ptr_object&
>(value));}
158 [[nodiscard]]
auto equals(
const shared_ptr_object& value)
const noexcept ->
bool override {
return ptr_ ==
value.ptr_;}
162 [[nodiscard]]
auto get() const noexcept -> element_type* {
return ptr_.get();}
170 auto reset() noexcept ->
void {ptr_.reset();}
174 template<
typename po
inter_t>
175 auto reset(pointer_t* ptr)
noexcept ->
void {ptr_.reset(ptr);}
178 auto reset(
xtd::null_ptr null)
noexcept ->
void {ptr_.reset();}
182 auto swap(shared_ptr_object& ptr)
noexcept ->
void {ptr_.swap(
ptr.ptr_);}
186 [[nodiscard]]
auto to_object() const noexcept -> type_t& {
return *to_pointer();}
191 template<
typename target_t>
192 [[nodiscard]]
auto to_object() const -> target_t;
196 [[nodiscard]] auto to_pointer() const noexcept -> element_type* {
return get();}
201 template<
typename target_t>
202 [[nodiscard]]
auto to_pointer() const -> target_t*;
206 [[nodiscard]] auto to_string() const noexcept -> xtd::
string override;
214 auto operator =(shared_ptr_object&& value) noexcept -> shared_ptr_object& {
215 ptr_ = std::move(
value.ptr_);
221 auto operator =(
const shared_ptr_object& value)
noexcept -> shared_ptr_object& {
228 template<
typename value_t>
229 auto operator =(shared_ptr_object<value_t>&& value)
noexcept -> shared_ptr_object& {
230 ptr_ = std::move(
value.ptr_);
236 template<
typename value_t>
237 auto operator =(
const shared_ptr_object<value_t>& value)
noexcept -> shared_ptr_object& {
244 template<
typename value_t>
245 auto operator =(std::shared_ptr<value_t>&& value)
noexcept -> shared_ptr_object& {
246 ptr_ = std::move(value);
252 template<
typename value_t>
253 auto operator =(
const std::shared_ptr<value_t>& value)
noexcept -> shared_ptr_object& {
260 auto operator *() const noexcept -> type_t& {
return ptr_.operator * ();}
264 auto operator ->() const noexcept -> type_t* {
return ptr_.operator ->();}
269 auto operator[](std::ptrdiff_t index)
const -> element_type& {
return ptr_.operator [](index);}
273 explicit operator bool() const noexcept {
return ptr_.operator bool();}
277 operator base_type() const noexcept {
return ptr_;}
281 operator weak_type() const noexcept {
return weak_type {ptr_};}
285 template<
typename other_t>
286 friend class shared_ptr_object;
290 template<
typename type_t>
291 inline const shared_ptr_object<type_t> shared_ptr_object<type_t>::empty;
297 template<
typename type_t>
298 shared_ptr_object(type_t*) -> shared_ptr_object<type_t>;
299 template<
typename type_t>
300 shared_ptr_object(std::weak_ptr<type_t>()) -> shared_ptr_object<type_t>;
301 template<
typename type_t,
typename deleter_t>
302 shared_ptr_object(xtd::unique_ptr_object<type_t, deleter_t>()) -> shared_ptr_object<type_t>;
303 template<
typename type_t,
typename deleter_t>
304 shared_ptr_object(std::unique_ptr<type_t, deleter_t>()) -> shared_ptr_object<type_t>;
static auto combine(args_t... values) noexcept -> xtd::usize
Combines values into a hash code.
Definition hash_code.hpp:70
@ value
Represnets the constant operator precedence (42).
Definition operator_precedence.hpp:30
null_ptr null
Represents a null pointer value.
std::nullptr_t null_ptr
Represents the null_opt alias on std::nullptr_t.
Definition null_ptr.hpp:19
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:25
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.hpp:27
std::size_t usize
Represents an unsigned size of any object in bytes.
Definition usize.hpp:22
@ other
The operating system is other.
Definition platform_id.hpp:60
Contains xtd::hash_code class.
Contains xtd::icomparable interface.
Contains xtd::iequatable interface.
virtual auto operator[](xtd::usize index) const -> const type_t &=0
Gets the element at the specified index.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
constexpr auto empty() const noexcept -> bool
Returns a value that indicates whether the current xtd::read_only_span <type_t> is empty.
Definition read_only_span.hpp:201
auto equals(const object &obj) const noexcept -> bool override
Determines whether the specified object is equal to the current object.
Definition read_only_span.hpp:239
const type_t * pointer
Represents the read_only_span pointer type.
Definition read_only_span.hpp:63
auto get_hash_code() const noexcept -> xtd::usize override
Serves as a hash function for a particular type.
Definition read_only_span.hpp:263
Contains xtd::null_ptr alias.
Contains xtd::object class.
Contains xtd::unique_ptr_object class.