TachyonUI
0.1.0
High-performance UI for building tools.
Toggle main menu visibility
Loading...
Searching...
No Matches
gui_numeric_type.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <cstdint>
4
5
namespace
tachyon
6
{
9
10
// ------------------------------------------------------------------------
11
// Numeric Value Union/Type - For editable numeric text fields
12
// ------------------------------------------------------------------------
13
14
enum class
NumericType
15
{
16
None
,
17
18
TypeUnsignedBit
= 16,
19
TypeSignedBit
= 32,
20
TypeFloatBit
= 64,
21
22
TypeUInt8
=
TypeUnsignedBit
| 1,
23
TypeUInt16
=
TypeUnsignedBit
| 2,
24
TypeUInt32
=
TypeUnsignedBit
| 3,
25
TypeUInt64
=
TypeUnsignedBit
| 4,
26
27
TypeInt8
=
TypeSignedBit
| 1,
28
TypeInt16
=
TypeSignedBit
| 2,
29
TypeInt32
=
TypeSignedBit
| 3,
30
TypeInt64
=
TypeSignedBit
| 4,
31
32
TypeFloat
=
TypeFloatBit
| 1,
33
TypeDouble
=
TypeFloatBit
| 2
34
};
35
36
union
NumericValue
37
{
38
uint8_t
value_uint8
;
39
uint16_t
value_uint16
;
40
uint32_t
value_uint32
;
41
uint64_t
value_uint64
;
42
43
int8_t
value_int8
;
44
int16_t
value_int16
;
45
int32_t
value_int32
;
46
int64_t
value_int64
;
47
48
float
value_float
;
49
double
value_double
;
50
};
51
52
template
<
typename
T>
constexpr
NumericType
GetNumericType
(
const
T&
/*value*/
) {
return
NumericType::None
; }
53
template
<>
constexpr
NumericType
GetNumericType
(
const
int8_t&
/*value*/
) {
return
NumericType::TypeInt8
; }
54
template
<>
constexpr
NumericType
GetNumericType
(
const
int16_t&
/*value*/
) {
return
NumericType::TypeInt16
; }
55
template
<>
constexpr
NumericType
GetNumericType
(
const
int32_t&
/*value*/
) {
return
NumericType::TypeInt32
; }
56
template
<>
constexpr
NumericType
GetNumericType
(
const
int64_t&
/*value*/
) {
return
NumericType::TypeInt64
; }
57
template
<>
constexpr
NumericType
GetNumericType
(
const
uint8_t&
/*value*/
) {
return
NumericType::TypeUInt8
; }
58
template
<>
constexpr
NumericType
GetNumericType
(
const
uint16_t&
/*value*/
) {
return
NumericType::TypeUInt16
; }
59
template
<>
constexpr
NumericType
GetNumericType
(
const
uint32_t&
/*value*/
) {
return
NumericType::TypeUInt32
; }
60
template
<>
constexpr
NumericType
GetNumericType
(
const
uint64_t&
/*value*/
) {
return
NumericType::TypeUInt64
; }
61
template
<>
constexpr
NumericType
GetNumericType
(
const
float
&
/*value*/
) {
return
NumericType::TypeFloat
; }
62
template
<>
constexpr
NumericType
GetNumericType
(
const
double
&
/*value*/
) {
return
NumericType::TypeDouble
; }
63
64
template
<
typename
T>
NumericType
CopyNumericTypeTo
(
const
T&
/*src*/
,
NumericValue
& dst) { dst = {};
return
NumericType::None
; }
65
template
<>
inline
NumericType
CopyNumericTypeTo
(
const
int8_t& src,
NumericValue
& dst) { dst.
value_int8
= src;
return
NumericType::TypeInt8
; }
66
template
<>
inline
NumericType
CopyNumericTypeTo
(
const
int16_t& src,
NumericValue
& dst) { dst.
value_int16
= src;
return
NumericType::TypeInt16
; }
67
template
<>
inline
NumericType
CopyNumericTypeTo
(
const
int32_t& src,
NumericValue
& dst) { dst.
value_int32
= src;
return
NumericType::TypeInt32
; }
68
template
<>
inline
NumericType
CopyNumericTypeTo
(
const
int64_t& src,
NumericValue
& dst) { dst.
value_int64
= src;
return
NumericType::TypeInt64
; }
69
template
<>
inline
NumericType
CopyNumericTypeTo
(
const
uint8_t& src,
NumericValue
& dst) { dst.
value_uint8
= src;
return
NumericType::TypeUInt8
; }
70
template
<>
inline
NumericType
CopyNumericTypeTo
(
const
uint16_t& src,
NumericValue
& dst) { dst.
value_uint16
= src;
return
NumericType::TypeUInt16
; }
71
template
<>
inline
NumericType
CopyNumericTypeTo
(
const
uint32_t& src,
NumericValue
& dst) { dst.
value_uint32
= src;
return
NumericType::TypeUInt32
; }
72
template
<>
inline
NumericType
CopyNumericTypeTo
(
const
uint64_t& src,
NumericValue
& dst) { dst.
value_uint64
= src;
return
NumericType::TypeUInt64
; }
73
template
<>
inline
NumericType
CopyNumericTypeTo
(
const
float
& src,
NumericValue
& dst) { dst.
value_float
= src;
return
NumericType::TypeFloat
; }
74
template
<>
inline
NumericType
CopyNumericTypeTo
(
const
double
& src,
NumericValue
& dst) { dst.
value_double
= src;
return
NumericType::TypeDouble
; }
75
76
template
<
typename
T>
bool
CopyNumericTypeTo
(
NumericType
/*type*/
,
const
NumericValue
&
/*src*/
, T&
/*dst*/
) {
return
false
; }
77
template
<>
inline
bool
CopyNumericTypeTo
(
NumericType
type,
const
NumericValue
& src, int8_t& dst) {
if
(type !=
NumericType::TypeInt8
)
return
false
; dst = src.
value_int8
;
return
true
; }
78
template
<>
inline
bool
CopyNumericTypeTo
(
NumericType
type,
const
NumericValue
& src, int16_t& dst) {
if
(type !=
NumericType::TypeInt16
)
return
false
; dst = src.
value_int16
;
return
true
; }
79
template
<>
inline
bool
CopyNumericTypeTo
(
NumericType
type,
const
NumericValue
& src, int32_t& dst) {
if
(type !=
NumericType::TypeInt32
)
return
false
; dst = src.
value_int32
;
return
true
; }
80
template
<>
inline
bool
CopyNumericTypeTo
(
NumericType
type,
const
NumericValue
& src, int64_t& dst) {
if
(type !=
NumericType::TypeInt64
)
return
false
; dst = src.
value_int64
;
return
true
; }
81
template
<>
inline
bool
CopyNumericTypeTo
(
NumericType
type,
const
NumericValue
& src, uint8_t& dst) {
if
(type !=
NumericType::TypeUInt8
)
return
false
; dst = src.
value_uint8
;
return
true
; }
82
template
<>
inline
bool
CopyNumericTypeTo
(
NumericType
type,
const
NumericValue
& src, uint16_t& dst) {
if
(type !=
NumericType::TypeUInt16
)
return
false
; dst = src.
value_uint16
;
return
true
; }
83
template
<>
inline
bool
CopyNumericTypeTo
(
NumericType
type,
const
NumericValue
& src, uint32_t& dst) {
if
(type !=
NumericType::TypeUInt32
)
return
false
; dst = src.
value_uint32
;
return
true
; }
84
template
<>
inline
bool
CopyNumericTypeTo
(
NumericType
type,
const
NumericValue
& src, uint64_t& dst) {
if
(type !=
NumericType::TypeUInt64
)
return
false
; dst = src.
value_uint64
;
return
true
; }
85
template
<>
inline
bool
CopyNumericTypeTo
(
NumericType
type,
const
NumericValue
& src,
float
& dst) {
if
(type !=
NumericType::TypeFloat
)
return
false
; dst = src.
value_float
;
return
true
; }
86
template
<>
inline
bool
CopyNumericTypeTo
(
NumericType
type,
const
NumericValue
& src,
double
& dst) {
if
(type !=
NumericType::TypeDouble
)
return
false
; dst = src.
value_double
;
return
true
; }
87
88
template
<
typename
T>
bool
EqualsNumericType
(
NumericType
/*type*/
,
NumericValue
&
/*left*/
,
const
T&
/*right*/
) {
return
false
; }
89
template
<>
inline
bool
EqualsNumericType
(
NumericType
type,
NumericValue
& left,
const
int8_t& right) {
return
type ==
NumericType::TypeInt8
&& left.
value_int8
== right; }
90
template
<>
inline
bool
EqualsNumericType
(
NumericType
type,
NumericValue
& left,
const
int16_t& right) {
return
type ==
NumericType::TypeInt16
&& left.
value_int16
== right; }
91
template
<>
inline
bool
EqualsNumericType
(
NumericType
type,
NumericValue
& left,
const
int32_t& right) {
return
type ==
NumericType::TypeInt32
&& left.
value_int32
== right; }
92
template
<>
inline
bool
EqualsNumericType
(
NumericType
type,
NumericValue
& left,
const
int64_t& right) {
return
type ==
NumericType::TypeInt64
&& left.
value_int64
== right; }
93
template
<>
inline
bool
EqualsNumericType
(
NumericType
type,
NumericValue
& left,
const
uint8_t& right) {
return
type ==
NumericType::TypeUInt8
&& left.
value_uint8
== right; }
94
template
<>
inline
bool
EqualsNumericType
(
NumericType
type,
NumericValue
& left,
const
uint16_t& right) {
return
type ==
NumericType::TypeUInt16
&& left.
value_uint16
== right; }
95
template
<>
inline
bool
EqualsNumericType
(
NumericType
type,
NumericValue
& left,
const
uint32_t& right) {
return
type ==
NumericType::TypeUInt32
&& left.
value_uint32
== right; }
96
template
<>
inline
bool
EqualsNumericType
(
NumericType
type,
NumericValue
& left,
const
uint64_t& right) {
return
type ==
NumericType::TypeUInt64
&& left.
value_uint64
== right; }
97
template
<>
inline
bool
EqualsNumericType
(
NumericType
type,
NumericValue
& left,
const
float
& right) {
return
type ==
NumericType::TypeFloat
&& left.
value_float
== right; }
98
template
<>
inline
bool
EqualsNumericType
(
NumericType
type,
NumericValue
& left,
const
double
& right) {
return
type ==
NumericType::TypeDouble
&& left.
value_double
== right; }
99
100
inline
bool
EqualsNumericType
(
NumericType
leftType,
NumericValue
& left,
NumericType
rightType,
const
NumericValue
& right)
101
{
102
if
(leftType != rightType)
return
false
;
103
switch
(leftType)
104
{
105
case
NumericType::TypeFloat
:
return
left.
value_float
== right.
value_float
;
106
case
NumericType::TypeDouble
:
return
left.
value_double
== right.
value_double
;
107
108
case
NumericType::TypeUInt64
:
return
left.
value_uint64
== right.
value_uint64
;
109
case
NumericType::TypeUInt32
:
return
left.
value_uint32
== right.
value_uint32
;
110
case
NumericType::TypeUInt16
:
return
left.
value_uint16
== right.
value_uint16
;
111
case
NumericType::TypeUInt8
:
return
left.
value_uint8
== right.
value_uint8
;
112
113
case
NumericType::TypeInt64
:
return
left.
value_int64
== right.
value_int64
;
114
case
NumericType::TypeInt32
:
return
left.
value_int32
== right.
value_int32
;
115
case
NumericType::TypeInt16
:
return
left.
value_int16
== right.
value_int16
;
116
case
NumericType::TypeInt8
:
return
left.
value_int8
== right.
value_int8
;
117
118
default
:
return
false
;
119
}
120
}
121
122
}
tachyon::ElementFlags::None
@ None
Definition
gui_element_flags.h:19
tachyon::CopyNumericTypeTo
NumericType CopyNumericTypeTo(const T &, NumericValue &dst)
Definition
gui_numeric_type.h:64
tachyon::NumericType
NumericType
Definition
gui_numeric_type.h:15
tachyon::EqualsNumericType
bool EqualsNumericType(NumericType, NumericValue &, const T &)
Definition
gui_numeric_type.h:88
tachyon::GetNumericType
constexpr NumericType GetNumericType(const T &)
Definition
gui_numeric_type.h:52
tachyon::NumericType::TypeFloat
@ TypeFloat
Definition
gui_numeric_type.h:32
tachyon::NumericType::TypeInt64
@ TypeInt64
Definition
gui_numeric_type.h:30
tachyon::NumericType::TypeInt16
@ TypeInt16
Definition
gui_numeric_type.h:28
tachyon::NumericType::TypeInt32
@ TypeInt32
Definition
gui_numeric_type.h:29
tachyon::NumericType::None
@ None
not a numeric type
Definition
gui_numeric_type.h:16
tachyon::NumericType::TypeUInt32
@ TypeUInt32
Definition
gui_numeric_type.h:24
tachyon::NumericType::TypeDouble
@ TypeDouble
Definition
gui_numeric_type.h:33
tachyon::NumericType::TypeUInt64
@ TypeUInt64
Definition
gui_numeric_type.h:25
tachyon::NumericType::TypeUInt16
@ TypeUInt16
Definition
gui_numeric_type.h:23
tachyon::NumericType::TypeSignedBit
@ TypeSignedBit
Definition
gui_numeric_type.h:19
tachyon::NumericType::TypeFloatBit
@ TypeFloatBit
Definition
gui_numeric_type.h:20
tachyon::NumericType::TypeInt8
@ TypeInt8
Definition
gui_numeric_type.h:27
tachyon::NumericType::TypeUInt8
@ TypeUInt8
Definition
gui_numeric_type.h:22
tachyon::NumericType::TypeUnsignedBit
@ TypeUnsignedBit
Definition
gui_numeric_type.h:18
tachyon
Definition
gui_logging.h:24
tachyon::NumericValue
Definition
gui_numeric_type.h:37
tachyon::NumericValue::value_int32
int32_t value_int32
Definition
gui_numeric_type.h:45
tachyon::NumericValue::value_uint16
uint16_t value_uint16
Definition
gui_numeric_type.h:39
tachyon::NumericValue::value_uint64
uint64_t value_uint64
Definition
gui_numeric_type.h:41
tachyon::NumericValue::value_int8
int8_t value_int8
Definition
gui_numeric_type.h:43
tachyon::NumericValue::value_int16
int16_t value_int16
Definition
gui_numeric_type.h:44
tachyon::NumericValue::value_uint8
uint8_t value_uint8
Definition
gui_numeric_type.h:38
tachyon::NumericValue::value_float
float value_float
Definition
gui_numeric_type.h:48
tachyon::NumericValue::value_double
double value_double
Definition
gui_numeric_type.h:49
tachyon::NumericValue::value_uint32
uint32_t value_uint32
Definition
gui_numeric_type.h:40
tachyon::NumericValue::value_int64
int64_t value_int64
Definition
gui_numeric_type.h:46
gui_core
text
gui_numeric_type.h
Generated by
1.18.0