xtd 0.2.0
xtd::shared_ptr_object< type_t > Class Template Reference
Inheritance diagram for xtd::shared_ptr_object< type_t >:
xtd::object xtd::icomparable< shared_ptr_object< type_t > > xtd::iequatable< shared_ptr_object< type_t > > xtd::interface xtd::extensions::comparison_operators< type_t, comparable_t > xtd::interface xtd::extensions::equality_operators< type_t, equatable_t >

Definition

template<class type_t>
class xtd::shared_ptr_object< type_t >

The xtd::shared_ptr_object is a shared pointer as std::shared_ptr.

Library
xtd.core
Examples
This example shows to use xtd::shared_ptr_object with xtd::version class
shared_ptr_object<xtd::version> version = new_shared_ptr_object<xtd::version>(1, 2, 3);
delete_shared_ptr_object(version); // Not mandatory.
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
The xtd::shared_ptr_object is a shared pointer as std::shared_ptr.
Definition shared_ptr_object.hpp:30
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition version.hpp:114
xtd::string to_string() const noexcept override
Converts the value of the current xtd::version object to its equivalent xtd::string representation.
void delete_shared_ptr_object(shared_ptr_object< type_t > &ptr)
xtd::delete_shared_ptr_object operator delete a xtd::shared_ptr_object or xtd::ptr object.
Definition delete_shared_ptr_object.hpp:25
Examples
as.cpp, assert_is_not_null.cpp, assert_is_null.cpp, assume_is_not_null.cpp, assume_is_null.cpp, console_firework.cpp, format_pointer.cpp, graph_control.cpp, object_memberwise_clone.cpp, object_to_string.cpp, socket_tcp_ip_v4_without_thread.cpp, timers_timer_synchronizing_object.cpp, valid_is_not_null.cpp, and valid_is_null.cpp.

Public Aliases

using base_type = std::shared_ptr< type_t >
 Represents the base type (std::shared_ptr<type_t>)
 
using element_type = typename base_type::element_type
 Represent the element type.
 
using weak_type = typename base_type::weak_type
 Represent the weak type.
 

Public Static Fields

static const shared_ptr_object empty
 Represents the empty xtd::shared_ptr_object. This field is constant.
 

Public Constructors

 shared_ptr_object () noexcept=default
 Initializes a new instance of the xtd::shared_ptr_object class.
 
 shared_ptr_object (xtd::null_ptr null) noexcept
 Initializes a new instance of the xtd::shared_ptr_object class with specified null pointer.
 
 shared_ptr_object (shared_ptr_object &&value) noexcept
 Initializes a new instance of the xtd::shared_ptr_object class with specified shared pointer object.
 
 shared_ptr_object (const shared_ptr_object &value) noexcept
 Initializes a new instance of the xtd::shared_ptr_object class with specified shared pointer object.
 
template<class pointer_t >
 shared_ptr_object (pointer_t *ptr) noexcept
 Initializes a new instance of the xtd::shared_ptr_object class with specified pointer.
 
template<class value_t >
 shared_ptr_object (shared_ptr_object< value_t > &&value) noexcept
 Initializes a new instance of the xtd::shared_ptr_object class with specified shared pointer object.
 
template<class value_t >
 shared_ptr_object (const shared_ptr_object< value_t > &value) noexcept
 Initializes a new instance of the xtd::shared_ptr_object class with specified shared pointer object.
 
template<class value_t >
 shared_ptr_object (base_type &&value) noexcept
 Initializes a new instance of the xtd::shared_ptr_object class with specified shared pointer object.
 
template<class value_t >
 shared_ptr_object (const std::shared_ptr< value_t > &value) noexcept
 Initializes a new instance of the xtd::shared_ptr_object class with specified shared pointer object.
 

Public Properties

bool is_unique () const noexcept
 Checks whether the managed object is managed only by the current xtd::shared_ptr_object object.
 
template<class value_t >
bool owner_before (const shared_ptr_object< value_t > &other) const noexcept
 Provides owner-based ordering of shared pointers.
 
