xtd 0.2.0
Loading...
Searching...
No Matches
is.h
Go to the documentation of this file.
1
4#pragma once
5#include "any.h"
6#include "parse.h"
7#include "types.h"
8#include "unused.h"
9#include <limits>
10#include <memory>
11#include <stdexcept>
12
14namespace xtd {
16 template<typename value_t>
17 inline bool is(bool value) {return false;}
18 template<typename value_t>
19 inline bool is(decimal value) {return false;}
20 template<typename value_t>
21 inline bool is(double value) {return false;}
22 template<typename value_t>
23 inline bool is(float value) {return false;}
24 template<typename value_t>
25 inline bool is(sbyte value) {return false;}
26 template<typename value_t>
27 inline bool is(int16 value) {return false;}
28 template<typename value_t>
29 inline bool is(int32 value) {return false;}
30 template<typename value_t>
31 inline bool is(int64 value) {return false;}
32 template<typename value_t>
33 inline bool is(slong value) {return false;}
34 template<typename value_t>
35 inline bool is(xtd::byte value) {return false;}
36 template<typename value_t>
37 inline bool is(uint16 value) {return false;}
38 template<typename value_t>
39 inline bool is(uint32 value) {return false;}
40 template<typename value_t>
41 inline bool is(uint64 value) {return false;}
42 template<typename value_t>
43 inline bool is(xtd::ulong value) {return false;}
45
63 template<>
64 inline bool is<bool>(bool value) {
65 return true;
66 }
67
85 template<>
86 inline bool is<decimal>(decimal value) {
87 return true;
88 }
89
107 template<>
108 inline bool is<double>(double value) {
109 return true;
110 }
111
129 template<>
130 inline bool is<float>(float value) {
131 return true;
132 }
133
151 template<>
152 inline bool is<sbyte>(sbyte value) {
153 return true;
154 }
155
173 template<>
174 inline bool is<int16>(int16 value) {
175 return true;
176 }
177
195 template<>
196 inline bool is<int32>(int32 value) {
197 return true;
198 }
199
217 template<>
218 inline bool is<int64>(int64 value) {
219 return true;
220 }
221
239 template<>
240 inline bool is<slong>(slong value) {
241 return true;
242 }
243
261 template<>
262 inline bool is<xtd::byte>(xtd::byte value) {
263 return true;
264 }
265
283 template<>
284 inline bool is<uint16>(uint16 value) {
285 return true;
286 }
287
305 template<>
306 inline bool is<uint32>(uint32 value) {
307 return true;
308 }
309
327 template<>
328 inline bool is<uint64>(uint64 value) {
329 return true;
330 }
331
349 template<>
350 inline bool is<xtd::ulong>(xtd::ulong value) {
351 return true;
352 }
353
364 template<typename type_t>
365 bool is(std::any value) {
366 try {
367 std::any_cast<type_t>(value);
368 return true;
369 } catch (const std::bad_cast&) {
370 return false;
371 }
372 }
373
384 template<>
385 inline bool is<std::any>(std::any value) {
386 return true;
387 }
388
399 template<typename type_t, typename param_t>
400 bool is(const param_t* value) {
401 try {
402 if (value == nullptr) return false;
403 return dynamic_cast<const type_t*>(value) != nullptr;
404 } catch (const std::bad_cast&) {
405 return false;
406 }
407 }
408
419 template<typename type_t, typename param_t>
420 bool is(const param_t& value) {
421 return is<type_t>(&value);
422 }
423
434 template<typename type_t, typename param_t>
435 bool is(param_t* value) {
436 try {
437 if (value == nullptr) return false;
438 return dynamic_cast<type_t*>(value) != nullptr;
439 } catch (const std::bad_cast&) {
440 return false;
441 }
442 }
443
454 template<typename type_t, typename param_t>
455 bool is(param_t& value) {
456 return is<type_t>(&value);
457 }
458
469 template<typename new_type_t, typename current_type_t>
471 auto result = std::dynamic_pointer_cast<new_type_t>(value);
472 if (result) return true;
473 return false;
474 }
475}
Contains std::any type and std::bad_any_cast exception.
int16_t int16
Represents a 16-bit signed integer.
Definition int16.h:23
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
uint32_t uint32
Represents a 32-bit unsigned integer.
Definition uint32.h:23
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
std::shared_ptr< type_t > sptr
The xtd::sptr object is a shared pointer.
Definition sptr.h:25
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
bool is< float >(float value)
Checks if the result of an expression is compatible with a given type.
Definition is.h:130
bool is< slong >(slong value)
Checks if the result of an expression is compatible with a given type.
Definition is.h:240
bool is< xtd::ulong >(xtd::ulong value)
Checks if the result of an expression is compatible with a given type.
Definition is.h:350
bool is< sbyte >(sbyte value)
Checks if the result of an expression is compatible with a given type.
Definition is.h:152
bool is(std::any value)
Checks if the result of an expression is compatible with a given type.
Definition is.h:365
bool is< decimal >(decimal value)
Checks if the result of an expression is compatible with a given type.
Definition is.h:86
bool is< int64 >(int64 value)
Checks if the result of an expression is compatible with a given type.
Definition is.h:218
bool is< uint64 >(uint64 value)
Checks if the result of an expression is compatible with a given type.
Definition is.h:328
bool is< double >(double value)
Checks if the result of an expression is compatible with a given type.
Definition is.h:108
bool is< uint16 >(uint16 value)
Checks if the result of an expression is compatible with a given type.
Definition is.h:284
bool is< bool >(bool value)
Checks if the result of an expression is compatible with a given type.
Definition is.h:64
bool is< uint32 >(uint32 value)
Checks if the result of an expression is compatible with a given type.
Definition is.h:306
bool is< std::any >(std::any value)
Checks if the result of an expression is compatible with a given type.
Definition is.h:385
bool is< int32 >(int32 value)
Checks if the result of an expression is compatible with a given type.
Definition is.h:196
bool is< int16 >(int16 value)
Checks if the result of an expression is compatible with a given type.
Definition is.h:174
bool is< xtd::byte >(xtd::byte value)
Checks if the result of an expression is compatible with a given type.
Definition is.h:262
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Contains xtd::parse methods.
Contains unused_ keyword.
Contains xtd fundamental types.