address.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #pragma once
  2. //
  3. // Copyright (c) 2019-2022 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
  4. //
  5. // Distributed under the MIT Software License
  6. //
  7. #include "arc.hpp"
  8. #include "forward.hpp"
  9. namespace rotor {
  10. /** \struct address_t
  11. * \brief Message subscription and delivery point
  12. *
  13. * Address is an abstraction of "point of service", i.e. any actor can send
  14. * an message to an address, and any actor can subscribe on any address to
  15. * handle certain kind of messages.
  16. *
  17. * An actor has "main" address, and in addition it may have "virtual" private
  18. * addresses to perform routing messages for the specific methods.
  19. *
  20. * Addresses are produced by {@link supervisor_t}, which also is responsible
  21. * for initial delivery of messages on the address. Address lifetime *should*
  22. * be no longer then corresponding supervisor lifetime.
  23. *
  24. * Addresses are non-copyable and non-moveable. The constructor is private
  25. * and it is intended to be created by supervisor only.
  26. *
  27. */
  28. struct address_t : public arc_base_t<address_t> {
  29. /// reference to {@link supervisor_t}, which generated the address
  30. supervisor_t &supervisor;
  31. /** \brief runtime label, describing some execution group */
  32. const void *locality;
  33. address_t(const address_t &) = delete;
  34. address_t(address_t &&) = delete;
  35. /** \brief returns true if two addresses are the same, i.e. are located in the
  36. * same memory region
  37. */
  38. inline bool operator==(const address_t &other) const noexcept { return this == &other; }
  39. /** \brief compares locality fields of the addresses */
  40. inline bool same_locality(const address_t &other) const noexcept { return this->locality == other.locality; }
  41. private:
  42. friend struct supervisor_t;
  43. address_t(supervisor_t &sup, const void *locality_) : supervisor{sup}, locality{locality_} {}
  44. };
  45. /** \brief intrusive pointer for address */
  46. using address_ptr_t = intrusive_ptr_t<address_t>;
  47. } // namespace rotor
  48. namespace std {
  49. /** \struct hash<rotor::address_ptr_t>
  50. * \brief Hash calculator for address
  51. */
  52. template <> struct hash<rotor::address_ptr_t> {
  53. /** \brief Calculates hash for the address */
  54. inline size_t operator()(const rotor::address_ptr_t &address) const noexcept {
  55. return reinterpret_cast<size_t>(address.get());
  56. }
  57. };
  58. } // namespace std