template<class value_t >
bool owner_before (const std::shared_ptr< value_t > &other) const noexcept
 Provides owner-based ordering of shared pointers.
 
template<class value_t >
bool owner_before (const std::weak_ptr< value_t > &other) const noexcept
 Provides owner-based ordering of shared pointers.
 
base_type pointer () const noexcept
 Returns the underlying base type pointer.
 
xtd::size use_count () const noexcept
 Gets the number of xtd::shared_ptr_object objects referring to the same managed object.
 

Public Methods

int32 compare_to (const shared_ptr_object &obj) const noexcept override
 Compares the current instance with another object of the same type.
 
bool equals (const xtd::object &value) const noexcept override
 Determines whether the specified object is equal to the current object.
 
bool equals (const shared_ptr_object &value) const noexcept override
 Indicates whether the current object is equal to another object of the same type.
 
element_typeget () const noexcept
 Gets the stored pointer.
 
xtd::size get_hash_code () const noexcept override
 Serves as a hash function for a particular type.
 
void reset () noexcept
 Reset the current object. Set the current object to null.
 
template<class pointer_t >
void reset (pointer_t *ptr) noexcept
 Reset the current object. Set the current object with specified pointer.
 
void swap (shared_ptr_object &ptr) noexcept
 Swaps this current instance with specified shared pointer object.
 
type_t & to_object () const noexcept
 Gets the stored object.
 
template<typename target_t >
target_t to_object () const
 Gets the stored object with specified target_t type.
 
type_t * to_pointer () const noexcept
 Gets the stored pointer.
 
template<typename target_t >
target_t * to_pointer () const
 Gets the stored pointer with specified target_t type.
 
xtd::string to_string () const noexcept override
 Returns a xtd::string that represents the current object.
 

Public Operators

shared_ptr_objectoperator= (shared_ptr_object &&value) noexcept
 Assignment operator with specified xtd::shared_ptr_object value.
 
shared_ptr_objectoperator= (const shared_ptr_object &value) noexcept
 Assignment operator with specified xtd::shared_ptr_object value.
 
template<class value_t >
shared_ptr_objectoperator= (shared_ptr_object< value_t > &&value) noexcept
 Assignment operator with specified xtd::shared_ptr_object value.
 
template<class value_t >
shared_ptr_objectoperator= (const shared_ptr_object< value_t > &value) noexcept
 Assignment operator with specified xtd::shared_ptr_object value.
 
template<class value_t >
shared_ptr_objectoperator= (std::shared_ptr< value_t > &&value) noexcept
 Assignment operator with specified std::shared_ptr value.
 
template<class value_t >
shared_ptr_objectoperator= (const std::shared_ptr< value_t > &value) noexcept
 Assignment operator with specified std::shared_ptr value.
 
type_t & operator* () const noexcept
 Gets the stored object.
 
type_t * operator-> () const noexcept
 Gets the stored pointer.
 
element_typeoperator[] (std::ptrdiff_t index) const
 Provides indexed access to the stored array.
 
 operator bool () const noexcept
 Checks if the stored pointer is not null.
 
 operator base_type () const noexcept
 Returns the underlying base type pointer.
 

Additional Inherited Members

- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<class object_t >
xtd::uptr< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
- Public Member Functions inherited from xtd::icomparable< shared_ptr_object< type_t > >
- Public Member Functions inherited from xtd::iequatable< shared_ptr_object< type_t > >
- Static Public Member Functions inherited from xtd::object
template<class object_a_t , class object_b_t >
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
template<class object_a_t , class object_b_t >
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 

Member Typedef Documentation

◆ base_type

template<class type_t >
using xtd::shared_ptr_object< type_t >::base_type = std::shared_ptr<type_t>

Represents the base type (std::shared_ptr<type_t>)

◆ element_type

template<class type_t >
using xtd::shared_ptr_object< type_t >::element_type = typename base_type::element_type

Represent the element type.

◆ weak_type

template<class type_t >
using xtd::shared_ptr_object< type_t >::weak_type = typename base_type::weak_type

Represent the weak type.

Constructor & Destructor Documentation

◆ shared_ptr_object() [1/9]

