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