xtd - Reference Guide 0.2.0
xtd::box< type_t > Class Template Reference

#include <box.h>

Definition

template<typename type_t>
class xtd::box< type_t >

Represents a boxed object.

class box : public xtd::icomparable<box<type_t>>, public xtd::iequatable<box<type_t>>, public xtd::object
Inheritance
xtd::objectxtd::box <type_t>
Implements
xtd::icomparable <>, xtd::iequatable <>
Namespace
xtd
Library
xtd.core
Remarks
You can use xtd::box to represent a class or structure that does not inherit from xtd::object. Typically used for integral types.
Use xtd::boxing to box an object.
Use xtd::unboxing to unbox an object.

Constructors

 box ()=default
 Initialize a new xtd::box object. More...
 
 box (const type_t &value)
 Initialize a new xtd::box object with specified value. More...
 

Properties

const type_t & value () const
 Gets the underlying value. More...
 
type_t & value ()
 Gets the underlying value. More...
 
boxvalue (const type_t &value)
 Sets de underlying value. More...
 

Opertors

 operator type_t () const
 

Methods

bool equals (const object &value) const noexcept override
 Determines whether the specified object is equal to the current object. More...
 
bool equals (const box &value) const noexcept override
 Indicates whether the current object is equal to another object of the same type. More...
 
int32_t compare_to (const object &value) const noexcept override
 Compares the current instance with another object of the same type. More...
 
int32_t compare_to (const box &value) const noexcept override
 Compares the current instance with another object of the same type. More...
 
xtd::ustring to_string () const noexcept override
 Returns a sxd::ustring that represents the current object. More...
 
xtd::ustring to_string (const xtd::ustring &format) const noexcept
 Converts the value of this instance to its equivalent string representation, using the specified format. More...
 
static type_t parse (const xtd::ustring &value)
 Converts the string to its type_t equivalent. More...
 
static bool try_parse (const xtd::ustring &value, type_t &result)
 Converts the string to its type_t equivalent. A return value indicates whether the conversion succeeded or failed. More...
 

Additional Inherited Members

- Public Member Functions inherited from xtd::icomparable< box< type_t > >
- Public Member Functions inherited from xtd::iequatable< box< type_t > >
- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object. More...
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type. More...
 
template<typename object_t >
std::unique_ptr< object_t > memberwise_clone () const
 Gets the type of the current instance. More...
 
- Static Public Member Functions inherited from xtd::object
static bool equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are considered equal. More...
 
static bool reference_equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are the same instance. More...
 

Constructor & Destructor Documentation

◆ box() [1/2]

template<typename type_t>
xtd::box< type_t >::box ( )
default

Initialize a new xtd::box object.

◆ box() [2/2]

template<typename type_t>
xtd::box< type_t >::box ( const type_t &  value)
inline

Initialize a new xtd::box object with specified value.

Parameters
valueVolue used to initialize object.

Member Function Documentation

◆ compare_to() [1/2]

template<typename type_t>
int32_t xtd::box< type_t >::compare_to ( const object 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.

Reimplemented from xtd::icomparable< box< type_t > >.

◆ compare_to() [2/2]

template<typename type_t>
int32_t xtd::box< type_t >::compare_to ( const box< 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< box< type_t > >.

◆ equals() [1/2]

template<typename type_t>
bool xtd::box< type_t >::equals ( const object obj) 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.
Examples
The following code example compares the current instance with another object.

Reimplemented from xtd::object.

◆ equals() [2/2]

template<typename type_t>
bool xtd::box< type_t >::equals ( const box< type_t > &  ) 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< box< type_t > >.

◆ parse()

template<typename type_t>
static type_t xtd::box< type_t >::parse ( const xtd::ustring value)
inlinestatic

Converts the string to its type_t equivalent.

Parameters
valueA string containing a type_t to convert.
Returns
A type_t equivalent to the number contained in value.

◆ to_string() [1/2]

template<typename type_t>
xtd::ustring xtd::box< type_t >::to_string ( ) const
inlineoverridevirtualnoexcept

Returns a sxd::ustring that represents the current object.

Returns
A string that represents the current object.
Examples
The following code example demonstrates what to_string returns.

Reimplemented from xtd::object.

◆ to_string() [2/2]

template<typename type_t>
xtd::ustring xtd::box< type_t >::to_string ( const xtd::ustring format) const
inlinenoexcept

Converts the value of this instance to its equivalent string representation, using the specified format.

Parameters
formatA value type format string.
Returns
The string representation of the value of this instance as specified by format.

◆ try_parse()

template<typename type_t>
static bool xtd::box< type_t >::try_parse ( const xtd::ustring value,
type_t &  result 
)
inlinestatic

Converts the string to its type_t equivalent. A return value indicates whether the conversion succeeded or failed.

Parameters
valueA string containing a type_t to convert.
resultA type_t equivalent to the number contained in value.
Returns
true if s was converted successfully; otherwise, false.

◆ value() [1/3]

template<typename type_t>
const type_t& xtd::box< type_t >::value ( ) const
inline

Gets the underlying value.

Returns
Return the underlying value.

◆ value() [2/3]

template<typename type_t>
type_t& xtd::box< type_t >::value ( )
inline

Gets the underlying value.

Returns
Return the underlying value.

◆ value() [3/3]

template<typename type_t>
box& xtd::box< type_t >::value ( const type_t &  value)
inline

Sets de underlying value.

Parameters
valueThe value to set to the underlying value.

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