acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
domain_enumeration.h
1//
2// Created by camilo on 2024-06-12 17:06 <3ThomasBorregaardSorensen!!
3//
4#pragma once
5
6
7template < typename ENUM, enum_domain t_edomain >
8class domain_enumeration
9{
10public:
11
12
13 ENUM m_eenum;
14
15
16 constexpr domain_enumeration() :m_eenum(ENUM(0)){}
17
18
19 constexpr domain_enumeration(ENUM eenum) :m_eenum(eenum){}
20
21
22 constexpr domain_enumeration(const ::domain_id & domainid)
23 {
24
25 if(domainid.m_edomain != t_edomain)
26 {
27
28 m_eenum = (ENUM) 0;
29
30 }
31 else
32 {
33
34 m_eenum = (ENUM) domainid.m_iId;
35
36 }
37
38 }
39
40
41 domain_enumeration(const ::atom & atom)
42 {
43
44 if(atom.get_type() != ::atom::e_type_domainid)
45 {
46
47 m_eenum = (ENUM)0;
48
49 }
50 else
51 {
52
53 this->operator=(atom.as_domainid());
54
55 }
56
57 }
58
59
60 constexpr ::domain_id as_domainid()
61 {
62
63 return {t_edomain, m_eenum};
64
65 }
66
67
68 constexpr domain_enumeration & operator =(const domain_enumeration & domainenumeration)
69 {
70
71 m_eenum = domainenumeration.m_eenum;
72
73 return *this;
74
75 }
76
77
78 constexpr bool operator == (const domain_enumeration & domainenumeration) const
79 {
80
81 return m_eenum == domainenumeration.m_eenum;
82
83 }
84
85
86 constexpr bool is_ok() const { return m_eenum != (ENUM) 0; }
87
88
89 constexpr bool is_nok() const { return !this->is_ok(); }
90
91
92 explicit constexpr operator ::hash32() const { return (::u32) m_eenum; }
93
94
95};
96
97
98#define DECLARE_DOMAIN_ENUMERATION(EENUM, ENUM, EDOMAIN) \
99using EENUM = domain_enumeration<ENUM, EDOMAIN>; \
100inline constexpr ::domain_id as_domainid(const EENUM & eenum) {return {EDOMAIN, (::i32) eenum.m_eenum};}
101
102
103
Definition atom.h:237