Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Side by Side Diff: mojo/edk/system/ports/name.h

Issue 2512753002: Move const PortName data out of header file (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/edk/system/node_controller.cc ('k') | mojo/edk/system/ports/name.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_EDK_SYSTEM_PORTS_NAME_H_ 5 #ifndef MOJO_EDK_SYSTEM_PORTS_NAME_H_
6 #define MOJO_EDK_SYSTEM_PORTS_NAME_H_ 6 #define MOJO_EDK_SYSTEM_PORTS_NAME_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <ostream> 10 #include <ostream>
11 #include <tuple> 11 #include <tuple>
12 12
13 #include "base/hash.h" 13 #include "base/hash.h"
14 14
15 namespace mojo { 15 namespace mojo {
16 namespace edk { 16 namespace edk {
17 namespace ports { 17 namespace ports {
18 18
19 struct Name { 19 struct Name {
20 Name(uint64_t v1, uint64_t v2) : v1(v1), v2(v2) {} 20 constexpr Name(uint64_t v1, uint64_t v2) : v1(v1), v2(v2) {}
21 uint64_t v1, v2; 21 uint64_t v1, v2;
22 }; 22 };
23 23
24 inline bool operator==(const Name& a, const Name& b) { 24 inline bool operator==(const Name& a, const Name& b) {
25 return a.v1 == b.v1 && a.v2 == b.v2; 25 return a.v1 == b.v1 && a.v2 == b.v2;
26 } 26 }
27 27
28 inline bool operator!=(const Name& a, const Name& b) { 28 inline bool operator!=(const Name& a, const Name& b) {
29 return !(a == b); 29 return !(a == b);
30 } 30 }
31 31
32 inline bool operator<(const Name& a, const Name& b) { 32 inline bool operator<(const Name& a, const Name& b) {
33 return std::tie(a.v1, a.v2) < std::tie(b.v1, b.v2); 33 return std::tie(a.v1, a.v2) < std::tie(b.v1, b.v2);
34 } 34 }
35 35
36 std::ostream& operator<<(std::ostream& stream, const Name& name); 36 std::ostream& operator<<(std::ostream& stream, const Name& name);
37 37
38 struct PortName : Name { 38 struct PortName : Name {
39 PortName() : Name(0, 0) {} 39 constexpr PortName() : Name(0, 0) {}
40 PortName(uint64_t v1, uint64_t v2) : Name(v1, v2) {} 40 constexpr PortName(uint64_t v1, uint64_t v2) : Name(v1, v2) {}
41 }; 41 };
42 42
43 const PortName kInvalidPortName = {0, 0};
44
45 struct NodeName : Name { 43 struct NodeName : Name {
46 NodeName() : Name(0, 0) {} 44 constexpr NodeName() : Name(0, 0) {}
47 NodeName(uint64_t v1, uint64_t v2) : Name(v1, v2) {} 45 constexpr NodeName(uint64_t v1, uint64_t v2) : Name(v1, v2) {}
48 }; 46 };
49 47
50 const NodeName kInvalidNodeName = {0, 0}; 48 struct constants {
49 static constexpr PortName kInvalidPortName = {0, 0};
50 static constexpr NodeName kInvalidNodeName = {0, 0};
51 };
51 52
52 } // namespace ports 53 } // namespace ports
53 } // namespace edk 54 } // namespace edk
54 } // namespace mojo 55 } // namespace mojo
55 56
56 namespace std { 57 namespace std {
57 58
58 template <> 59 template <>
59 struct hash<mojo::edk::ports::PortName> { 60 struct hash<mojo::edk::ports::PortName> {
60 std::size_t operator()(const mojo::edk::ports::PortName& name) const { 61 std::size_t operator()(const mojo::edk::ports::PortName& name) const {
61 return base::HashInts64(name.v1, name.v2); 62 return base::HashInts64(name.v1, name.v2);
62 } 63 }
63 }; 64 };
64 65
65 template <> 66 template <>
66 struct hash<mojo::edk::ports::NodeName> { 67 struct hash<mojo::edk::ports::NodeName> {
67 std::size_t operator()(const mojo::edk::ports::NodeName& name) const { 68 std::size_t operator()(const mojo::edk::ports::NodeName& name) const {
68 return base::HashInts64(name.v1, name.v2); 69 return base::HashInts64(name.v1, name.v2);
69 } 70 }
70 }; 71 };
71 72
72 } // namespace std 73 } // namespace std
73 74
74 #endif // MOJO_EDK_SYSTEM_PORTS_NAME_H_ 75 #endif // MOJO_EDK_SYSTEM_PORTS_NAME_H_
OLDNEW
« no previous file with comments | « mojo/edk/system/node_controller.cc ('k') | mojo/edk/system/ports/name.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698