| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 14 | 14 |
| 15 class SourceFile; | 15 class SourceFile; |
| 16 | 16 |
| 17 // Represents a directory within the source tree. Source dirs begin and end in | 17 // Represents a directory within the source tree. Source dirs begin and end in |
| 18 // slashes. | 18 // slashes. |
| 19 // | 19 // |
| 20 // If there is one slash at the beginning, it will mean a system-absolute file | 20 // If there is one slash at the beginning, it will mean a system-absolute file |
| 21 // path. On Windows, absolute system paths will be of the form "/C:/foo/bar". | 21 // path. On Windows, absolute system paths will be of the form "/C:/foo/bar". |
| 22 // | 22 // |
| 23 // Two slashes at the beginning indicate a path relative to the source root. | 23 // Two slashes at the beginning indicate a path relative to the source root. |
| 24 class SourceDir { | 24 class SourceDir { |
| 25 public: | 25 public: |
| 26 enum SwapIn { SWAP_IN }; |
| 27 |
| 26 SourceDir(); | 28 SourceDir(); |
| 27 explicit SourceDir(const base::StringPiece& p); | 29 explicit SourceDir(const base::StringPiece& p); |
| 30 // Swaps the given string in without copies. The given string will be empty |
| 31 // after this call. |
| 32 SourceDir(SwapIn, std::string* s); |
| 28 ~SourceDir(); | 33 ~SourceDir(); |
| 29 | 34 |
| 30 // Resolves a file or dir name relative to this source directory. Will return | 35 // Resolves a file or dir name relative to this source directory. Will return |
| 31 // an empty SourceDir/File on error. Empty input is always an error (it's | 36 // an empty SourceDir/File on error. Empty input is always an error (it's |
| 32 // possible we should say ResolveRelativeDir vs. an empty string should be | 37 // possible we should say ResolveRelativeDir vs. an empty string should be |
| 33 // the source dir, but we require "." instead). | 38 // the source dir, but we require "." instead). |
| 34 // | 39 // |
| 35 // If source_root is supplied, these functions will additionally handle the | 40 // If source_root is supplied, these functions will additionally handle the |
| 36 // case where the input is a system-absolute but still inside the source | 41 // case where the input is a system-absolute but still inside the source |
| 37 // tree. This is the case for some external tools. | 42 // tree. This is the case for some external tools. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 66 // them as such). This is normally used when concatenating directories | 71 // them as such). This is normally used when concatenating directories |
| 67 // together. | 72 // together. |
| 68 // | 73 // |
| 69 // This function asserts that the directory is actually source-absolute. The | 74 // This function asserts that the directory is actually source-absolute. The |
| 70 // return value points into our buffer. | 75 // return value points into our buffer. |
| 71 base::StringPiece SourceAbsoluteWithOneSlash() const { | 76 base::StringPiece SourceAbsoluteWithOneSlash() const { |
| 72 CHECK(is_source_absolute()); | 77 CHECK(is_source_absolute()); |
| 73 return base::StringPiece(&value_[1], value_.size() - 1); | 78 return base::StringPiece(&value_[1], value_.size() - 1); |
| 74 } | 79 } |
| 75 | 80 |
| 76 void SwapInValue(std::string* v); | 81 void SwapValue(std::string* v); |
| 77 | 82 |
| 78 bool operator==(const SourceDir& other) const { | 83 bool operator==(const SourceDir& other) const { |
| 79 return value_ == other.value_; | 84 return value_ == other.value_; |
| 80 } | 85 } |
| 81 bool operator!=(const SourceDir& other) const { | 86 bool operator!=(const SourceDir& other) const { |
| 82 return !operator==(other); | 87 return !operator==(other); |
| 83 } | 88 } |
| 84 bool operator<(const SourceDir& other) const { | 89 bool operator<(const SourceDir& other) const { |
| 85 return value_ < other.value_; | 90 return value_ < other.value_; |
| 86 } | 91 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 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 |
| 112 #endif // TOOLS_GN_SOURCE_DIR_H_ | 117 #endif // TOOLS_GN_SOURCE_DIR_H_ |
| OLD | NEW |