name.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef MOJO_CORE_PORTS_NAME_H_
  5. #define MOJO_CORE_PORTS_NAME_H_
  6. #include <stdint.h>
  7. #include <ostream>
  8. #include <tuple>
  9. #include "base/component_export.h"
  10. #include "base/hash/hash.h"
  11. namespace mojo {
  12. namespace core {
  13. namespace ports {
  14. struct COMPONENT_EXPORT(MOJO_CORE_PORTS) Name {
  15. Name(uint64_t v1, uint64_t v2) : v1(v1), v2(v2) {}
  16. uint64_t v1, v2;
  17. };
  18. inline bool operator==(const Name& a, const Name& b) {
  19. return a.v1 == b.v1 && a.v2 == b.v2;
  20. }
  21. inline bool operator!=(const Name& a, const Name& b) {
  22. return !(a == b);
  23. }
  24. inline bool operator<(const Name& a, const Name& b) {
  25. return std::tie(a.v1, a.v2) < std::tie(b.v1, b.v2);
  26. }
  27. COMPONENT_EXPORT(MOJO_CORE_PORTS)
  28. std::ostream& operator<<(std::ostream& stream, const Name& name);
  29. struct COMPONENT_EXPORT(MOJO_CORE_PORTS) PortName : Name {
  30. PortName() : Name(0, 0) {}
  31. PortName(uint64_t v1, uint64_t v2) : Name(v1, v2) {}
  32. };
  33. extern COMPONENT_EXPORT(MOJO_CORE_PORTS) const PortName kInvalidPortName;
  34. struct COMPONENT_EXPORT(MOJO_CORE_PORTS) NodeName : Name {
  35. NodeName() : Name(0, 0) {}
  36. NodeName(uint64_t v1, uint64_t v2) : Name(v1, v2) {}
  37. };
  38. extern COMPONENT_EXPORT(MOJO_CORE_PORTS) const NodeName kInvalidNodeName;
  39. } // namespace ports
  40. } // namespace core
  41. } // namespace mojo
  42. namespace std {
  43. template <>
  44. struct COMPONENT_EXPORT(MOJO_CORE_PORTS) hash<mojo::core::ports::PortName> {
  45. std::size_t operator()(const mojo::core::ports::PortName& name) const {
  46. return base::HashInts64(name.v1, name.v2);
  47. }
  48. };
  49. template <>
  50. struct COMPONENT_EXPORT(MOJO_CORE_PORTS) hash<mojo::core::ports::NodeName> {
  51. std::size_t operator()(const mojo::core::ports::NodeName& name) const {
  52. return base::HashInts64(name.v1, name.v2);
  53. }
  54. };
  55. } // namespace std
  56. #endif // MOJO_CORE_PORTS_NAME_H_