1d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// Use of this source code is governed by a BSD-style license that can be
3d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// found in the LICENSE file.
4d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch
5d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch#ifndef TOOLS_GN_OUTPUT_FILE_H_
6d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch#define TOOLS_GN_OUTPUT_FILE_H_
7d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch
8d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch#include <string>
9d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch
105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "base/containers/hash_tables.h"
11d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch#include "tools/gn/build_settings.h"
1203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
1303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)class SourceFile;
14d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch
15d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// A simple wrapper around a string that indicates the string is a path
16d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// relative to the output directory.
17d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochclass OutputFile {
18d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch public:
1903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  OutputFile();
2003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  explicit OutputFile(const base::StringPiece& str);
2103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  OutputFile(const BuildSettings* build_settings,
2203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)             const SourceFile& source_file);
2303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  ~OutputFile();
24d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch
25d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch  std::string& value() { return value_; }
26d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch  const std::string& value() const { return value_; }
27d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch
28d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch  // Converts to a SourceFile by prepending the build directory to the file.
2903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // The *Dir version requires that the current OutputFile ends in a slash, and
3003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // the *File version is the opposite.
3103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  SourceFile AsSourceFile(const BuildSettings* build_settings) const;
3203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  SourceDir AsSourceDir(const BuildSettings* build_settings) const;
33d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch
34d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch  bool operator==(const OutputFile& other) const {
35d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch    return value_ == other.value_;
36d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch  }
37d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch  bool operator!=(const OutputFile& other) const {
38d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch    return value_ != other.value_;
39d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch  }
404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool operator<(const OutputFile& other) const {
414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    return value_ < other.value_;
424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
43d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch
44d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch private:
45d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch  std::string value_;
46d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch};
47d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch
485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)namespace BASE_HASH_NAMESPACE {
495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#if defined(COMPILER_GCC)
515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)template<> struct hash<OutputFile> {
525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  std::size_t operator()(const OutputFile& v) const {
535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    hash<std::string> h;
545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    return h(v.value());
555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  }
565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)};
575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#elif defined(COMPILER_MSVC)
585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)inline size_t hash_value(const OutputFile& v) {
595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  return hash_value(v.value());
605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#endif  // COMPILER...
625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}  // namespace BASE_HASH_NAMESPACE
645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)inline void swap(OutputFile& lhs, OutputFile& rhs) {
665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  lhs.value().swap(rhs.value());
675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#endif  // TOOLS_GN_OUTPUT_FILE_H_
70