Add translations for various sub-directories
[binutils-gdb.git] / gdb / filename-seen-cache.h
blob3cac93fceadcea0602e549b631da36a64d570ef8
1 /* Filename-seen cache for the GNU debugger, GDB.
3 Copyright (C) 1986-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #ifndef GDB_FILENAME_SEEN_CACHE_H
21 #define GDB_FILENAME_SEEN_CACHE_H
23 #include "gdbsupport/unordered_set.h"
24 #include "filenames.h"
26 /* Cache to watch for file names already seen. */
28 class filename_seen_cache
30 public:
31 filename_seen_cache () = default;
33 DISABLE_COPY_AND_ASSIGN (filename_seen_cache);
35 /* Empty the cache. */
36 void clear ()
37 { m_tab.clear (); }
39 /* If FILE is not already in the table of files of the cache, add it and
40 return false; otherwise return true.
42 NOTE: We don't manage space for FILE, we assume FILE lives as
43 long as the caller needs. */
44 bool seen (const char *file)
45 { return !m_tab.insert (file).second; }
47 private:
48 struct hash
50 std::size_t operator() (const char *s) const noexcept
51 { return filename_hash (s); }
54 struct eq
56 bool operator() (const char *lhs, const char *rhs) const noexcept
57 { return filename_eq (lhs, rhs); }
60 /* Table of files seen so far. */
61 gdb::unordered_set<const char *, hash, eq> m_tab;
64 #endif /* GDB_FILENAME_SEEN_CACHE_H */