29 template<
class 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<
class po
inter_t>
67 explicit shared_ptr_object(pointer_t* ptr) noexcept : ptr_ {
ptr} {}
70 template<
class value_t>
71 shared_ptr_object(shared_ptr_object<value_t>&& value) noexcept : ptr_ {std::move(value.ptr_)} {}
74 template<
class 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<
class value_t>
85 shared_ptr_object(
const std::shared_ptr<value_t>& value) noexcept : ptr_ {value} {}
88 template<
class value_t>
89 explicit shared_ptr_object(
const std::weak_ptr<value_t>& value) noexcept : ptr_ {value} {}
92 template<
class value_t,
class deleter_t>
93 shared_ptr_object(xtd::unique_ptr_object<value_t, deleter_t>&& value) : ptr_ {std::move(value.pointer())} {}
96 template<
class value_t,
class deleter_t>
97 shared_ptr_object(std::unique_ptr<value_t, deleter_t>&& value) : ptr_ {std::move(value)} {}
105 bool is_unique() const noexcept {
return use_count() ==
xtd::size {1};}
110 template<
class value_t>
111 bool owner_before(
const shared_ptr_object<value_t>& other)
const noexcept {
return ptr_.owner_before(
other.ptr_);}
115 template<
class value_t>
116 bool owner_before(
const std::shared_ptr<value_t>& other)
const noexcept {
return ptr_.owner_before(other);}
120 template<
class value_t>
121 bool owner_before(
const std::weak_ptr<value_t>& other)
const noexcept {
return ptr_.owner_before(other);}
125 const base_type& pointer() const noexcept {
return ptr_;}
129 base_type& pointer() noexcept {
return ptr_;}
133 xtd::size use_count() const noexcept {
return static_cast<xtd::size>(ptr_.use_count());}
149 int32 compare_to(
const shared_ptr_object& obj)
const noexcept override {
return to_pointer() < obj.to_pointer() ? -1 : to_pointer() > obj.to_pointer() ? 1 : 0;}
154 bool equals(
const xtd::object& value)
const noexcept override {
return dynamic_cast<const shared_ptr_object*
>(&value) &&
equals(
static_cast<const shared_ptr_object&
>(value));}
158 bool equals(
const shared_ptr_object& value)
const noexcept override {
return ptr_ == value.ptr_;}
162 element_type* get() const noexcept {
return ptr_.get();}
170 void reset() noexcept {ptr_.reset();}
174 template<
class po
inter_t>
175 void reset(pointer_t* ptr)
noexcept {ptr_.reset(ptr);}
182 void swap(shared_ptr_object& ptr)
noexcept {ptr_.swap(
ptr.ptr_);}
186 type_t& to_object() const noexcept {
return *to_pointer();}
191 template<
typename target_t>
192 target_t to_object()
const;
196 element_type* to_pointer() const noexcept {
return get();}
201 template<
typename target_t>
202 target_t* to_pointer()
const;
214 shared_ptr_object& operator =(shared_ptr_object&& value) noexcept {
215 ptr_ = std::move(value.ptr_);
221 shared_ptr_object& operator =(
const shared_ptr_object& value)
noexcept {
228 template<
class value_t>
229 shared_ptr_object& operator =(shared_ptr_object<value_t>&& value)
noexcept {
230 ptr_ = std::move(value.ptr_);
236 template<
class value_t>
237 shared_ptr_object& operator =(
const shared_ptr_object<value_t>& value)
noexcept {
244 template<
class value_t>
245 shared_ptr_object& operator =(std::shared_ptr<value_t>&& value)
noexcept {
246 ptr_ = std::move(value);
252 template<
class value_t>
253 shared_ptr_object& operator =(
const std::shared_ptr<value_t>& value)
noexcept {
260 type_t& operator *() const noexcept {
return ptr_.operator *();}
264 type_t* operator ->() const noexcept {
return ptr_.operator ->();}
269 element_type& operator[](std::ptrdiff_t index)
const {
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<
class other_t>
286 friend class shared_ptr_object;
290 template<
class type_t>
291 inline const shared_ptr_object<type_t> shared_ptr_object<type_t>::empty;
297 template<
class type_t>
298 shared_ptr_object(type_t*) -> shared_ptr_object<type_t>;
299 template<
class type_t>
300 shared_ptr_object(std::weak_ptr<type_t>()) -> shared_ptr_object<type_t>;
301 template<
class type_t,
class deleter_t>
302 shared_ptr_object(xtd::unique_ptr_object<type_t, deleter_t>()) -> shared_ptr_object<type_t>;
303 template<
class type_t,
class deleter_t>
304 shared_ptr_object(std::unique_ptr<type_t, deleter_t>()) -> shared_ptr_object<type_t>;
static xtd::size combine(args_t... values) noexcept
Combines values into a hash code.
Definition hash_code.hpp:70
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
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
int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.hpp:27
@ other
The operating system is other.
Definition platform_id.hpp:58
Contains xtd::hash_code class.
Contains xtd::icomparable interface.
Contains xtd::iequatable interface.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
string to_string() const noexcept override
Returns the string representation of this xtd::read_only_span <type_t> object.
Definition read_only_span.hpp:375
bool equals(const object &obj) const noexcept override
Determines whether the specified object is equal to the current object.
Definition read_only_span.hpp:272
constexpr bool empty() const noexcept
Returns a value that indicates whether the current xtd::read_only_span <type_t> is empty.
Definition read_only_span.hpp:205
xtd::size get_hash_code() const noexcept override
Serves as a hash function for a particular type.
Definition read_only_span.hpp:296
Contains xtd::null_ptr alias.
Contains xtd::object class.
Contains xtd::unique_ptr_object class.