nany
clid.hxx
1 #pragma once
2 #include "clid.h"
3 #include <iosfwd>
4 
5 
6 namespace ny {
7 
8 
9 inline CLID CLID::AtomMapID(uint32_t atomid) {
10  assert(atomid != 0);
11  return CLID{atomid, 0};
12 }
13 
14 
15 inline CLID::CLID(uint32_t atomid, uint32_t lvid)
16  : m_data{{atomid, lvid}} {
17  assert(lvid < 1000000); // arbitrary integrity check
18 }
19 
20 
21 inline bool CLID::isVoid() const {
22  return !m_data.u64;
23 }
24 
25 
26 inline void CLID::reclass(uint32_t lvid) {
27  assert(lvid < 1000000); // arbitrary integrity check
28  m_data.u32[1] = lvid;
29 }
30 
31 
32 inline void CLID::reclass(uint32_t atomid, uint32_t lvid) {
33  assert(lvid < 1000000); // arbitrary integrity check
34  m_data.u32[0] = atomid;
35  m_data.u32[1] = lvid;
36 }
37 
38 
39 inline void CLID::reclassToVoid() {
40  m_data.u64 = 0;
41 }
42 
43 
44 inline bool CLID::operator == (const CLID& rhs) const {
45  return m_data.u64 == rhs.m_data.u64;
46 }
47 
48 
49 inline bool CLID::operator != (const CLID& rhs) const {
50  return m_data.u64 != rhs.m_data.u64;
51 }
52 
53 
54 inline bool CLID::operator < (const CLID& rhs) const {
55  return m_data.u64 < rhs.m_data.u64;
56 }
57 
58 
59 inline size_t CLID::hash() const {
60  return std::hash<uint64_t>()(m_data.u64);
61 }
62 
63 
64 inline uint32_t CLID::atomid() const {
65  return m_data.u32[0];
66 }
67 
68 
69 inline uint32_t CLID::lvid() const {
70  return m_data.u32[1];
71 }
72 
73 
74 } // namespace ny
75 
76 
77 namespace std {
78 
79 
80 template<> struct hash<ny::CLID> final {
81  inline size_t operator() (const ny::CLID& clid) const {
82  return clid.hash();
83  }
84 };
85 
86 
87 } // namespace std
88 
89 
90 namespace Yuni {
91 namespace Extension {
92 namespace CString {
93 
94 
95 template<class CStringT>
96 class Append<CStringT, ny::CLID> final {
97 public:
98  static void Perform(CStringT& string, const ny::CLID& rhs) {
99  string << '{' << rhs.atomid() << ':' << rhs.lvid() << '}';
100  }
101 };
102 
103 
104 } // namespace CString
105 } // namespace Extension
106 } // namespace Yuni
size_t hash() const
hash of the clid
Definition: clid.hxx:59
uint32_t atomid() const
Get the atom id of the clid.
Definition: clid.hxx:64
Definition: signature.cpp:9
Definition: clid.h:11
static CLID AtomMapID(uint32_t atomid)
Create a CLID for an atom id.
Definition: clid.hxx:9
bool isVoid() const
Get if the clid is valid (aka != 0)
Definition: clid.hxx:21
Definition: signature.hxx:53
Definition: ast.cpp:6
CLID()=default
Default constructor.
bool operator!=(const CLID &) const
Not equal operator.
Definition: clid.hxx:49
bool operator==(const CLID &) const
Equal operator.
Definition: clid.hxx:44
void reclass(uint32_t lvid)
update the class id from lvid only
Definition: clid.hxx:26
void reclassToVoid()
update to &#39;void&#39;
Definition: clid.hxx:39
bool operator<(const CLID &) const
Comparison operator.
Definition: clid.hxx:54
uint32_t lvid() const
Get the lvid part.
Definition: clid.hxx:69