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 <stddef.h> 9 10 #include <string> 11 12 class BuildSettings; 13 class SourceDir; 14 class SourceFile; 15 16 // A simple wrapper around a string that indicates the string is a path 17 // relative to the output directory. 18 class OutputFile { 19 public: 20 OutputFile() = default; 21 22 explicit OutputFile(std::string&& v); 23 explicit OutputFile(const std::string& v); 24 25 OutputFile(const BuildSettings* build_settings, 26 const SourceFile& source_file); 27 value()28 std::string& value() { return value_; } value()29 const std::string& value() const { return value_; } 30 31 // Converts to a SourceFile by prepending the build directory to the file. 32 // The *Dir version requires that the current OutputFile ends in a slash, and 33 // the *File version is the opposite. 34 SourceFile AsSourceFile(const BuildSettings* build_settings) const; 35 SourceDir AsSourceDir(const BuildSettings* build_settings) const; 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 bool operator<(const OutputFile& other) const { 44 return value_ < other.value_; 45 } 46 47 private: 48 std::string value_; 49 }; 50 51 namespace std { 52 53 template <> 54 struct hash<OutputFile> { 55 std::size_t operator()(const OutputFile& v) const { 56 hash<std::string> h; 57 return h(v.value()); 58 } 59 }; 60 61 } // namespace std 62 63 #endif // TOOLS_GN_OUTPUT_FILE_H_ 64