xtd 1.0.0
Loading...
Searching...
No Matches
unboxing.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "box.hpp"
6#include "byte.hpp"
7#include "char.hpp"
8#include "char16.hpp"
9#include "char32.hpp"
10#include "char8.hpp"
11#include "decimal.hpp"
12#include "double.hpp"
13#include "int16.hpp"
14#include "int32.hpp"
15#include "int64.hpp"
16#include "intptr.hpp"
17#include "sbyte.hpp"
18#include "single.hpp"
19#include "ssize.hpp"
20#include "uint16.hpp"
21#include "uint32.hpp"
22#include "uint64.hpp"
23#include "uintptr.hpp"
24#include "usize.hpp"
25#include "wchar.hpp"
26#define __XTD_STD_INTERNAL__
28#undef __XTD_STD_INTERNAL__
29
31namespace xtd {
33
48 template<typename type_t>
49 [[nodiscard]] inline auto unboxing(const xtd::box<type_t>& value) noexcept -> type_t {return value.value;}
51
53 template<typename type_t>
54 [[nodiscard]] inline auto unboxing(xtd::box<type_t>& value) noexcept -> type_t {return value.value;}
55
56 template<typename type_t>
57 [[nodiscard]] inline auto unboxing(const xtd::enum_object<type_t>& value) noexcept -> type_t {return value.value;}
58
59 template<typename type_t>
60 [[nodiscard]] inline auto unboxing(xtd::enum_object<type_t>& value) noexcept -> type_t {return value.value;}
61
62 [[nodiscard]] inline auto unboxing(const xtd::object& value) noexcept -> const xtd::object& {return value;}
63 [[nodiscard]] inline auto unboxing(xtd::object& value) noexcept -> xtd::object& {return value;}
64
65 [[nodiscard]] inline auto unboxing(const xtd::string& value) noexcept -> const char* {return value.chars().c_str();}
66 [[nodiscard]] inline auto unboxing(xtd::string& value) noexcept -> const char* {return value.chars().c_str();}
67
68 template<typename char_t>
69 [[nodiscard]] inline auto unboxing(const xtd::string& value) -> const char_t* {xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::invalid_cast, "Invalid character type");}
70 template<typename char_t>
71 [[nodiscard]] inline auto unboxing(xtd::string& value) -> const char_t* {xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::invalid_cast, "Invalid character type");}
72
73 template<>
74 [[nodiscard]] inline auto unboxing<char>(const xtd::string& value) -> const char* {return value.chars().c_str();}
75 template<>
76 [[nodiscard]] inline auto unboxing<char>(xtd::string& value) -> const char* {return value.chars().c_str();}
77
78 template<>
79 [[nodiscard]] inline auto unboxing<xtd::char8>(const xtd::string& value) -> const xtd::char8* {
80 thread_local static xtd::u8string result;
81 result = convert_string::to_u8string(value);
82 return result.c_str();
83 }
84 template<>
85 [[nodiscard]] inline auto unboxing<xtd::char8>(xtd::string& value) -> const xtd::char8* {
86 thread_local static xtd::u8string result;
87 result = convert_string::to_u8string(value);
88 return result.c_str();
89 }
90
91 template<>
92 [[nodiscard]] inline auto unboxing<xtd::char16>(const xtd::string& value) -> const xtd::char16* {
93 thread_local static xtd::u16string result;
94 result = convert_string::to_u16string(value);
95 return result.c_str();
96 }
97 template<>
98 [[nodiscard]] inline auto unboxing<xtd::char16>(xtd::string& value) -> const xtd::char16* {
99 thread_local static xtd::u16string result;
100 result = convert_string::to_u16string(value);
101 return result.c_str();
102 }
103
104 template<>
105 [[nodiscard]] inline auto unboxing<xtd::char32>(const xtd::string& value) -> const xtd::char32* {
106 thread_local static xtd::u32string result;
107 result = convert_string::to_u32string(value);
108 return result.c_str();
109 }
110 template<>
111 [[nodiscard]] inline auto unboxing<char32>(xtd::string& value) -> const char32* {
112 thread_local static xtd::u32string result;
113 result = convert_string::to_u32string(value);
114 return result.c_str();
115 }
116
117 template<>
118 [[nodiscard]] inline auto unboxing<xtd::wchar>(const xtd::string& value) -> const xtd::wchar* {
119 thread_local static xtd::wstring result;
120 result = convert_string::to_wstring(value);
121 return result.c_str();
122 }
123 template<>
124 [[nodiscard]] inline auto unboxing<xtd::wchar>(string& value) -> const xtd::wchar* {
125 thread_local static std::wstring result;
126 result = convert_string::to_wstring(value);
127 return result.c_str();
128 }
129
130 /*
131 template<typename type_t>
132 [[nodiscard]] inline auto unboxing(const type_t& value) noexcept -> const type_t& {
133 if (dynamic_cast<const xtd::enum_object<type_t>*>(&value) != nullptr) {
134 thread_local static type_t result = dynamic_cast<const xtd::enum_object<type_t>*>(&value)->value();
135 return result;
136 }
137 if (dynamic_cast<const xtd::box<type_t>*>(&value) != nullptr)
138 return dynamic_cast<const xtd::box<type_t>*>(&value)->value();
139 return value;
140 }
141
142 template<typename type_t>
143 [[nodiscard]] inline auto unboxing(type_t& value) noexcept -> type_t& {
144 if (dynamic_cast<xtd::enum_object<type_t>*>(&value) != nullptr) {
145 thread_local static type_t result = dynamic_cast<xtd::enum_object<type_t>*>(&value)->value();
146 return result;
147 }
148 auto result = dynamic_cast<xtd::box<type_t>*>(&value);
149 if (result != nullptr)
150 return dynamic_cast<xtd::box<type_t>*>(&value)->value();
151 return value;
152 }
153 */
154
155 [[nodiscard]] inline auto unboxing(const char& value) noexcept -> char {return value;}
156 [[nodiscard]] inline auto unboxing(const xtd::char8& value) noexcept -> xtd::char8 {return value;}
157 [[nodiscard]] inline auto unboxing(const xtd::char16& value) noexcept -> xtd::char16 {return value;}
158 [[nodiscard]] inline auto unboxing(const xtd::char32& value) noexcept -> xtd::char32 {return value;}
159 [[nodiscard]] inline auto unboxing(const xtd::wchar& value) noexcept -> xtd::wchar {return value;}
160 [[nodiscard]] inline auto unboxing(char& value) noexcept -> char {return value;}
161 [[nodiscard]] inline auto unboxing(xtd::char8& value) noexcept -> xtd::char8 {return value;}
162 [[nodiscard]] inline auto unboxing(xtd::char16& value) noexcept -> xtd::char16 {return value;}
163 [[nodiscard]] inline auto unboxing(xtd::char32& value) noexcept -> xtd::char32 {return value;}
164 [[nodiscard]] inline auto unboxing(xtd::wchar& value) noexcept -> xtd::wchar {return value;}
165 [[nodiscard]] inline auto unboxing(const xtd::byte& value) noexcept -> xtd::byte {return value;}
166 [[nodiscard]] inline auto unboxing(const xtd::int16& value) noexcept -> xtd::int16 {return value;}
167 [[nodiscard]] inline auto unboxing(const xtd::int32& value) noexcept -> xtd::int32 {return value;}
168 [[nodiscard]] inline auto unboxing(const xtd::int64& value) noexcept -> xtd::int64 {return value;}
169 [[nodiscard]] inline auto unboxing(const xtd::slong& value) noexcept -> xtd::slong {return value;}
170 [[nodiscard]] inline auto unboxing(const xtd::sbyte& value) noexcept -> xtd::sbyte {return value;}
171 [[nodiscard]] inline auto unboxing(const xtd::uint16& value) noexcept -> xtd::uint16 {return value;}
172 [[nodiscard]] inline auto unboxing(const xtd::uint32& value) noexcept -> xtd::uint32 {return value;}
173 [[nodiscard]] inline auto unboxing(const xtd::uint64& value) noexcept -> xtd::uint64 {return value;}
174 [[nodiscard]] inline auto unboxing(const xtd::ulong& value) noexcept -> xtd::ulong {return value;}
175 [[nodiscard]] inline auto unboxing(xtd::byte& value) noexcept -> xtd::byte {return value;}
176 [[nodiscard]] inline auto unboxing(xtd::int16& value) noexcept -> xtd::int16 {return value;}
177 [[nodiscard]] inline auto unboxing(xtd::int32& value) noexcept -> xtd::int32 {return value;}
178 [[nodiscard]] inline auto unboxing(xtd::int64& value) noexcept -> xtd::int64 {return value;}
179 [[nodiscard]] inline auto unboxing(xtd::slong& value) noexcept -> xtd::slong {return value;}
180 [[nodiscard]] inline auto unboxing(xtd::sbyte& value) noexcept -> xtd::sbyte {return value;}
181 [[nodiscard]] inline auto unboxing(xtd::uint16& value) noexcept -> xtd::uint16 {return value;}
182 [[nodiscard]] inline auto unboxing(xtd::uint32& value) noexcept -> xtd::uint32 {return value;}
183 [[nodiscard]] inline auto unboxing(xtd::uint64& value) noexcept -> xtd::uint64 {return value;}
184 [[nodiscard]] inline auto unboxing(xtd::ulong& value) noexcept -> xtd::ulong {return value;}
185 [[nodiscard]] inline auto unboxing(const float& value) noexcept -> float {return value;}
186 [[nodiscard]] inline auto unboxing(const double& value) noexcept -> double {return value;}
187 [[nodiscard]] inline auto unboxing(const decimal& value) noexcept -> decimal {return value;}
188 [[nodiscard]] inline auto unboxing(float& value) noexcept -> float {return value;}
189 [[nodiscard]] inline auto unboxing(double& value) noexcept -> double {return value;}
190 [[nodiscard]] inline auto unboxing(xtd::decimal& value) noexcept -> xtd::decimal {return value;}
192}
Contains xtd::box struct.
Contains xtd::byte type.
Contains xtd::char16 type.
Contains xtd::char32 type.
Contains xtd::char8 type.
Contains xtd::char_ type.
auto c_str() const noexcept -> const_pointer
Returns a pointer to a null-terminated character array with data equivalent to those stored in the st...
Definition basic_string.hpp:353
static auto to_wstring(const xtd::string &str) noexcept -> xtd::wstring
Converts xtd::string to xtd::wstring.
static auto to_u32string(const xtd::string &str) noexcept -> xtd::u32string
Converts xtd::string to xtd::u32string.
static auto to_u8string(const xtd::string &str) noexcept -> xtd::u8string
Converts xtd::string to xtd::u8string.
static auto to_u16string(const xtd::string &str) noexcept -> xtd::u16string
Converts xtd::string to xtd::u16string.
static auto throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current()) -> void
Throws an exption with specified exception case.
Contains xtd::decimal type.
Contains xtd::double_ type.
@ value
Represnets the constant operator precedence (42).
Definition operator_precedence.hpp:30
@ invalid_cast
The cast is not valid.
Definition exception_case.hpp:63
xtd::basic_string< xtd::char8 > u8string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:76
xtd::basic_string< xtd::char32 > u32string
Represents text as a sequence of UTF-32 code units.
Definition __string_definitions.hpp:65
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
xtd::basic_string< xtd::char16 > u16string
Represents text as a sequence of UTF-16 code units.
Definition __string_definitions.hpp:54
xtd::basic_string< xtd::wchar > wstring
Represents text as a sequence of UTF-16 code unit on Windows or UTF-32 code unit on non-Windows syste...
Definition __string_definitions.hpp:87
auto unboxing(const xtd::box< type_t > &value) noexcept -> type_t
Allows to unbox an object.
Definition unboxing.hpp:49
std::int64_t int64
Represents a 64-bit signed integer.
Definition int64.hpp:23
std::uint32_t uint32
Represents a 32-bit unsigned integer.
Definition uint32.hpp:23
char8_t char8
Represents a 8-bit unicode character.
Definition char8.hpp:26
__slong__ slong
Represents a 32-bit or 64-bit signed integer.
Definition slong.hpp:27
std::int8_t sbyte
Represents a 8-bit signed integer.
Definition sbyte.hpp:23
wchar_t wchar
Represents a wide character.
Definition wchar.hpp:24
__ulong__ ulong
Represents a 32-bit or 64-bit unsigned integer.
Definition ulong.hpp:27
long double decimal
Represents a decimal-precision floating-point number.
Definition decimal.hpp:23
std::uint16_t uint16
Represents a 16-bit unsigned integer.
Definition uint16.hpp:23
char16_t char16
Represents a 16-bit unicode character.
Definition char16.hpp:26
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:25
std::int16_t int16
Represents a 16-bit signed integer.
Definition int16.hpp:23
std::uint64_t uint64
Represents a 64-bit unsigned integer.
Definition uint64.hpp:23
std::uint8_t byte
Represents a 8-bit unsigned integer.
Definition byte.hpp:23
char32_t char32
Represents a 32-bit unicode character.
Definition char32.hpp:23
Contains xtd::int16 type.
Contains xtd::int32 type.
Contains xtd::int64 type.
Contains xtd::intptr type.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Contains xtd::sbyte type.
Contains xtd::single type.
Contains xtd::ssize type.
Represents a boxed object.
Definition box.hpp:55
Contains xtd::uint16 type.
Contains xtd::uint32 type.
Contains xtd::uint64 type.
Contains xtd::uintptr type.
Contains xtd::usize type.
Contains xtd::wchar type.