1 // Copyright 2015 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_LIB_FILE_H_ 6 #define TOOLS_GN_LIB_FILE_H_ 7 8 #include <stddef.h> 9 10 #include <algorithm> 11 #include <string> 12 #include <string_view> 13 14 #include "gn/source_file.h" 15 16 // Represents an entry in "libs" list. Can be either a path (a SourceFile) or 17 // a library name (a string). 18 class LibFile { 19 public: 20 LibFile() = default; 21 22 explicit LibFile(std::string_view lib_name); 23 explicit LibFile(const SourceFile& source_file); 24 is_source_file()25 bool is_source_file() const { return name_.empty(); } 26 27 // Returns name, or source_file().value() (whichever is set). 28 const std::string& value() const; 29 const SourceFile& source_file() const; 30 31 bool operator==(const LibFile& other) const { 32 return value() == other.value(); 33 } 34 bool operator!=(const LibFile& other) const { return !operator==(other); } 35 bool operator<(const LibFile& other) const { return value() < other.value(); } 36 37 private: 38 std::string name_; 39 SourceFile source_file_; 40 }; 41 42 namespace std { 43 44 template <> 45 struct hash<LibFile> { 46 std::size_t operator()(const LibFile& v) const { 47 hash<std::string> h; 48 return h(v.value()); 49 } 50 }; 51 52 } // namespace std 53 54 #endif // TOOLS_GN_LIB_FILE_H_ 55