xtd 0.2.0
Loading...
Searching...
No Matches
is.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "any.hpp"
6#include "parse.hpp"
7#include "types.hpp"
8#include <limits>
9#include <memory>
10#include <stdexcept>
11
13namespace xtd {
15 template<class value_t>
16 inline bool is(bool value) {return false;}
17 template<class value_t>
18 inline bool is(char value) {return false;}
19 template<class value_t>
20 inline bool is(char16 value) {return false;}
21 template<class value_t>
22 inline bool is(char32 value) {return false;}
23 template<class value_t>
24 inline bool is(char8 value) {return false;}
25 template<class value_t>
26 inline bool is(wchar value) {return false;}
27 template<class value_t>
28 inline bool is(decimal value) {return false;}
29 template<class value_t>
30 inline bool is(double value) {return false;}
31 template<class value_t>
32 inline bool is(float value) {return false;}
33 template<class value_t>
34 inline bool is(sbyte value) {return false;}
35 template<class value_t>
36 inline bool is(int16 value) {return false;}
37 template<class value_t>
38 inline bool is(int32 value) {return false;}
39 template<class value_t>
40 inline bool is(int64 value) {return false;}
41 template<class value_t>
42 inline bool is(slong value) {return false;}
43 template<class value_t>
44 inline bool is(xtd::byte value) {return false;}
45 template<class value_t>
46 inline bool is(uint16 value) {return false;}
47 template<class value_t>
48 inline bool is(uint32 value) {return false;}
49 template<class value_t>
50 inline bool is(uint64 value) {return false;}
51 template<class value_t>
52 inline bool is(xtd::ulong value) {return false;}
54
72 template<>
73 inline bool is<bool>(bool value) {
74 return true;
75 }
76
94 template<>
95 inline bool is<char>(char value) {
96 return true;
97 }
98
116 template<>
117 inline bool is<char16>(char16 value) {
118 return true;
119 }
120
138 template<>
139 inline bool is<char32>(char32 value) {
140 return true;
141 }
142
160 template<>
161 inline bool is<char8>(char8 value) {
162 return true;
163 }
164
182 template<>
183 inline bool is<wchar>(wchar value) {
184 return true;
185 }
186
204 template<>
205 inline bool is<decimal>(decimal value) {
206 return true;
207 }
208
226 template<>
227 inline bool is<double>(double value) {
228 return true;
229 }
230
248 template<>
249 inline bool is<float>(float value) {
250 return true;
251 }
252
270 template<>
271 inline bool is<sbyte>(sbyte value) {
272 return true;
273 }
274
292 template<>
293 inline bool is<int16>(int16 value) {
294 return true;
295 }
296
314 template<>
315 inline bool is<int32>(int32 value) {
316 return true;
317 }
318
336 template<>
337 inline bool is<int64>(int64 value) {
338 return true;
339 }
340
358 template<>
359 inline bool is<slong>(slong value) {
360 return true;
361 }
362
380 template<>
381 inline bool is<xtd::byte>(xtd::byte value) {
382 return true;
383 }
384
402 template<>
403 inline bool is<uint16>(uint16 value) {
404 return true;
405 }
406
424 template<>
425 inline bool is<uint32>(uint32 value) {
426 return true;
427 }
428
446 template<>
447 inline bool is<uint64>(uint64 value) {
448 return true;
449 }
450
468 template<>
469 inline bool is<xtd::ulong>(xtd::ulong value) {
470 return true;
471 }
472
483 template<class type_t>
484 bool is(xtd::any value) {
485 try {
487 return true;
488 } catch (const std::bad_cast&) {
489 return false;
490 }
491 }
492
503 template<>
504 inline bool is<xtd::any>(xtd::any value) {
505 return true;
506 }
507
518 template<class type_t, class param_t>
519 bool is(const param_t* value) {
520 try {
521 if (value == nullptr) return false;
522 return dynamic_cast<const type_t*>(value) != nullptr;
523 } catch (const std::bad_cast&) {
524 return false;
525 }
526 }
527
538 template<class type_t, class param_t>
539 bool is(const param_t& value) {
540 return is<type_t>(&value);
541 }
542
553 template<class type_t, class param_t>
554 bool is(param_t* value) {
555 try {
556 if (value == nullptr) return false;
557 return dynamic_cast<type_t*>(value) != nullptr;
558 } catch (const std::bad_cast&) {
559 return false;
560 }
561 }
562
573 template<class type_t, class param_t>
574 bool is(param_t& value) {
575 return is<type_t>(&value);
576 }
577
588 template<class new_type_t, class current_type_t>
590 auto result = std::dynamic_pointer_cast<new_type_t>(value.pointer());
591 if (result) return true;
592 return false;
593 }
594}
Contains xtd::any type and std::bad_any_cast exception.
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
xtd::shared_ptr_object< type_t > sptr
The xtd::sptr object is a shared pointer.
Definition sptr.hpp:25
__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:23
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
std::any any
Represents the any alias on std::any.
Definition any.hpp:24
bool is< float >(float value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:249
bool is< slong >(slong value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:359
bool is< wchar >(wchar value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:183
bool is< xtd::ulong >(xtd::ulong value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:469
type_t any_cast(const xtd::any &operand)
Performs type-safe access to the contained object.
Definition any_cast.hpp:22
bool is< sbyte >(sbyte value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:271
bool is< decimal >(decimal value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:205
bool is< int64 >(int64 value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:337
bool is< char16 >(char16 value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:117
bool is(xtd::any value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:484
bool is< xtd::any >(xtd::any value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:504
bool is< char32 >(char32 value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:139
bool is< uint64 >(uint64 value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:447
bool is< double >(double value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:227
bool is< uint16 >(uint16 value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:403
bool is< bool >(bool value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:73
bool is< uint32 >(uint32 value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:425
bool is< char8 >(char8 value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:161
bool is< int32 >(int32 value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:315
bool is< char >(char value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:95
bool is< int16 >(int16 value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:293
bool is< xtd::byte >(xtd::byte value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:381
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Contains xtd::parse methods.
Contains xtd fundamental types.