xtd 0.2.0
box.hpp
Go to the documentation of this file.
1
4#pragma once
7#include "convert_string.hpp"
8#include "hash_code.hpp"
9#include "icomparable.hpp"
10#include "iequatable.hpp"
12#include "iequatable.hpp"
13#include "iformatable.hpp"
14#include "istringable.hpp"
15#include "is.hpp"
16#include "enum.hpp"
17#include "object.hpp"
18#include "string.hpp"
19#include "types.hpp"
20#include "typeof.hpp"
21
23namespace xtd {
56 template<class type_t>
57 struct box : xtd::object, xtd::icomparable<box<type_t>>, xtd::iequatable<box<type_t>>, xtd::iformatable {
59
62 using value_type = type_t;
63
65 using reference = type_t&;
66
68 using const_reference = const type_t&;
69
71 using pointer = type_t*;
72
74 using const_pointer = const type_t*;
76
78
81 box() = default;
87 template<class ...args_t>
88 box(args_t&& ...args) : value(args...) {}
90
92 box(box&&) = default;
93 box(const box&) = default;
94 box& operator =(box&&) = default;
95 box& operator =(const box&) = default;
96 box& operator =(const_reference value) {
97 this->value = value;
98 return *this;
99 };
101
103
109
111
115 operator value_type() const noexcept {return value;}
117
119
131 int32 compare_to(const box& value) const noexcept override {return xtd::collections::generic::helpers::comparer<value_type> {}(this->value, value.value);}
132
136 bool equals(const object& obj) const noexcept override {return is<box<value_type>>(obj) && equals(static_cast<const box<value_type>&>(obj));}
140 bool equals(const box& value) const noexcept override {return xtd::collections::generic::helpers::equator<value_type> {}(this->value, value.value);}
141
144 xtd::size get_hash_code() const noexcept override {return hash_code::combine(value);}
145
148 xtd::string to_string() const noexcept override {return std::is_integral<value_type>::value || std::is_floating_point<value_type>::value || std::is_enum<type>::value || std::is_pointer<type>::value || std::is_base_of<xtd::istringable, value_type>::value || std::is_base_of<xtd::object, value_type>::value ? xtd::string::format("{}", value) : typeof_<value_type>().full_name();}
152 xtd::string to_string(const xtd::string& format) const {return to_string(format, std::locale {});}
157 xtd::string to_string(const xtd::string& format, const std::locale& loc) const override {return xtd::string::format(xtd::string::format("{{:{}}}", format), value);}
159
161
166 static value_type parse(const xtd::string& value) {return xtd::parse<value_type>(value);}
167
172 static bool try_parse(const xtd::string& value, reference result) noexcept {return xtd::try_parse<value_type>(value.chars(), result);}
174 };
175}
Represents text as a sequence of character units.
Definition basic_string.hpp:71
static xtd::size combine(args_t... values) noexcept
Combines values into a hash code.
Definition hash_code.hpp:70
Defines a generalized comparison method that a value type or class implements to create a type-specif...
Definition icomparable.hpp:21
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:22
Provides functionality to format the value of an object into a string representation.
Definition iformatable.hpp:35
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:43
Contains xtd::convert_string class.
Contains enum_ and enum_ut_ keywords.
Contains xtd::collections::generic::helpers::equator struct.
Contains xtd::collections::generic::helpers::comparer struct.
static basic_string format(const basic_string< char > &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
xtd::string format(const xtd::string &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition format.hpp:20
int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
Contains xtd::hash_code class.
Contains xtd::icomparable interface.
Contains xtd::iequatable interface.
Contains xtd::iformatable interface.
Contains xtd::invalid_cast_exception exception.
Contains xtd::is method.
Contains xtd::istringable interface.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Contains xtd::object class.
Contains xtd::string alias.
Represents a boxed object.
Definition box.hpp:57
bool equals(const object &obj) const noexcept override
Determines whether the specified object is equal to the current object.
Definition box.hpp:136
box(args_t &&...args)
Initialize a new xtd::box object with specified value.
Definition box.hpp:88
bool equals(const box &value) const noexcept override
Indicates whether the current object is equal to another object of the same type.
Definition box.hpp:140
type_t * pointer
Represents the reference type.
Definition box.hpp:71
xtd::string to_string() const noexcept override
Returns a xtd::string that represents the current object.
Definition box.hpp:148
static bool try_parse(const xtd::string &value, reference result) noexcept
Converts the string to its value_type equivalent. A return value indicates whether the conversion suc...
Definition box.hpp:172
box()=default
Initialize a new xtd::box object.
static value_type parse(const xtd::string &value)
Converts the string to its value_type equivalent.
Definition box.hpp:166
int32 compare_to(const box &value) const noexcept override
Compares the current instance with another object of the same type.
Definition box.hpp:131
xtd::size get_hash_code() const noexcept override
Serves as a hash function for a particular type.
Definition box.hpp:144
const type_t * const_pointer
Represents the cont reference type.
Definition box.hpp:74
const type_t & const_reference
Represents the cont reference type.
Definition box.hpp:68
box(const_reference value)
Initialize a new xtd::box object with specified value.
Definition box.hpp:84
value_type value
Gets or sets the underlying value.
Definition box.hpp:107
type_t & reference
Represents the reference type.
Definition box.hpp:65
type_t value_type
Definition box.hpp:62
xtd::string to_string(const xtd::string &format, const std::locale &loc) const override
Converts the value of this instance to its equivalent string representation, using the specified form...
Definition box.hpp:157
xtd::string to_string(const xtd::string &format) const
Converts the value of this instance to its equivalent string representation, using the specified form...
Definition box.hpp:152
Implements a function object for compare data.
Definition comparer.hpp:31
Implements a function object for performing comparisons. Unless specialised, invokes operator== on ty...
Definition equator.hpp:38
Contains typeof_ keyword.
Contains xtd fundamental types.