xtd 0.2.0
Loading...
Searching...
No Matches
unboxing.h
Go to the documentation of this file.
1
4#pragma once
5#include "box.h"
6#include "byte.h"
7#include "char.h"
8#include "char16.h"
9#include "char32.h"
10#include "char8.h"
11#include "decimal.h"
12#include "double.h"
13#include "int16.h"
14#include "int32.h"
15#include "int64.h"
16#include "intptr.h"
17#include "sbyte.h"
18#include "single.h"
19#include "size.h"
20#include "uint16.h"
21#include "uint32.h"
22#include "uint64.h"
23#include "uintptr.h"
24#include "wchar.h"
25
27namespace xtd {
39 template<typename type_t>
40 inline type_t unboxing(const xtd::box<type_t>& value) noexcept {return value.value();}
41
43 template<typename type_t>
44 inline type_t unboxing(xtd::box<type_t>& value) noexcept {return value.value();}
45
46 template<typename type_t>
47 inline type_t unboxing(const xtd::enum_object<type_t>& value) noexcept {return value.value();}
48
49 template<typename type_t>
50 inline type_t unboxing(xtd::enum_object<type_t>& value) noexcept {return value.value();}
51
52 inline const object& unboxing(const object& value) noexcept {return value;}
53 inline object& unboxing(object& value) noexcept {return value;}
54
55 inline const char* unboxing(const ustring& value) noexcept {return value.c_str();}
56 inline const char* unboxing(ustring& value) noexcept {return value.c_str();}
57
58 template<typename char_t>
59 inline const char_t* unboxing(const ustring& value) {throw invalid_cast_exception("Invalid character type");}
60 template<typename char_t>
61 inline const char_t* unboxing(ustring& value) {throw invalid_cast_exception("Invalid character type");}
62
63 template<>
64 inline const char* unboxing<char>(const ustring& value) {return value.c_str();}
65 template<>
66 inline const char* unboxing<char>(ustring& value) {return value.c_str();}
67
68#if defined(__cpp_lib_char8_t)
69 template<>
70 inline const char8* unboxing<char8>(const ustring& value) {
71 thread_local static std::u8string result;
72 result = convert_string::to_u8string(value);
73 return result.c_str();
74 }
75 template<>
76 inline const char8* unboxing<char8>(ustring& value) {
77 thread_local static std::u8string result;
78 result = convert_string::to_u8string(value);
79 return result.c_str();
80 }
81#endif
82
83 template<>
84 inline const char16* unboxing<char16>(const ustring& value) {
85 thread_local static std::u16string result;
86 result = convert_string::to_u16string(value);
87 return result.c_str();
88 }
89 template<>
90 inline const char16* unboxing<char16>(ustring& value) {
91 thread_local static std::u16string result;
92 result = convert_string::to_u16string(value);
93 return result.c_str();
94 }
95
96 template<>
97 inline const char32* unboxing<char32>(const ustring& value) {
98 thread_local static std::u32string result;
99 result = convert_string::to_u32string(value);
100 return result.c_str();
101 }
102 template<>
103 inline const char32* unboxing<char32>(ustring& value) {
104 thread_local static std::u32string result;
105 result = convert_string::to_u32string(value);
106 return result.c_str();
107 }
108
109 template<>
110 inline const wchar* unboxing<wchar>(const ustring& value) {
111 thread_local static std::wstring result;
112 result = convert_string::to_wstring(value);
113 return result.c_str();
114 }
115 template<>
116 inline const wchar* unboxing<wchar>(ustring& value) {
117 thread_local static std::wstring result;
118 result = convert_string::to_wstring(value);
119 return result.c_str();
120 }
121
122 /*
123 template<typename type_t>
124 inline const type_t& unboxing(const type_t& value) noexcept {
125 if (dynamic_cast<const xtd::enum_object<type_t>*>(&value) != nullptr) {
126 thread_local static type_t result = dynamic_cast<const xtd::enum_object<type_t>*>(&value)->value();
127 return result;
128 }
129 if (dynamic_cast<const xtd::box<type_t>*>(&value) != nullptr)
130 return dynamic_cast<const xtd::box<type_t>*>(&value)->value();
131 return value;
132 }
133
134 template<typename type_t>
135 inline type_t& unboxing(type_t& value) noexcept {
136 if (dynamic_cast<xtd::enum_object<type_t>*>(&value) != nullptr) {
137 thread_local static type_t result = dynamic_cast<xtd::enum_object<type_t>*>(&value)->value();
138 return result;
139 }
140 auto result = dynamic_cast<xtd::box<type_t>*>(&value);
141 if (result != nullptr)
142 return dynamic_cast<xtd::box<type_t>*>(&value)->value();
143 return value;
144 }
145 */
146
147 inline char unboxing(const char& value) noexcept {return value;}
148#if defined(__cpp_lib_char8_t)
149 inline char8 unboxing(const char8& value) noexcept {return value;}
150#endif
151 inline char16 unboxing(const char16& value) noexcept {return value;}
152 inline char32 unboxing(const char32& value) noexcept {return value;}
153 inline wchar unboxing(const wchar& value) noexcept {return value;}
154 inline char unboxing(char& value) noexcept {return value;}
155#if defined(__cpp_lib_char8_t)
156 inline char8 unboxing(char8& value) noexcept {return value;}
157#endif
158 inline char16 unboxing(char16& value) noexcept {return value;}
159 inline char32 unboxing(char32& value) noexcept {return value;}
160 inline wchar unboxing(wchar& value) noexcept {return value;}
161 inline xtd::byte unboxing(const xtd::byte& value) noexcept {return value;}
162 inline int16 unboxing(const int16& value) noexcept {return value;}
163 inline int32 unboxing(const int32& value) noexcept {return value;}
164 inline int64 unboxing(const int64& value) noexcept {return value;}
165 inline slong unboxing(const slong& value) noexcept {return value;}
166 inline sbyte unboxing(const sbyte& value) noexcept {return value;}
167 inline uint16 unboxing(const uint16& value) noexcept {return value;}
168 inline uint32 unboxing(const uint32& value) noexcept {return value;}
169 inline uint64 unboxing(const uint64& value) noexcept {return value;}
170 inline xtd::ulong unboxing(const xtd::ulong& value) noexcept {return value;}
171 inline xtd::byte unboxing(xtd::byte& value) noexcept {return value;}
172 inline int16 unboxing(int16& value) noexcept {return value;}
173 inline int32 unboxing(int32& value) noexcept {return value;}
174 inline int64 unboxing(int64& value) noexcept {return value;}
175 inline slong unboxing(slong& value) noexcept {return value;}
176 inline sbyte unboxing(sbyte& value) noexcept {return value;}
177 inline uint16 unboxing(uint16& value) noexcept {return value;}
178 inline uint32 unboxing(uint32& value) noexcept {return value;}
179 inline uint64 unboxing(uint64& value) noexcept {return value;}
180 inline xtd::ulong unboxing(xtd::ulong& value) noexcept {return value;}
181 inline float unboxing(const float& value) noexcept {return value;}
182 inline double unboxing(const double& value) noexcept {return value;}
183 inline decimal unboxing(const decimal& value) noexcept {return value;}
184 inline float unboxing(float& value) noexcept {return value;}
185 inline double unboxing(double& value) noexcept {return value;}
186 inline decimal unboxing(decimal& value) noexcept {return value;}
187
188 template<typename type_t>
189 inline std::string to_string(const xtd::box<type_t>& value, const std::string& fmt, const std::locale& loc) {
190 return value.to_string(fmt);
191 }
192
193 template<typename type_t>
194 inline std::string to_string(const xtd::box_char<type_t>& value, const std::string& fmt, const std::locale& loc) {
195 return value.to_string(fmt);
196 }
197
198 template<typename type_t>
199 inline std::string to_string(const xtd::box_integer<type_t>& value, const std::string& fmt, const std::locale& loc) {
200 return value.to_string(fmt);
201 }
202
203 template<typename type_t>
204 inline std::string to_string(const xtd::box_floating_point<type_t>& value, const std::string& fmt, const std::locale& loc) {
205 return value.to_string(fmt);
206 }
208}
Contains xtd::box class.
Contains xtd::byte type and xtd::byte_object alias.
Contains xtd::char16 type and xtd::char16_object alias.
Contains xtd::char32 type and xtd::char32_object alias.
Contains xtd::char8 type and xtd::char8_object alias.
Contains xtd::char type and xtd::char_object alias.
Represents a boxed char object.
Definition box_char.h:36
Represents a boxed floating point object.
Definition box_floating_point.h:39
Represents a boxed integer object.
Definition box_integer.h:50
Represents a boxed object.
Definition box.h:47
xtd::ustring to_string() const noexcept override
Returns a sxd::ustring that represents the current object.
Definition box.h:108
static std::u32string to_u32string(const std::string &str) noexcept
Converts std::string to std::u32string.
static std::u8string to_u8string(const std::string &str) noexcept
Converts std::string to std::u8string.
static std::u16string to_u16string(const std::string &str) noexcept
Converts std::string to std::u16string.
static std::wstring to_wstring(const std::string &str) noexcept
Converts std::string to std::wstring.
Provides the base class for enumerations.
Definition enum_object.h:38
Contains xtd::decimal type and xtd::decimal_object alias.
Contains xtd::double type and xtd::double_object alias.
type_t unboxing(const xtd::box< type_t > &value) noexcept
Allows to unbox an object.
Definition unboxing.h:40
char8_t char8
Represents a 8-bit unicode character.
Definition types.h:64
wchar_t wchar
Represents a wide character.
Definition types.h:286
int_least16_t int16
Represents a 16-bit signed integer.
Definition types.h:120
long double decimal
Represents a decimal-precision floating-point number.
Definition types.h:98
__ulong__ ulong
Represents a 32-bit or 64-bit unsigned integer.
Definition types.h:274
char16_t char16
Represents a 16-bit unicode character.
Definition types.h:76
int_least8_t sbyte
Represents a 8-bit signed integer.
Definition types.h:175
int_least64_t int64
Represents a 64-bit signed integer.
Definition types.h:142
uint_least16_t uint16
Represents a 16-bit unsigned integer.
Definition types.h:230
int_least32_t int32
Represents a 32-bit signed integer.
Definition types.h:131
char32_t char32
Represents a 32-bit unicode character.
Definition types.h:87
uint_least64_t uint64
Represents a 64-bit unsigned integer.
Definition types.h:252
uint_least32_t uint32
Represents a 32-bit unsigned integer.
Definition types.h:241
__slong__ slong
Represents a 32-bit or 64-bit signed integer.
Definition types.h:208
uint_least8_t byte
Represents a 8-bit unsigned integer.
Definition types.h:41
std::string to_string(const date_time &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition date_time.h:1080
Contains xtd::int16 type and xtd::int16_object alias.
Contains xtd::int32 type and xtd::int32_object alias.
Contains xtd::int64 type and xtd::int64_object alias.
Contains xtd::intptr type and xtd::intptr_object alias.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Contains xtd::sbyte type and xtd::sbyte_object alias.
Contains xtd::single type and xtd::single_object alias.
Contains xtd::uint16 type and xtd::uint16_object alias.
Contains xtd::uint32 type and xtd::uint32_object alias.
Contains xtd::uint64 type and xtd::uint64_object alias.
Contains xtd::uintptr type and xtd::uintptr_object alias.
Contains xtd::wchar type and xtd::wchar_object alias.
Contains xtd::drawing::size class.