-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtrunknode.h
More file actions
58 lines (47 loc) · 1.66 KB
/
trunknode.h
File metadata and controls
58 lines (47 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef __TRUNKNODE_H
#define __TRUNKNODE_H
#include <inttypes.h>
class trunk_t {
size_t t_;
public:
explicit trunk_t(size_t t) : t_(t) { assert(t < 256); }
template <class T> trunk_t(T) = delete;
bool operator< (trunk_t const o) const { return t_ < o.t_; }
bool operator== (trunk_t const o) const { return t_ == o.t_; }
bool operator!= (trunk_t const o) const { return t_ != o.t_; }
uint8_t raw() const { return t_; }
};
class node_t {
size_t n_;
public:
explicit node_t(size_t n) : n_(n) { assert(n < 256); }
template <class T> node_t(T) = delete;
bool operator< (node_t const o) const { return n_ < o.n_; }
bool operator== (node_t const o) const { return n_ == o.n_; }
bool operator!= (node_t const o) const { return n_ != o.n_; }
uint8_t raw() const { return n_; }
};
class trunknode_t {
size_t tn;
public:
trunknode_t() : tn(0) {}
trunknode_t(trunk_t const t, node_t const n) :
tn((uint16_t(t.raw()) << 8) | uint16_t(n.raw())) {}
trunknode_t(trunknode_t const &obj) : tn(obj.tn) {}
trunknode_t& operator=(trunknode_t const& that) { // Added by JD
this->tn = that.tn;
return *this;
}
explicit trunknode_t(uint16_t const addr) : tn(addr) {}
bool operator< (trunknode_t const o) const { return tn < o.tn; }
bool operator== (trunknode_t const o) const { return tn == o.tn; }
bool operator!= (trunknode_t const o) const { return tn != o.tn; }
bool isBlank() const { return tn == 0; }
trunk_t trunk() const { return trunk_t(tn >> 8); }
node_t node() const { return node_t(tn & 0xff); }
uint16_t raw() const { return tn; }
};
// Local Variables:
// mode:c++
// End:
#endif