summaryrefslogtreecommitdiffstats
path: root/tools/gn/output_file.h
blob: eb6faf064f8c19cf32e1398a0878a34234e91633 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef TOOLS_GN_OUTPUT_FILE_H_
#define TOOLS_GN_OUTPUT_FILE_H_

#include <string>

#include "base/containers/hash_tables.h"
#include "tools/gn/build_settings.h"

class SourceFile;

// A simple wrapper around a string that indicates the string is a path
// relative to the output directory.
class OutputFile {
 public:
  OutputFile();
  explicit OutputFile(const base::StringPiece& str);
  OutputFile(const BuildSettings* build_settings,
             const SourceFile& source_file);
  ~OutputFile();

  std::string& value() { return value_; }
  const std::string& value() const { return value_; }

  // Converts to a SourceFile by prepending the build directory to the file.
  // The *Dir version requires that the current OutputFile ends in a slash, and
  // the *File version is the opposite.
  SourceFile AsSourceFile(const BuildSettings* build_settings) const;
  SourceDir AsSourceDir(const BuildSettings* build_settings) const;

  bool operator==(const OutputFile& other) const {
    return value_ == other.value_;
  }
  bool operator!=(const OutputFile& other) const {
    return value_ != other.value_;
  }
  bool operator<(const OutputFile& other) const {
    return value_ < other.value_;
  }

 private:
  std::string value_;
};

namespace BASE_HASH_NAMESPACE {

#if defined(COMPILER_GCC)
template<> struct hash<OutputFile> {
  std::size_t operator()(const OutputFile& v) const {
    hash<std::string> h;
    return h(v.value());
  }
};
#elif defined(COMPILER_MSVC)
inline size_t hash_value(const OutputFile& v) {
  return hash_value(v.value());
}
#endif  // COMPILER...

}  // namespace BASE_HASH_NAMESPACE

inline void swap(OutputFile& lhs, OutputFile& rhs) {
  lhs.value().swap(rhs.value());
}

#endif  // TOOLS_GN_OUTPUT_FILE_H_