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_SOURCE_DIR_H_ | 5 #ifndef TOOLS_GN_SOURCE_DIR_H_ |
6 #define TOOLS_GN_SOURCE_DIR_H_ | 6 #define TOOLS_GN_SOURCE_DIR_H_ |
7 | 7 |
| 8 #include <algorithm> |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
14 | 15 |
15 class SourceFile; | 16 class SourceFile; |
16 | 17 |
17 // Represents a directory within the source tree. Source dirs begin and end in | 18 // Represents a directory within the source tree. Source dirs begin and end in |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 bool operator==(const SourceDir& other) const { | 79 bool operator==(const SourceDir& other) const { |
79 return value_ == other.value_; | 80 return value_ == other.value_; |
80 } | 81 } |
81 bool operator!=(const SourceDir& other) const { | 82 bool operator!=(const SourceDir& other) const { |
82 return !operator==(other); | 83 return !operator==(other); |
83 } | 84 } |
84 bool operator<(const SourceDir& other) const { | 85 bool operator<(const SourceDir& other) const { |
85 return value_ < other.value_; | 86 return value_ < other.value_; |
86 } | 87 } |
87 | 88 |
| 89 void swap(SourceDir& other) { |
| 90 std::swap(value_, other.value_); |
| 91 } |
| 92 |
88 private: | 93 private: |
89 friend class SourceFile; | 94 friend class SourceFile; |
90 std::string value_; | 95 std::string value_; |
91 | 96 |
92 // Copy & assign supported. | 97 // Copy & assign supported. |
93 }; | 98 }; |
94 | 99 |
95 namespace BASE_HASH_NAMESPACE { | 100 namespace BASE_HASH_NAMESPACE { |
96 | 101 |
97 #if defined(COMPILER_GCC) | 102 #if defined(COMPILER_GCC) |
98 template<> struct hash<SourceDir> { | 103 template<> struct hash<SourceDir> { |
99 std::size_t operator()(const SourceDir& v) const { | 104 std::size_t operator()(const SourceDir& v) const { |
100 hash<std::string> h; | 105 hash<std::string> h; |
101 return h(v.value()); | 106 return h(v.value()); |
102 } | 107 } |
103 }; | 108 }; |
104 #elif defined(COMPILER_MSVC) | 109 #elif defined(COMPILER_MSVC) |
105 inline size_t hash_value(const SourceDir& v) { | 110 inline size_t hash_value(const SourceDir& v) { |
106 return hash_value(v.value()); | 111 return hash_value(v.value()); |
107 } | 112 } |
108 #endif // COMPILER... | 113 #endif // COMPILER... |
109 | 114 |
110 } // namespace BASE_HASH_NAMESPACE | 115 } // namespace BASE_HASH_NAMESPACE |
111 | 116 |
| 117 namespace std { |
| 118 |
| 119 template<> inline void swap(SourceDir& lhs, SourceDir& rhs) { |
| 120 lhs.swap(rhs); |
| 121 } |
| 122 |
| 123 } // namespace std |
| 124 |
112 #endif // TOOLS_GN_SOURCE_DIR_H_ | 125 #endif // TOOLS_GN_SOURCE_DIR_H_ |
OLD | NEW |