Automatic date update in version.in
[binutils-gdb/blckswan.git] / gdb / filename-seen-cache.h
blob83a6e8a6258c8935b6b3e62ebc0af63c2a6acf6b
1 /* Filename-seen cache for the GNU debugger, GDB.
3 Copyright (C) 1986-2022 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 FILENAME_SEEN_CACHE_H
21 #define FILENAME_SEEN_CACHE_H
23 #include "defs.h"
24 #include "gdbsupport/function-view.h"
25 #include "gdbsupport/gdb-hashtab.h"
27 /* Cache to watch for file names already seen. */
29 class filename_seen_cache
31 public:
32 filename_seen_cache ();
34 DISABLE_COPY_AND_ASSIGN (filename_seen_cache);
36 /* Empty the cache, but do not delete it. */
37 void clear ();
39 /* If FILE is not already in the table of files in 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);
46 /* Traverse all cache entries, calling CALLBACK on each. The
47 filename is passed as argument to CALLBACK. */
48 void traverse (gdb::function_view<void (const char *filename)> callback)
50 auto erased_cb = [] (void **slot, void *info) -> int
52 auto filename = (const char *) *slot;
53 auto restored_cb = (decltype (callback) *) info;
54 (*restored_cb) (filename);
55 return 1;
58 htab_traverse_noresize (m_tab.get (), erased_cb, &callback);
61 private:
62 /* Table of files seen so far. */
63 htab_up m_tab;
66 #endif /* FILENAME_SEEN_CACHE_H */