Update copyright year range in all GDB files
[deliverable/binutils-gdb.git] / gdb / filename-seen-cache.h
CommitLineData
bbf2f4df
PA
1/* Filename-seen cache for the GNU debugger, GDB.
2
e2882c85 3 Copyright (C) 1986-2018 Free Software Foundation, Inc.
bbf2f4df
PA
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20#include "defs.h"
21#include "common/function-view.h"
22
23/* Cache to watch for file names already seen. */
24
25class filename_seen_cache
26{
27public:
28 filename_seen_cache ();
29 ~filename_seen_cache ();
30
d6541620 31 DISABLE_COPY_AND_ASSIGN (filename_seen_cache);
bbf2f4df
PA
32
33 /* Empty the cache, but do not delete it. */
34 void clear ();
35
36 /* If FILE is not already in the table of files in CACHE, add it and
37 return false; otherwise return true.
38
39 NOTE: We don't manage space for FILE, we assume FILE lives as
40 long as the caller needs. */
41 bool seen (const char *file);
42
43 /* Traverse all cache entries, calling CALLBACK on each. The
44 filename is passed as argument to CALLBACK. */
45 void traverse (gdb::function_view<void (const char *filename)> callback)
46 {
47 auto erased_cb = [] (void **slot, void *info) -> int
48 {
49 auto filename = (const char *) *slot;
50 auto restored_cb = (decltype (callback) *) info;
51 (*restored_cb) (filename);
52 return 1;
53 };
54
55 htab_traverse_noresize (m_tab, erased_cb, &callback);
56 }
57
58private:
59 /* Table of files seen so far. */
60 htab_t m_tab;
61};
This page took 0.094523 seconds and 4 git commands to generate.