acme
Foundational cross-platform layer of the ca2 framework
Toggle main menu visibility
Loading...
Searching...
No Matches
boolean.h
1
#pragma once
2
3
4
#include "acme/prototype/prototype/e_check.h"
5
6
class
i32_boolean
7
{
8
public
:
9
10
11
::i32 m_i;
12
13
14
15
constexpr
i32_boolean():m_i(0) { }
16
17
18
template
<
typename
T>
19
requires
(::std::is_same<typename T::CFLAG_TYPE_TAG, c_flag_type_t>::value)
20
constexpr
i32_boolean(
const
T & t):
21
m_i((
bool
)t)
22
{
23
24
}
25
template
<
typename
T>
26
requires
(::std::is_enum<T>::value)
27
constexpr
i32_boolean(
const
T & t):
28
m_i((((::std::underlying_type_t<T>)t) != (::std::underlying_type_t<T>)0))
29
{
30
31
}
32
constexpr
i32_boolean(::i32 i):m_i(i) { }
33
34
35
//constexpr boolean(bool b) { m_uOn = b ? 1 : 0; m_uSet = 1; }
36
37
38
constexpr
i32_boolean(
const
i32_boolean&
boolean
) :m_i(
boolean
.m_i){}
39
40
constexpr
operator
bool()
const
{
return
m_i;}
41
constexpr
operator ::i32 &() {
return
m_i;}
42
43
};
44
45
46
namespace
logic
47
{
48
49
50
//#pragma pack(push, boolean, 1)
51
52
53
54
class
boolean
55
{
56
public
:
57
58
59
::u8 m_uOn;
60
::u8 m_uSet;
61
62
63
//inline boolean(no_initialize_t) { m_uSet = false; }
64
65
66
constexpr
boolean() { m_uSet = 0; }
67
68
69
template
<
typename
T>
70
requires
(::std::is_same<typename T::CFLAG_TYPE_TAG, c_flag_type_t>::value)
71
constexpr
boolean
(
const
T & t)
72
{
73
m_uSet=1;
74
m_uOn = (bool) t;
75
76
}
77
constexpr
boolean(::i32 i) { m_uOn = i ? 1 : 0; m_uSet = 1; }
78
79
80
//constexpr boolean(bool b) { m_uOn = b ? 1 : 0; m_uSet = 1; }
81
82
83
constexpr
boolean(
const
boolean
&
boolean
) =
default
;
84
85
86
inline
constexpr
bool
is_set_false()
const
{
return
m_uSet && !m_uOn; }
87
88
inline
constexpr
bool
is_set_true()
const
{
return
m_uSet && m_uOn; }
89
90
inline
constexpr
bool
is_true_default_false()
const
{
return
m_uSet && m_uOn; }
91
92
inline
constexpr
bool
undefined()
const
{
return
!m_uSet; }
93
94
inline
constexpr
bool
is_set()
const
{
return
m_uSet; }
95
96
inline
constexpr
bool
is_false_or_undefined()
const
{
return
!m_uSet || !m_uOn; }
97
98
inline
constexpr
bool
is_true_or_undefined()
const
{
return
!m_uSet || m_uOn; }
99
100
inline
constexpr
bool
is_false_default_true()
const
{
return
!m_uSet || !m_uOn; }
101
102
inline
constexpr
bool
is_true_default_true()
const
{
return
!m_uSet || m_uOn; }
103
104
inline
constexpr
bool
is_true(
bool
bDefault)
const
{
return
m_uSet ? m_uOn : bDefault; }
105
106
inline
constexpr
bool
is_false(
bool
bDefault)
const
{
return
m_uSet ? !m_uOn : bDefault; }
107
108
//inline bool is_optional() const { return !m_eboolean; }
109
110
111
//inline bool isOptional() const { return is_optional(); }
112
113
114
inline
operator
bool()
const
{
return
is_set_true(); }
115
116
inline
bool
operator!()
const
{
return
is_false_or_undefined(); }
117
118
119
//inline bool operator<(::i32 i) const { return (::i32)m_eboolean < i; }
120
121
122
//inline bool operator<=(::i32 i) const { return (::i32)m_eboolean <= i; }
123
124
125
//inline bool operator>(::i32 i) const { return (::i32)m_eboolean > i; }
126
127
128
//inline bool operator>=(::i32 i) const { return (::i32)m_eboolean >= i; }
129
130
131
inline
bool
operator==(
const
boolean
& b)
const
132
{
133
134
if
(this->undefined() || b.undefined())
135
{
136
137
return
false
;
138
139
}
140
141
return
m_uOn ^ b.m_uOn;
142
143
}
144
145
146
//inline bool operator!=(::i32 i) const { return !operator==(i); }
147
148
149
inline
boolean
& operator=(const ::logic::boolean& b)
150
{
151
if
(b.is_set())
152
{
153
m_uOn = b.m_uOn;
154
m_uSet = 1;
155
}
156
else
157
{
158
m_uSet = 0;
159
160
}
161
return
*
this
;
162
}
163
164
165
//inline boolean& operator=(bool b)
166
//{
167
// m_eboolean = (b ? e_boolean_true : e_boolean_false);
168
// return *this;
169
//}
170
171
172
//inline bool operator==(bool b) const { return (m_eboolean == e_boolean_true && b) || (m_eboolean == e_boolean_false && !b); }
173
174
175
//inline bool operator!=(bool b) const { return !operator==(b); }
176
177
178
//inline boolean& operator=(const boolean& boolean)
179
//{
180
// if (this != &boolean && !boolean.undefined()) { m_eboolean = boolean.m_eboolean; };
181
// return *this;
182
//}
183
184
185
inline
void
defer(
const
boolean
& b) {
if
(this->undefined()) { operator =(b); } }
186
187
188
inline
boolean
deferred(
const
boolean
& b)
const
{
if
(this->undefined()) {
return
b; }
else
{
return
*
this
; } }
189
190
191
inline
boolean
operator()(
const
boolean
& b = 1)
const
{
return
deferred(b); }
192
193
inline
boolean
& operator()(
const
boolean
& b = 0) {
return
operator =(b); }
194
195
196
operator ::e_check()
const
197
{
198
199
if
(this->undefined())
200
{
201
202
return
e_check_undefined;
203
204
}
205
else
if
(m_uOn)
206
{
207
208
return
e_check_checked;
209
210
}
211
else
212
{
213
214
return
e_check_unchecked;
215
216
}
217
218
}
219
220
};
221
222
223
}
// namespace logic
224
225
226
//#pragma pack(pop, boolean)
227
228
//inline bool __is_true(bool b) { return b; }
229
//
230
//
231
//inline bool __is_true(const enum_boolean & boolean) { return boolean > 0; }
232
//
233
//
234
//inline bool __is_false(bool b) { return !b; }
235
//
236
//
237
//inline bool __is_false(const enum_boolean & ebit) { return ebit < 0; }
238
//
239
//
240
//inline bool __is_optional(bool b) { return false; }
241
//
242
//
243
//inline bool __is_optional(const ::logic::boolean & boolean) { return boolean.isOptional(); }
244
//
245
//
246
//#define __optional_is_true(flag, option) ((bool)(flag) || (__is_optional(flag) && (option)))
247
248
249
250
inline
bool
is_equivalent(
bool
b1,
bool
b2)
251
{
252
253
return
!!b1 == !!b2;
254
255
}
prototype
logic
boolean.h
Generated by
1.17.0