OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 TOOLS_GN_LABEL_PTR_H_ | 5 #ifndef TOOLS_GN_LABEL_PTR_H_ |
6 #define TOOLS_GN_LABEL_PTR_H_ | 6 #define TOOLS_GN_LABEL_PTR_H_ |
7 | 7 |
8 #include <functional> | 8 #include <functional> |
9 | 9 |
| 10 #include "tools/gn/label.h" |
| 11 |
| 12 class Config; |
10 class ParseNode; | 13 class ParseNode; |
| 14 class Target; |
11 | 15 |
12 // Structure that holds a labeled "thing". This is used for various places | 16 // Structure that holds a labeled "thing". This is used for various places |
13 // where we need to store lists of targets or configs. We sometimes populate | 17 // where we need to store lists of targets or configs. We sometimes populate |
14 // the pointers on another thread from where we compute the labels, so this | 18 // the pointers on another thread from where we compute the labels, so this |
15 // structure lets us save them separately. This also allows us to store the | 19 // structure lets us save them separately. This also allows us to store the |
16 // location of the thing that added this dependency. | 20 // location of the thing that added this dependency. |
17 template<typename T> | 21 template<typename T> |
18 struct LabelPtrPair { | 22 struct LabelPtrPair { |
19 typedef T DestType; | 23 typedef T DestType; |
20 | 24 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 // std::sort(vect.begin(), vect.end(), LabelPtrLabelLess<Config>()); | 77 // std::sort(vect.begin(), vect.end(), LabelPtrLabelLess<Config>()); |
74 template<typename T> | 78 template<typename T> |
75 struct LabelPtrLabelLess : public std::binary_function<LabelPtrPair<T>, | 79 struct LabelPtrLabelLess : public std::binary_function<LabelPtrPair<T>, |
76 LabelPtrPair<T>, | 80 LabelPtrPair<T>, |
77 bool> { | 81 bool> { |
78 bool operator()(const LabelPtrPair<T>& a, const LabelPtrPair<T>& b) const { | 82 bool operator()(const LabelPtrPair<T>& a, const LabelPtrPair<T>& b) const { |
79 return a.label < b.label; | 83 return a.label < b.label; |
80 } | 84 } |
81 }; | 85 }; |
82 | 86 |
| 87 // Default comparison operators ----------------------------------------------- |
| 88 // |
| 89 // The default hash and comparison operators operate on the label, which should |
| 90 // always be valid, whereas the pointer is sometimes null. |
| 91 |
| 92 template<typename T> inline bool operator==(const LabelPtrPair<T>& a, |
| 93 const LabelPtrPair<T>& b) { |
| 94 return a.label == b.label; |
| 95 } |
| 96 |
| 97 template<typename T> inline bool operator<(const LabelPtrPair<T>& a, |
| 98 const LabelPtrPair<T>& b) { |
| 99 return a.label < b.label; |
| 100 } |
| 101 |
| 102 namespace BASE_HASH_NAMESPACE { |
| 103 |
| 104 #if defined(COMPILER_GCC) |
| 105 template<typename T> struct hash< LabelPtrPair<T> > { |
| 106 std::size_t operator()(const LabelPtrPair<T>& v) const { |
| 107 BASE_HASH_NAMESPACE::hash<Label> h; |
| 108 return h(v.label); |
| 109 } |
| 110 }; |
| 111 #elif defined(COMPILER_MSVC) |
| 112 template<typename T> |
| 113 inline size_t hash_value(const LabelPtrPair<T>& v) { |
| 114 return BASE_HASH_NAMESPACE::hash_value(v.label); |
| 115 } |
| 116 #endif // COMPILER... |
| 117 |
| 118 } // namespace BASE_HASH_NAMESPACE |
| 119 |
83 #endif // TOOLS_GN_LABEL_PTR_H_ | 120 #endif // TOOLS_GN_LABEL_PTR_H_ |
OLD | NEW |