Home | History | Annotate | Download | only in ports
      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 
      5 #ifndef MOJO_EDK_SYSTEM_PORTS_NAME_H_
      6 #define MOJO_EDK_SYSTEM_PORTS_NAME_H_
      7 
      8 #include <stdint.h>
      9 
     10 #include <ostream>
     11 #include <tuple>
     12 
     13 #include "base/hash.h"
     14 
     15 namespace mojo {
     16 namespace edk {
     17 namespace ports {
     18 
     19 struct Name {
     20   Name(uint64_t v1, uint64_t v2) : v1(v1), v2(v2) {}
     21   uint64_t v1, v2;
     22 };
     23 
     24 inline bool operator==(const Name& a, const Name& b) {
     25   return a.v1 == b.v1 && a.v2 == b.v2;
     26 }
     27 
     28 inline bool operator!=(const Name& a, const Name& b) {
     29   return !(a == b);
     30 }
     31 
     32 inline bool operator<(const Name& a, const Name& b) {
     33   return std::tie(a.v1, a.v2) < std::tie(b.v1, b.v2);
     34 }
     35 
     36 std::ostream& operator<<(std::ostream& stream, const Name& name);
     37 
     38 struct PortName : Name {
     39   PortName() : Name(0, 0) {}
     40   PortName(uint64_t v1, uint64_t v2) : Name(v1, v2) {}
     41 };
     42 
     43 extern const PortName kInvalidPortName;
     44 
     45 struct NodeName : Name {
     46   NodeName() : Name(0, 0) {}
     47   NodeName(uint64_t v1, uint64_t v2) : Name(v1, v2) {}
     48 };
     49 
     50 extern const NodeName kInvalidNodeName;
     51 
     52 }  // namespace ports
     53 }  // namespace edk
     54 }  // namespace mojo
     55 
     56 namespace std {
     57 
     58 template <>
     59 struct hash<mojo::edk::ports::PortName> {
     60   std::size_t operator()(const mojo::edk::ports::PortName& name) const {
     61     return base::HashInts64(name.v1, name.v2);
     62   }
     63 };
     64 
     65 template <>
     66 struct hash<mojo::edk::ports::NodeName> {
     67   std::size_t operator()(const mojo::edk::ports::NodeName& name) const {
     68     return base::HashInts64(name.v1, name.v2);
     69   }
     70 };
     71 
     72 }  // namespace std
     73 
     74 #endif  // MOJO_EDK_SYSTEM_PORTS_NAME_H_
     75