xtd 0.2.0
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 "size.hpp"
20#include "uint16.hpp"
21#include "uint32.hpp"
22#include "uint64.hpp"
23#include "uintptr.hpp"
24#include "wchar.hpp"
25#define __XTD_STD_INTERNAL__
27#undef __XTD_STD_INTERNAL__
28
30namespace xtd {
32
47 template<class type_t>
48 inline type_t unboxing(const xtd::box<type_t>& value) noexcept {return value.value();}
50
52 template<class type_t>
53 inline type_t unboxing(xtd::box<type_t>& value) noexcept {return value.value();}
54
55 template<class type_t>
56 inline type_t unboxing(const xtd::enum_object<type_t>& value) noexcept {return value.value();}
57
58 template<class type_t>
59 inline type_t unboxing(xtd::enum_object<type_t>& value) noexcept {return value.value();}
60
61 inline const object& unboxing(const object& value) noexcept {return value;}
62 inline object& unboxing(object& value) noexcept {return value;}
63
64 inline const char* unboxing(const string& value) noexcept {return value.c_str();}
65 inline const char* unboxing(string& value) noexcept {return value.c_str();}
66
67 template<class char_t>
68 inline const char_t* unboxing(const string& value) {xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::invalid_cast, "Invalid character type");}
69 template<class char_t>
70 inline const char_t* unboxing(string& value) {xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::invalid_cast, "Invalid character type");}
71
72 template<>
73 inline const char* unboxing<char>(const string& value) {return value.c_str();}
74 template<>
75 inline const char* unboxing<char>(string& value) {return value.c_str();}
76
77#if defined(__xtd__cpp_lib_char8_t)
78 template<>
79 inline const char8* unboxing<char8>(const string& value) {
80 thread_local static std::u8string result;
81 result = convert_string::to_u8string(value);
82 return result.c_str();
83 }
84 template<>
85 inline const char8* unboxing<char8>(string& value) {
86 thread_local static std::u8string result;
87 result = convert_string::to_u8string(value);
88 return result.c_str();
89 }
90#endif
91
92 template<>
93 inline const char16* unboxing<char16>(const string& value) {
94 thread_local static std::u16string result;
95 result = convert_string::to_u16string(value);
96 return result.c_str();
97 }
98 template<>
99 inline const char16* unboxing<char16>(string& value) {
100 thread_local static std::u16string result;
101 result = convert_string::to_u16string(value);
102 return result.c_str();
103 }
104
105 template<>
106 inline const char32* unboxing<char32>(const string& value) {
107 thread_local static std::u32string result;
108 result = convert_string::to_u32string(value);
109 return result.c_str();
110 }
111 template<>
112 inline const char32* unboxing<char32>(string& value) {
113 thread_local static std::u32string result;
114 result = convert_string::to_u32string(value);
115 return result.c_str();
116 }
117
118 template<>
119 inline const wchar* unboxing<wchar>(const string& value) {
120 thread_local static std::wstring result;
121 result = convert_string::to_wstring(value);
122 return result.c_str();
123 }
124 template<>
125 inline const wchar* unboxing<wchar>(string& value) {
126 thread_local static std::wstring result;
127 result = convert_string::to_wstring(value);
128 return result.c_str();
129 }
130
131 /*
132 template<class type_t>
133 inline const type_t& unboxing(const type_t& value) noexcept {
134 if (dynamic_cast<const xtd::enum_object<type_t>*>(&value) != nullptr) {
135 thread_local static type_t result = dynamic_cast<const xtd::enum_object<type_t>*>(&value)->value();
136 return result;
137 }
138 if (dynamic_cast<const xtd::box<type_t>*>(&value) != nullptr)
139 return dynamic_cast<const xtd::box<type_t>*>(&value)->value();
140 return value;
141 }
142
143 template<class type_t>
144 inline type_t& unboxing(type_t& value) noexcept {
145 if (dynamic_cast<xtd::enum_object<type_t>*>(&value) != nullptr) {
146 thread_local static type_t result = dynamic_cast<xtd::enum_object<type_t>*>(&value)->value();
147 return result;
148 }
149 auto result = dynamic_cast<xtd::box<type_t>*>(&value);
150 if (result != nullptr)
151 return dynamic_cast<xtd::box<type_t>*>(&value)->value();
152 return value;
153 }
154 */
155
156 inline char unboxing(const char& value) noexcept {return value;}
157#if defined(__xtd__cpp_lib_char8_t)
158 inline char8 unboxing(const char8& value) noexcept {return value;}
159#endif
160 inline char16 unboxing(const char16& value) noexcept {return value;}
161 inline char32 unboxing(const char32& value) noexcept {return value;}
162 inline wchar unboxing(const wchar& value) noexcept {return value;}
163 inline char unboxing(char& value) noexcept {return value;}
164#if defined(__xtd__cpp_lib_char8_t)
165 inline char8 unboxing(char8& value) noexcept {return value;}
166#endif
167 inline char16 unboxing(char16& value) noexcept {return value;}
168 inline char32 unboxing(char32& value) noexcept {return value;}
169 inline wchar unboxing(wchar& value) noexcept {return value;}
170 inline xtd::byte unboxing(const xtd::byte& value) noexcept {return value;}
171 inline int16 unboxing(const int16& value) noexcept {return value;}
172 inline int32 unboxing(const int32& value) noexcept {return value;}
173 inline int64 unboxing(const int64& value) noexcept {return value;}
174 inline slong unboxing(const slong& value) noexcept {return value;}
175 inline sbyte unboxing(const sbyte& value) noexcept {return value;}
176 inline uint16 unboxing(const uint16& value) noexcept {return value;}
177 inline uint32 unboxing(const uint32& value) noexcept {return value;}
178 inline uint64 unboxing(const uint64& value) noexcept {return value;}
179 inline xtd::ulong unboxing(const xtd::ulong& value) noexcept {return value;}
180 inline xtd::byte unboxing(xtd::byte& value) noexcept {return value;}
181 inline int16 unboxing(int16& value) noexcept {return value;}
182 inline int32 unboxing(int32& value) noexcept {return value;}
183 inline int64 unboxing(int64& value) noexcept {return value;}
184 inline slong unboxing(slong& value) noexcept {return value;}
185 inline sbyte unboxing(sbyte& value) noexcept {return value;}
186 inline uint16 unboxing(uint16& value) noexcept {return value;}
187 inline uint32 unboxing(uint32& value) noexcept {return value;}
188 inline uint64 unboxing(uint64& value) noexcept {return value;}
189 inline xtd::ulong unboxing(xtd::ulong& value) noexcept {return value;}
190 inline float unboxing(const float& value) noexcept {return value;}
191 inline double unboxing(const double& value) noexcept {return value;}
192 inline decimal unboxing(const decimal& value) noexcept {return value;}
193 inline float unboxing(float& value) noexcept {return value;}
194 inline double unboxing(double& value) noexcept {return value;}
195 inline decimal unboxing(decimal& value) noexcept {return value;}
197}
Contains __xtd_std_version definitions.
Contains xtd::box struct.
Contains xtd::byte type.
Contains xtd::char16 type.
Contains xtd::char32 type.
Contains xtd::char8 type.
Contains xtd::char_ type.
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.
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
Contains xtd::decimal type.
Contains xtd::double_ type.
@ invalid_cast
The cast is not valid.
type_t unboxing(const xtd::box< type_t > &value) noexcept
Allows to unbox an object.
Definition unboxing.hpp:48
int16_t int16
Represents a 16-bit signed integer.
Definition int16.hpp:23
char8_t char8
Represents a 8-bit unicode character.
Definition char8.hpp:27
wchar_t wchar
Represents a wide character.
Definition wchar.hpp:24
int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
long double decimal
Represents a decimal-precision floating-point number.
Definition decimal.hpp:23
int64_t int64
Represents a 64-bit signed integer.
Definition int64.hpp:23
__ulong__ ulong
Represents a 32-bit or 64-bit unsigned integer.
Definition ulong.hpp:27
int8_t sbyte
Represents a 8-bit signed integer.
Definition sbyte.hpp:23
char16_t char16
Represents a 16-bit unicode character.
Definition char16.hpp:26
uint32_t uint32
Represents a 32-bit unsigned integer.
Definition uint32.hpp:23
char32_t char32
Represents a 32-bit unicode character.
Definition char32.hpp:26
uint64_t uint64
Represents a 64-bit unsigned integer.
Definition uint64.hpp:23
uint8_t byte
Represents a 8-bit unsigned integer.
Definition byte.hpp:23
uint16_t uint16
Represents a 16-bit unsigned integer.
Definition uint16.hpp:23
__slong__ slong
Represents a 32-bit or 64-bit signed integer.
Definition slong.hpp:27
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 xtd_about_box.hpp:10
Contains xtd::sbyte type.
Contains xtd::single type.
Represents a boxed object.
Definition box.hpp:56
Provides the base class for enumerations.
Definition enum_object.hpp:48
Contains xtd::uint16 type.
Contains xtd::uint32 type.
Contains xtd::uint64 type.
Contains xtd::uintptr type.
Contains xtd::wchar type.
Contains xtd::drawing::size class.