• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef TOOLS_GN_OUTPUT_FILE_H_
6 #define TOOLS_GN_OUTPUT_FILE_H_
7 
8 #include <string>
9 
10 #include "base/containers/hash_tables.h"
11 #include "tools/gn/build_settings.h"
12 
13 class SourceFile;
14 
15 // A simple wrapper around a string that indicates the string is a path
16 // relative to the output directory.
17 class OutputFile {
18  public:
19   OutputFile();
20   explicit OutputFile(const base::StringPiece& str);
21   OutputFile(const BuildSettings* build_settings,
22              const SourceFile& source_file);
23   ~OutputFile();
24 
value()25   std::string& value() { return value_; }
value()26   const std::string& value() const { return value_; }
27 
28   // Converts to a SourceFile by prepending the build directory to the file.
29   // The *Dir version requires that the current OutputFile ends in a slash, and
30   // the *File version is the opposite.
31   SourceFile AsSourceFile(const BuildSettings* build_settings) const;
32   SourceDir AsSourceDir(const BuildSettings* build_settings) const;
33 
34   bool operator==(const OutputFile& other) const {
35     return value_ == other.value_;
36   }
37   bool operator!=(const OutputFile& other) const {
38     return value_ != other.value_;
39   }
40   bool operator<(const OutputFile& other) const {
41     return value_ < other.value_;
42   }
43 
44  private:
45   std::string value_;
46 };
47 
48 namespace BASE_HASH_NAMESPACE {
49 
50 #if defined(COMPILER_GCC)
51 template<> struct hash<OutputFile> {
52   std::size_t operator()(const OutputFile& v) const {
53     hash<std::string> h;
54     return h(v.value());
55   }
56 };
57 #elif defined(COMPILER_MSVC)
58 inline size_t hash_value(const OutputFile& v) {
59   return hash_value(v.value());
60 }
61 #endif  // COMPILER...
62 
63 }  // namespace BASE_HASH_NAMESPACE
64 
65 inline void swap(OutputFile& lhs, OutputFile& rhs) {
66   lhs.value().swap(rhs.value());
67 }
68 
69 #endif  // TOOLS_GN_OUTPUT_FILE_H_
70