template<class type_t >
xtd::shared_ptr_object< type_t >::shared_ptr_object ( )
defaultnoexcept

Initializes a new instance of the xtd::shared_ptr_object class.

◆ shared_ptr_object() [2/9]

template<class type_t >
xtd::shared_ptr_object< type_t >::shared_ptr_object ( xtd::null_ptr  null)
inlinenoexcept

Initializes a new instance of the xtd::shared_ptr_object class with specified null pointer.

Parameters
nullThe null pointer.

◆ shared_ptr_object() [3/9]

template<class type_t >
xtd::shared_ptr_object< type_t >::shared_ptr_object ( shared_ptr_object< type_t > &&  value)
inlinenoexcept

Initializes a new instance of the xtd::shared_ptr_object class with specified shared pointer object.

Parameters
valueThe shared pointer object.

◆ shared_ptr_object() [4/9]

template<class type_t >
xtd::shared_ptr_object< type_t >::shared_ptr_object ( const shared_ptr_object< type_t > &  value)
inlinenoexcept

Initializes a new instance of the xtd::shared_ptr_object class with specified shared pointer object.

Parameters
valueThe shared pointer object.

◆ shared_ptr_object() [5/9]

template<class type_t >
template<class pointer_t >
xtd::shared_ptr_object< type_t >::shared_ptr_object ( pointer_t *  ptr)
inlinenoexcept

Initializes a new instance of the xtd::shared_ptr_object class with specified pointer.

Parameters
valueThe pointer.

◆ shared_ptr_object() [6/9]

template<class type_t >
template<class value_t >
xtd::shared_ptr_object< type_t >::shared_ptr_object ( shared_ptr_object< value_t > &&  value)
inlineexplicitnoexcept

Initializes a new instance of the xtd::shared_ptr_object class with specified shared pointer object.

Parameters
valueThe shared pointer object.

◆ shared_ptr_object() [7/9]

template<class type_t >
template<class value_t >
xtd::shared_ptr_object< type_t >::shared_ptr_object ( const shared_ptr_object< value_t > &  value)
inlineexplicitnoexcept

Initializes a new instance of the xtd::shared_ptr_object class with specified shared pointer object.

Parameters
valueThe shared pointer object.

◆ shared_ptr_object() [8/9]

template<class type_t >
template<class value_t >
xtd::shared_ptr_object< type_t >::shared_ptr_object ( base_type &&  value)
inlineexplicitnoexcept

Initializes a new instance of the xtd::shared_ptr_object class with specified shared pointer object.

Parameters
valueThe shared pointer object.

◆ shared_ptr_object() [9/9]

template<class type_t >
template<class value_t >
xtd::shared_ptr_object< type_t >::shared_ptr_object ( const std::shared_ptr< value_t > &  value)
inlineexplicitnoexcept

Initializes a new instance of the xtd::shared_ptr_object class with specified shared pointer object.

Parameters
valueThe shared pointer object.

Member Function Documentation

◆ is_unique()

template<class type_t >
bool xtd::shared_ptr_object< type_t >::is_unique ( ) const
inlinenoexcept

Checks whether the managed object is managed only by the current xtd::shared_ptr_object object.

Returns
true if the managed object is managed only by the current xtd::shared_ptr_object object; otherwise false.

◆ owner_before() [1/3]

template<class type_t >
template<class value_t >
bool xtd::shared_ptr_object< type_t >::owner_before ( const shared_ptr_object< value_t > &  other) const
inlinenoexcept

Provides owner-based ordering of shared pointers.

Parameters
otherThe xtd::shared_ptr_object to be compared.
Returns
true if thid current instance precedes other; otherwise false.

◆ owner_before() [2/3]

template<class type_t >
template<class value_t >
bool xtd::shared_ptr_object< type_t >::owner_before ( const std::shared_ptr< value_t > &  other) const
inlinenoexcept

Provides owner-based ordering of shared pointers.

Parameters
otherThe xtd::shared_ptr_object::base_type to be compared.
Returns
true if thid current instance precedes other; otherwise false.

◆ owner_before() [3/3]

