acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
enumeration.h
1// Refactored by camilo on 2026-05-30 03:10 <3ThomasBorregaardSørensen!! Mummi!! Bilbo!!
2#pragma once
3
4
5struct hash32;
6
7
8template < typename INTEGRAL >
9concept prototype_integral = std::is_integral_v < ::decay < INTEGRAL > >;
10
11
12template < typename CFLAG >
13class c_flag
14{
15public:
16
17
18 using CFLAG_TYPE_TAG = c_flag_type_t;
19
20 using CFLAG_TYPE = CFLAG;
21
22 using CFLAG_INT = std::underlying_type_t<CFLAG_TYPE>;
23
24
25 CFLAG m_cflag;
26
27
28 constexpr c_flag() { m_cflag = (CFLAG) 0; }
29 constexpr c_flag(const ::std::initializer_list < CFLAG > & list_base )
30 {
31
32 m_cflag = (CFLAG) 0;
33
34 for (auto & e : list_base)
35 {
36
37 add(e);
38
39 }
40
41 }
42 template < typename THE_CFLAG >
43 constexpr c_flag(THE_CFLAG e)
44 requires (::std::is_same_v < THE_CFLAG, CFLAG >
46 { m_cflag = (CFLAG) e; }
47 //template < prototype_integral INTEGRAL >
48 //c_flag(INTEGRAL i) { m_cflag = (CFLAG) i; }
49 constexpr c_flag(const c_flag & e) { m_cflag = e.m_cflag; }
50
51 //constexpr void add(const c_flag & e) { m_cflag = e | m_cflag; }
52
53 constexpr c_flag & operator |= (const c_flag & e) { m_cflag = (CFLAG) ((CFLAG_INT)e.m_cflag | (CFLAG_INT)m_cflag); return *this; }
54 constexpr c_flag & operator &= (const c_flag & e) { m_cflag = (CFLAG) ((CFLAG_INT)m_cflag & (CFLAG_INT)e.m_cflag); return *this; }
55
56 constexpr c_flag & operator += (const c_flag & e) { return operator |= (e); }
57 constexpr c_flag & operator -= (const c_flag & e) { return operator &= (~e); }
58
59 constexpr c_flag & operator ^= (const c_flag & e) { toggle(e); return *this; }
60
61// inline c_flag operator + (CFLAG e) const { return (CFLAG)(m_cflag | e); }
62 constexpr CFLAG operator - (const c_flag & e) const { return m_cflag & ~e; }
63
64 //template < typename TYPE >
65 //c_flag operator + (const TYPE & t) const { auto copy = *this; copy.add(t); return copy; }
66
67 //IMPL_OPERATOR_PLUS(c_flag);
68
69 template < typename TYPE > \
70 CFLAG operator + (const TYPE & t) const
71 {
72 auto copy = *this;
73 copy.add(t);
74 return copy;
75 }
76
77 constexpr CFLAG operator | (const c_flag & e) const { return (CFLAG) ((CFLAG_INT) m_cflag | (CFLAG_INT) e.m_cflag); }
78 constexpr CFLAG operator & (const c_flag & e) const { return (CFLAG) ((CFLAG_INT) m_cflag & (CFLAG_INT) e.m_cflag); }
79
80 constexpr CFLAG operator | (const CFLAG & e) const { return (CFLAG) ((CFLAG_INT) m_cflag | (CFLAG_INT) e); }
81 constexpr CFLAG operator & (const CFLAG & e) const { return (CFLAG) ((CFLAG_INT) m_cflag & (CFLAG_INT) e); }
82
83 constexpr bool is(const c_flag & e) const { return (m_cflag & e) == e; }
84 constexpr bool has(c_flag e) const { return is(e); }
85 constexpr bool is_clear(const c_flag & e) const { return !(m_cflag & e); }
86 constexpr bool is_null() const { return m_cflag == (CFLAG)0; }
87 constexpr bool is_set() const { return !is_null(); }
88
89 constexpr void erase(const c_flag & e) { operator -= (e); }
90 constexpr void add(const c_flag & e) { operator += (e); }
91 constexpr void unset(const c_flag & e) { erase(e); }
92 constexpr void set(const c_flag & e) { add(e); }
93 constexpr void clear() { m_cflag = (CFLAG) 0; }
94
95 constexpr void set(const c_flag & e, bool bSet) { if(bSet) set(e); else unset(e); }
96 constexpr void toggle(const c_flag & e) { if (is(e)) unset(e); else set(e); }
97
98 constexpr c_flag & operator = (const c_flag & e) { m_cflag = e.m_cflag; return *this; }
99
100
101 constexpr bool operator == (const c_flag & e) const { return m_cflag == e.m_cflag; }
102
103
104 constexpr CFLAG & eflag() { return (CFLAG &)m_cflag; }
105 constexpr CFLAG eflag() const { return (CFLAG)m_cflag; }
106
107 constexpr bool operator !()
108 {
109
110 return !((CFLAG)m_cflag);
111
112 }
113
114 constexpr explicit operator bool() const {
115 return this->is_set();
116 }
117
118 constexpr explicit operator ::i64() const {
119 return (::i64)m_cflag;
120 }
121
122 constexpr explicit operator ::i32() const {
123 return (::i32)m_cflag;
124 }
125
126 constexpr explicit operator ::u64() const {
127 return (::u64)m_cflag;
128 }
129
130 constexpr explicit operator ::u32() const {
131 return (::u32)m_cflag;
132 }
133 constexpr explicit operator ::hash32() const;
134
135
136 constexpr explicit operator ::i16() const {
137 return (::i64)m_cflag;
138 }
139
140 constexpr explicit operator ::i8() const {
141 return (::i32)m_cflag;
142 }
143
144 constexpr explicit operator ::u16() const {
145 return (::u16)m_cflag;
146 }
147
148 constexpr explicit operator ::u8() const {
149 return (::u32)m_cflag;
150 }
151
152 // constexpr operator CFLAG & ()
153 // {
154 // return (CFLAG &)m_cflag;
155 // }
156 //
157 // constexpr operator CFLAG() const
158 // {
159 //
160 // return (CFLAG)m_cflag;
161 // }
162
163
164 constexpr CFLAG operator ~() const
165 {
166
167 return (CFLAG)(~(CFLAG_INT) m_cflag);
168
169
170 }
171
172
173 constexpr c_flag & operator ++(::i32)
174 {
175
176 m_cflag = (CFLAG)((CFLAG_INT) m_cflag + 1);
177
178 return *this;
179
180 }
181
182
183 constexpr c_flag & operator %=(const CFLAG & eenum)
184 {
185
186 m_cflag = (CFLAG)((CFLAG_INT) m_cflag % (CFLAG_INT) eenum);
187
188 return *this;
189
190 }
191
192 constexpr c_flag& rotate(const CFLAG& eenum)
193 {
194
195 if ((CFLAG_INT) m_cflag < 0)
196 {
197
198 m_cflag = (CFLAG) 0;
199
200 }
201
202 this->operator ++(0);
203
204 return this->operator %=(eenum);
205
206 }
207
208 constexpr ::std::strong_ordering operator<=>(const c_flag & e) const
209 {
210 return (CFLAG_INT)m_cflag <=> (CFLAG_INT) e.m_cflag;
211 }
212
213
214};
215
216
217template < typename ENUM >
218class enumeration
219{
220public:
221
222
223 using ENUM_TYPE_TAG = enum_type_t;
224
225 using ENUM_TYPE = ENUM;
226
227 using ENUM_INT = std::underlying_type_t<ENUM_TYPE>;
228
229
230 ENUM m_eenum;
231
232
233 constexpr enumeration() { m_eenum = (ENUM) 0; }
234 constexpr enumeration(const ::std::initializer_list < ENUM > & list_base )
235 {
236
237 m_eenum = (ENUM) 0;
238
239 for (auto & e : list_base)
240 {
241
242 add(e);
243
244 }
245
246 }
247 template < typename THE_ENUM >
248 constexpr enumeration(THE_ENUM e)
249 requires (::std::is_same_v < THE_ENUM, ENUM >
251 { m_eenum = (ENUM) e; }
252 //template < prototype_integral INTEGRAL >
253 //enumeration(INTEGRAL i) { m_eenum = (ENUM) i; }
254 constexpr enumeration(const enumeration & e) { m_eenum = e.m_eenum; }
255
256// constexpr void add(ENUM e) { m_eenum = (ENUM)(e | m_eenum); }
257//
258// constexpr enumeration & operator |= (ENUM e) { add(e); return *this; }
259// constexpr enumeration & operator &= (ENUM e) { m_eenum = (ENUM) (m_eenum & e); return *this; }
260//
261// constexpr enumeration & operator |= (const enumeration & e) { m_eenum = (ENUM) (e.m_eenum | m_eenum); return *this; }
262// constexpr enumeration & operator &= (const enumeration & e) { m_eenum = (ENUM) (m_eenum & e.m_eenum); return *this; }
263//
264// constexpr enumeration & operator += (ENUM e) { return operator |= (e); }
265// constexpr enumeration & operator -= (ENUM e) { return operator &= ((ENUM)~(::i64)(e)); }
266//
267// constexpr enumeration & operator += (const enumeration & e) { return operator |= ((ENUM)e.m_eenum); }
268// constexpr enumeration & operator -= (const enumeration & e) { return operator &= ((ENUM)~(::i64)(e.m_eenum)); }
269//
270// constexpr enumeration & operator ^= (ENUM e) { toggle(e); return *this; }
271// constexpr enumeration & operator ^= (const enumeration & e) { toggle(e); return *this; }
272//
273// // inline enumeration operator + (ENUM e) const { return (ENUM)(m_eenum | e); }
274// constexpr enumeration operator - (ENUM e) const { return (ENUM)(m_eenum & ~((::i64)e)); }
275
276 //template < typename TYPE >
277 //enumeration operator + (const TYPE & t) const { auto copy = *this; copy.add(t); return copy; }
278
279 //IMPL_OPERATOR_PLUS(enumeration);
280
281 //template < typename TYPE > \
282 //enumeration operator + (const TYPE & t) const
283 //{
284 // auto copy = *this;
285 // copy.add(t);
286 // return copy;
287 //}
288
289 //constexpr enumeration operator | (ENUM e) const { return (ENUM)(m_eenum | e); }
290 //constexpr enumeration operator & (ENUM e) const { return (ENUM)(m_eenum & e); }
291
292 template < prototype_integral INTEGRAL >
293 constexpr enumeration operator + (INTEGRAL i) const { return (ENUM)((::std::underlying_type_t<ENUM>) m_eenum + i); }
294 //constexpr enumeration operator & (const enumeration & e) const { return (ENUM)(m_eenum & e.m_eenum); }
295
296 constexpr bool is(ENUM e) const { return m_eenum == e; }
297 //constexpr bool has(ENUM e) const { return is(e); }
298 //constexpr bool is_clear(ENUM e) const { return !(m_eenum & e); }
299 constexpr bool is_null() const { return !is_set(); }
300 constexpr bool is_set() const { return !is_set(); }
301
302 //constexpr void erase(ENUM e) { operator -= (e); }
303 //constexpr void add(const enumeration & e) { operator += (e); }
304 //constexpr void unset(const enumeration & e) { erase(e); }
305 constexpr void set(const enumeration & e) { m_eenum = e; }
306 //constexpr void erase(const enumeration & e) { operator -= (e); }
307 constexpr void clear() { m_eenum = (ENUM) 0; }
308
309 // constexpr void set(ENUM e, bool bSet) { if(bSet) set(e); else unset(e); }
310 // constexpr void toggle(ENUM e) { if (is(e)) unset(e); else set(e); }
311
312 constexpr enumeration & operator = (const enumeration & e) { m_eenum = e.m_eenum; return *this; }
313
314
315 constexpr bool operator == (const enumeration & e) const { return m_eenum == e.m_eenum; }
316 //constexpr bool operator == (ENUM e) const { return m_eenum == e; }
317
318
319 constexpr ENUM & eflag() { return (ENUM &)m_eenum; }
320 constexpr ENUM eflag() const { return (ENUM)m_eenum; }
321
322 constexpr bool operator !()
323 {
324
325 return !((ENUM)m_eenum);
326
327 }
328
329
330
331 constexpr explicit operator bool() const {
332 return this->is_set();
333 }
334
335 constexpr explicit operator ::i64() const {
336 return (::i64)m_eenum;
337 }
338
339 constexpr explicit operator ::i32() const {
340 return (::i32)m_eenum;
341 }
342
343 constexpr explicit operator ::u64() const {
344 return (::u64)m_eenum;
345 }
346
347 constexpr explicit operator ::u32() const {
348 return (::u32)m_eenum;
349 }
350
351 constexpr explicit operator ::hash32() const;
352
353 constexpr explicit operator ::i16() const {
354 return (::i64)m_eenum;
355 }
356
357 constexpr explicit operator ::i8() const {
358 return (::i32)m_eenum;
359 }
360
361 constexpr explicit operator ::u16() const {
362 return (::u16)m_eenum;
363 }
364
365 constexpr explicit operator ::u8() const {
366 return (::u32)m_eenum;
367 }
368
369
370 //constexpr operator ENUM & ()
371 //{
372 // return (ENUM &)m_eenum;
373 //}
374
375 // constexpr operator ENUM() const
376 // {
377 //
378 // return (ENUM)m_eenum;
379 // }
380
381
382 enumeration & operator ++(::i32)
383 {
384
385 m_eenum = (ENUM)((ENUM_INT) m_eenum + 1);
386
387 return *this;
388
389 }
390
391
392 enumeration & operator %=(const enumeration & eenum)
393 {
394
395 m_eenum = (ENUM)((ENUM_INT) m_eenum % (ENUM_INT) eenum.m_eenum);
396
397 return *this;
398
399 }
400
401 enumeration& modulus(const enumeration & eenumMin, const enumeration & eenumMax)
402 {
403
404 m_eenum = (ENUM) ((ENUM_INT) eenumMin.m_eenum + ((m_eenum - eenumMin) % (eenumMax - eenumMin)));
405 return *this;
406 }
407
408 enumeration& rotate(const enumeration & eenumMin, const enumeration & eenumMax)
409 {
410 operator++(0);
411 return modulus(eenumMin, eenumMax);
412
413 }
414
415 enumeration& rotate(const enumeration & eenumMax)
416 {
417 return rotate((ENUM) 0, eenumMax);
418
419 }
420
421 constexpr ENUM_INT operator-(const enumeration & e) const
422 {
423
424 return (ENUM_INT)m_eenum - (ENUM_INT) e.m_eenum;
425
426 }
427
428 constexpr ::std::strong_ordering operator<=>(const enumeration & e) const
429 {
430
431 return (ENUM_INT)m_eenum <=> (ENUM_INT) e.m_eenum;
432
433 }
434
435};
436
437
438#define DECLARE_C_FLAG(TYPE, CFLAG) \
439using TYPE = ::c_flag < CFLAG >; \
440constexpr CFLAG operator | (CFLAG e, CFLAG f) { return (CFLAG) ((::std::underlying_type_t<CFLAG>)e | (::std::underlying_type_t<CFLAG>)f); } \
441inline CFLAG & operator|=(CFLAG & e, CFLAG f) { return e= (CFLAG)((::std::underlying_type_t<CFLAG>)e | (::std::underlying_type_t<CFLAG>)f); } \
442constexpr CFLAG operator | (CFLAG e, const TYPE & f) { return (CFLAG) ((::std::underlying_type_t<CFLAG>)e | (::std::underlying_type_t<CFLAG>)f.m_cflag); } \
443template < prototype_integral INTEGRAL > \
444constexpr CFLAG operator | (CFLAG e, INTEGRAL i) { return (CFLAG) ((::std::underlying_type_t<CFLAG>)e | (::std::underlying_type_t<CFLAG>)i); } \
445template < prototype_integral INTEGRAL > \
446constexpr CFLAG operator | (INTEGRAL i, const TYPE & e) { return (CFLAG) ((::std::underlying_type_t<CFLAG>)i | (::std::underlying_type_t<CFLAG>)e.m_cflag); } \
447 constexpr CFLAG operator & (CFLAG e, CFLAG f) { return (CFLAG) ((::std::underlying_type_t<CFLAG>)e & (::std::underlying_type_t<CFLAG>)f); } \
448inline CFLAG &operator&=(CFLAG &e, CFLAG f) \
449 { \
450 return e = (CFLAG)((::std::underlying_type_t<CFLAG>)e & (::std::underlying_type_t<CFLAG>)f); \
451 } \
452constexpr CFLAG operator & (CFLAG e, const TYPE & f) { return (CFLAG) ((::std::underlying_type_t<CFLAG>)e & (::std::underlying_type_t<CFLAG>)f.m_cflag); } \
453template < prototype_integral INTEGRAL > \
454constexpr CFLAG operator & (CFLAG e, INTEGRAL i) { return (CFLAG) ((::std::underlying_type_t<CFLAG>)e & (::std::underlying_type_t<CFLAG>)i); } \
455template < prototype_integral INTEGRAL > \
456constexpr CFLAG operator & (INTEGRAL i, const TYPE & e) { return (CFLAG) ((::std::underlying_type_t<CFLAG>)i & (::std::underlying_type_t<CFLAG>)e.m_cflag); } \
457constexpr CFLAG operator ~ (CFLAG e) { return (CFLAG) (~(::std::underlying_type_t<CFLAG>)e); } \
458constexpr CFLAG operator-(CFLAG e, CFLAG f) \
459{ \
460 return (CFLAG)((::std::underlying_type_t<CFLAG>)e & ~(::std::underlying_type_t<CFLAG>)f); \
461} \
462inline CFLAG &operator-=(CFLAG &e, CFLAG f) \
463{ \
464 return e = (CFLAG)((::std::underlying_type_t<CFLAG>)e & ~(::std::underlying_type_t<CFLAG>)f); \
465}
466
467
468
469
470
471
472#define DECLARE_ENUMERATION(ENUMERATION, ENUM) \
473using ENUMERATION = ::enumeration < ENUM >; \
474template < prototype_integral INTEGRAL > \
475constexpr ENUMERATION operator + (ENUM e, INTEGRAL i) { return (ENUM) ((::std::underlying_type_t<ENUM>)e + (::std::underlying_type_t<ENUM>)i); } \
476constexpr auto operator - (ENUM e, ENUM f) { return ((::std::underlying_type_t<ENUM>)e - (::std::underlying_type_t<ENUM>)f); } \
477constexpr auto operator - (ENUM e, const ENUMERATION & f) { return ((::std::underlying_type_t<ENUM>)e - (::std::underlying_type_t<ENUM>)f.m_eenum); } \
478template < prototype_integral INTEGRAL > \
479constexpr ENUMERATION operator - (ENUM e, INTEGRAL i) { return (ENUM) ((::std::underlying_type_t<ENUM>)e & (::std::underlying_type_t<ENUM>)i); } \
480
481
482
483//constexpr ENUM operator + (ENUM e, ENUM f) { return (ENUM) ((::std::underlying_type_t<CFLAG>)e + (::std::underlying_type_t<CFLAG>)f); }
484//template < prototype_integral INTEGRAL >
485//constexpr ENUM operator + (INTEGRAL i, ENUM e) { return (ENUM) ((::std::underlying_type_t<CFLAG>)i | (::std::underlying_type_t<CFLAG>)e); }
486//constexpr ENUM operator - (ENUM e, ENUM f) { return (ENUM) ((::std::underlying_type_t<CFLAG>)e & (::std::underlying_type_t<CFLAG>)f); }
487//template < prototype_integral INTEGRAL >
488//constexpr ENUM operator - (INTEGRAL i, ENUM e) { return (ENUM) ((::std::underlying_type_t<CFLAG>)i & (::std::underlying_type_t<CFLAG>)e); }
Definition list.h:33
Definition enumeration.h:9
Definition _structures.h:22
Definition _structures.h:23
Definition hash32.h:14