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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 bool operator==(const SourceDir& other) const { | 84 bool operator==(const SourceDir& other) const { |
84 return value_ == other.value_; | 85 return value_ == other.value_; |
85 } | 86 } |
86 bool operator!=(const SourceDir& other) const { | 87 bool operator!=(const SourceDir& other) const { |
87 return !operator==(other); | 88 return !operator==(other); |
88 } | 89 } |
89 bool operator<(const SourceDir& other) const { | 90 bool operator<(const SourceDir& other) const { |
90 return value_ < other.value_; | 91 return value_ < other.value_; |
91 } | 92 } |
92 | 93 |
| 94 void swap(SourceDir& other) { |
| 95 value_.swap(other.value_); |
| 96 } |
| 97 |
93 private: | 98 private: |
94 friend class SourceFile; | 99 friend class SourceFile; |
95 std::string value_; | 100 std::string value_; |
96 | 101 |
97 // Copy & assign supported. | 102 // Copy & assign supported. |
98 }; | 103 }; |
99 | 104 |
100 namespace BASE_HASH_NAMESPACE { | 105 namespace BASE_HASH_NAMESPACE { |
101 | 106 |
102 #if defined(COMPILER_GCC) | 107 #if defined(COMPILER_GCC) |
103 template<> struct hash<SourceDir> { | 108 template<> struct hash<SourceDir> { |
104 std::size_t operator()(const SourceDir& v) const { | 109 std::size_t operator()(const SourceDir& v) const { |
105 hash<std::string> h; | 110 hash<std::string> h; |
106 return h(v.value()); | 111 return h(v.value()); |
107 } | 112 } |
108 }; | 113 }; |
109 #elif defined(COMPILER_MSVC) | 114 #elif defined(COMPILER_MSVC) |
110 inline size_t hash_value(const SourceDir& v) { | 115 inline size_t hash_value(const SourceDir& v) { |
111 return hash_value(v.value()); | 116 return hash_value(v.value()); |
112 } | 117 } |
113 #endif // COMPILER... | 118 #endif // COMPILER... |
114 | 119 |
115 } // namespace BASE_HASH_NAMESPACE | 120 } // namespace BASE_HASH_NAMESPACE |
116 | 121 |
| 122 inline void swap(SourceDir& lhs, SourceDir& rhs) { |
| 123 lhs.swap(rhs); |
| 124 } |
| 125 |
117 #endif // TOOLS_GN_SOURCE_DIR_H_ | 126 #endif // TOOLS_GN_SOURCE_DIR_H_ |
OLD | NEW |