Subordination
A framework for distributed programming
mobile_kernel.hh
1 #ifndef SUBORDINATION_KERNEL_MOBILE_KERNEL_HH
2 #define SUBORDINATION_KERNEL_MOBILE_KERNEL_HH
3 
4 #include <subordination/kernel/kernel_base.hh>
5 #include <subordination/kernel/kernel_header.hh>
6 
7 namespace sbn {
8 
9  class mobile_kernel: public kernel_base, public kernel_header {
10 
11  public:
12  typedef uint64_t id_type;
13 
14  private:
15  id_type _id = no_id();
16 
17  public:
18  virtual void
19  read(sys::pstream& in);
20 
21  virtual void
22  write(sys::pstream& out) const;
23 
24  inline id_type
25  id() const noexcept {
26  return this->_id;
27  }
28 
29  inline void
30  id(id_type rhs) noexcept {
31  this->_id = rhs;
32  }
33 
34  inline bool
35  has_id() const noexcept {
36  return this->_id != no_id();
37  }
38 
39  inline void
40  set_id(id_type rhs) noexcept {
41  this->_id = rhs;
42  }
43 
44  inline bool
45  operator==(const mobile_kernel& rhs) const noexcept {
46  return this == &rhs || (
47  this->id() == rhs.id()
48  && this->has_id()
49  && rhs.has_id()
50  );
51  }
52 
53  inline bool
54  operator!=(const mobile_kernel& rhs) const noexcept {
55  return !this->operator==(rhs);
56  }
57 
58  static constexpr id_type
59  no_id() noexcept {
60  return 0;
61  }
62 
63  inline uint64_t
64  unique_id() const noexcept {
65  return this->has_id() ? this->id() : uint64_t(this);
66  }
67 
68 
69  };
70 
71 }
72 
73 #endif // vim:filetype=cpp
Definition: kernel_base.hh:17
Definition: kernel_header.hh:14
Definition: mobile_kernel.hh:9