[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / tools / gn / output_file.h
blob5f43a6437fea548d219dcdc74b500d878e4494b1
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_OUTPUT_FILE_H_
6 #define TOOLS_GN_OUTPUT_FILE_H_
8 #include <string>
10 #include "base/containers/hash_tables.h"
11 #include "tools/gn/build_settings.h"
13 class SourceFile;
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(std::string&& v);
21 explicit OutputFile(const std::string& v);
22 OutputFile(const BuildSettings* build_settings,
23 const SourceFile& source_file);
24 ~OutputFile();
26 std::string& value() { return value_; }
27 const std::string& value() const { return value_; }
29 // Converts to a SourceFile by prepending the build directory to the file.
30 // The *Dir version requires that the current OutputFile ends in a slash, and
31 // the *File version is the opposite.
32 SourceFile AsSourceFile(const BuildSettings* build_settings) const;
33 SourceDir AsSourceDir(const BuildSettings* build_settings) const;
35 bool operator==(const OutputFile& other) const {
36 return value_ == other.value_;
38 bool operator!=(const OutputFile& other) const {
39 return value_ != other.value_;
41 bool operator<(const OutputFile& other) const {
42 return value_ < other.value_;
45 private:
46 std::string value_;
49 namespace BASE_HASH_NAMESPACE {
51 template<> struct hash<OutputFile> {
52 std::size_t operator()(const OutputFile& v) const {
53 hash<std::string> h;
54 return h(v.value());
58 } // namespace BASE_HASH_NAMESPACE
60 inline void swap(OutputFile& lhs, OutputFile& rhs) {
61 lhs.value().swap(rhs.value());
64 #endif // TOOLS_GN_OUTPUT_FILE_H_