template<class type_t >
template<class value_t >
bool xtd::shared_ptr_object< type_t >::owner_before ( const std::weak_ptr< value_t > &  other) const
inlinenoexcept

Provides owner-based ordering of shared pointers.

Parameters
otherThe std::weak_ptr to be compared.
Returns
true if thid current instance precedes other; otherwise false.

◆ pointer()

template<class type_t >
base_type xtd::shared_ptr_object< type_t >::pointer ( ) const
inlinenoexcept

Returns the underlying base type pointer.

Returns
The underlying base type pointer.

◆ use_count()

template<class type_t >
xtd::size xtd::shared_ptr_object< type_t >::use_count ( ) const
inlinenoexcept

Gets the number of xtd::shared_ptr_object objects referring to the same managed object.

Returns
The number of xtd::shared_ptr_object objects referring to the same managed object.

◆ compare_to()

template<class type_t >
int32 xtd::shared_ptr_object< type_t >::compare_to ( const shared_ptr_object< type_t > &  obj) const
inlineoverridevirtualnoexcept

Compares the current instance with another object of the same type.

Parameters
objAn object to compare with this instance.
Returns
A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has these meanings:
Value Condition
Less than zero This instance is less than obj.
Zero This instance is equal to obj.
Greater than zero This instance is greater than obj.

Implements xtd::icomparable< shared_ptr_object< type_t > >.

◆ equals() [1/2]

template<class type_t >
bool xtd::shared_ptr_object< type_t >::equals ( const xtd::object value) const
inlineoverridevirtualnoexcept

Determines whether the specified object is equal to the current object.

Parameters
objThe object to compare with the current object.
Returns
true if the specified object is equal to the current object. otherwise, false.

Reimplemented from xtd::object.

◆ equals() [2/2]

template<class type_t >
bool xtd::shared_ptr_object< type_t >::equals ( const shared_ptr_object< type_t > &  value) const
inlineoverridevirtualnoexcept

Indicates whether the current object is equal to another object of the same type.

Parameters
objAn object to compare with this object.
Returns
true if the current object is equal to the other parameter; otherwise, false.

Implements xtd::iequatable< shared_ptr_object< type_t > >.

◆ get()

template<class type_t >
element_type * xtd::shared_ptr_object< type_t >::get ( ) const
inlinenoexcept

Gets the stored pointer.

Returns
The stored pointer.

◆ get_hash_code()

template<class type_t >
xtd::size xtd::shared_ptr_object< type_t >::get_hash_code ( ) const
inlineoverridevirtualnoexcept

Serves as a hash function for a particular type.

Returns
size_t A hash code for the current object.

Reimplemented from xtd::object.

◆ reset() [1/2]

template<class type_t >
void xtd::shared_ptr_object< type_t >::reset ( )
inlinenoexcept

Reset the current object. Set the current object to null.

Remarks
xtd::shared_ptr_object::usecount property is decremented. If alias count equal 0 the object T is deleted.

◆ reset() [2/2]

template<class type_t >
template<class pointer_t >
void xtd::shared_ptr_object< type_t >::reset ( pointer_t *  ptr)
inlinenoexcept

Reset the current object. Set the current object with specified pointer.

Parameters
ptrThe pointer to assign the current object. It can be null.
Remarks
xtd::shared_ptr_object::usecount property is decremented. If alias count equal 0 the object T is deleted.

◆ swap()

template<class type_t >
void xtd::shared_ptr_object< type_t >::swap ( shared_ptr_object< type_t > &  ptr)
inlinenoexcept

Swaps this current instance with specified shared pointer object.

Parameters
ptrThe shared pointer object to swap with this current instance.

◆ to_object() [1/2]

template<class type_t >
type_t & xtd::shared_ptr_object< type_t >::to_object ( ) const
inlinenoexcept

Gets the stored object.

Returns
The stored object.

◆ to_object() [2/2]

template<class type_t >
template<typename target_t >
target_t xtd::shared_ptr_object< type_t >::to_object ( ) const

Gets the stored object with specified target_t type.

Returns
The stored object.
Exceptions
xtd::cast_exceptionIf the current object can't be casted in target_t.

