Replace command buffer FlushSync with WaitForTokenInRange and WaitForGetOffsetInRange
[chromium-blink-merge.git] / tools / gn / source_dir.h
blob99be5c37ec7b12e556cc6968e0ab9d36364e4b7d
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
3 // found in the LICENSE file.
5 #ifndef TOOLS_GN_SOURCE_DIR_H_
6 #define TOOLS_GN_SOURCE_DIR_H_
8 #include <string>
10 #include "base/containers/hash_tables.h"
11 #include "base/files/file_path.h"
12 #include "base/logging.h"
13 #include "base/strings/string_piece.h"
15 class SourceFile;
17 // Represents a directory within the source tree. Source dirs begin and end in
18 // slashes.
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".
23 // Two slashes at the beginning indicate a path relative to the source root.
24 class SourceDir {
25 public:
26 enum SwapIn { SWAP_IN };
28 SourceDir();
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);
33 ~SourceDir();
35 // Resolves a file or dir name relative to this source directory. Will return
36 // an empty SourceDir/File on error. Empty input is always an error (it's
37 // possible we should say ResolveRelativeDir vs. an empty string should be
38 // the source dir, but we require "." instead).
40 // If source_root is supplied, these functions will additionally handle the
41 // case where the input is a system-absolute but still inside the source
42 // tree. This is the case for some external tools.
43 SourceFile ResolveRelativeFile(
44 const base::StringPiece& p,
45 const base::StringPiece& source_root = base::StringPiece()) const;
46 SourceDir ResolveRelativeDir(
47 const base::StringPiece& p,
48 const base::StringPiece& source_root = base::StringPiece()) const;
50 // Resolves this source file relative to some given source root. Returns
51 // an empty file path on error.
52 base::FilePath Resolve(const base::FilePath& source_root) const;
54 bool is_null() const { return value_.empty(); }
55 const std::string& value() const { return value_; }
57 // Returns true if this path starts with a "//" which indicates a path
58 // from the source root.
59 bool is_source_absolute() const {
60 return value_.size() >= 2 && value_[0] == '/' && value_[1] == '/';
63 // Returns true if this path starts with a single slash which indicates a
64 // system-absolute path.
65 bool is_system_absolute() const {
66 return !is_source_absolute();
69 // Returns a source-absolute path starting with only one slash at the
70 // beginning (normally source-absolute paths start with two slashes to mark
71 // them as such). This is normally used when concatenating directories
72 // together.
74 // This function asserts that the directory is actually source-absolute. The
75 // return value points into our buffer.
76 base::StringPiece SourceAbsoluteWithOneSlash() const {
77 CHECK(is_source_absolute());
78 return base::StringPiece(&value_[1], value_.size() - 1);
81 void SwapValue(std::string* v);
83 bool operator==(const SourceDir& other) const {
84 return value_ == other.value_;
86 bool operator!=(const SourceDir& other) const {
87 return !operator==(other);
89 bool operator<(const SourceDir& other) const {
90 return value_ < other.value_;
93 private:
94 friend class SourceFile;
95 std::string value_;
97 // Copy & assign supported.
100 namespace BASE_HASH_NAMESPACE {
102 #if defined(COMPILER_GCC)
103 template<> struct hash<SourceDir> {
104 std::size_t operator()(const SourceDir& v) const {
105 hash<std::string> h;
106 return h(v.value());
109 #elif defined(COMPILER_MSVC)
110 inline size_t hash_value(const SourceDir& v) {
111 return hash_value(v.value());
113 #endif // COMPILER...
115 } // namespace BASE_HASH_NAMESPACE
117 #endif // TOOLS_GN_SOURCE_DIR_H_