◆ to_pointer() [1/2]

template<class type_t >
type_t * xtd::shared_ptr_object< type_t >::to_pointer ( ) const
inlinenoexcept

Gets the stored pointer.

Returns
The stored pointer.

◆ to_pointer() [2/2]

template<class type_t >
template<typename target_t >
target_t * xtd::shared_ptr_object< type_t >::to_pointer ( ) const

Gets the stored pointer with specified target_t type.

Returns
The stored pointer.
Exceptions
xtd::cast_exceptionIf the current object can't be casted in target_t.

◆ to_string()

template<class type_t >
xtd::string xtd::shared_ptr_object< type_t >::to_string ( ) const
overridevirtualnoexcept

Returns a xtd::string that represents the current object.

Returns
A string that represents the current object.

Reimplemented from xtd::object.

Examples
object_to_string.cpp.

◆ operator=() [1/6]

template<class type_t >
shared_ptr_object & xtd::shared_ptr_object< type_t >::operator= ( shared_ptr_object< type_t > &&  value)
inlinenoexcept

Assignment operator with specified xtd::shared_ptr_object value.

Parameters
valueThe value to assign.

◆ operator=() [2/6]

template<class type_t >
shared_ptr_object & xtd::shared_ptr_object< type_t >::operator= ( const shared_ptr_object< type_t > &  value)
inlinenoexcept

Assignment operator with specified xtd::shared_ptr_object value.

Parameters
valueThe value to assign.

◆ operator=() [3/6]

template<class type_t >
template<class value_t >
shared_ptr_object & xtd::shared_ptr_object< type_t >::operator= ( shared_ptr_object< value_t > &&  value)
inlinenoexcept

Assignment operator with specified xtd::shared_ptr_object value.

Parameters
valueThe value to assign.

◆ operator=() [4/6]

template<class type_t >
template<class value_t >
shared_ptr_object & xtd::shared_ptr_object< type_t >::operator= ( const shared_ptr_object< value_t > &  value)
inlinenoexcept

Assignment operator with specified xtd::shared_ptr_object value.

Parameters
valueThe value to assign.

◆ operator=() [5/6]

template<class type_t >
template<class value_t >
shared_ptr_object & xtd::shared_ptr_object< type_t >::operator= ( std::shared_ptr< value_t > &&  value)
inlinenoexcept

Assignment operator with specified std::shared_ptr value.

Parameters
valueThe value to assign.

◆ operator=() [6/6]

template<class type_t >
template<class value_t >
shared_ptr_object & xtd::shared_ptr_object< type_t >::operator= ( const std::shared_ptr< value_t > &  value)
inlinenoexcept

Assignment operator with specified std::shared_ptr value.

Parameters
valueThe value to assign.

◆ operator*()

template<class type_t >
type_t & xtd::shared_ptr_object< type_t >::operator* ( ) const
inlinenoexcept

Gets the stored object.

Returns
The stored object.

◆ operator->()

template<class type_t >
type_t * xtd::shared_ptr_object< type_t >::operator-> ( ) const
inlinenoexcept

Gets the stored pointer.

Returns
The stored pointer.

◆ operator[]()

template<class type_t >
element_type & xtd::shared_ptr_object< type_t >::operator[] ( std::ptrdiff_t  index) const
inline

Provides indexed access to the stored array.

Parameters
indexThe array index.
Returns
A reference to the index-th element of the array, i.e., get()[index].

◆ operator bool()

template<class type_t >
xtd::shared_ptr_object< type_t >::operator bool ( ) const
inlineexplicitnoexcept

Checks if the stored pointer is not null.

Returns
trueif stored pointer is non null; otherwise false.

◆ operator base_type()

template<class type_t >
xtd::shared_ptr_object< type_t >::operator base_type ( ) const
inlinenoexcept

Returns the underlying base type pointer.

Returns
The underlying base type pointer.

Member Data Documentation

◆ empty

template<class type_t >
const shared_ptr_object xtd::shared_ptr_object< type_t >::empty
inlinestatic

Represents the empty xtd::shared_ptr_object. This field is constant.


The documentation for this class was generated from the following file: