]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/scm-hash.hh
6c390be8f5b352d09ee3e2cd359912b51f713e78
[lilypond.git] / lily / include / scm-hash.hh
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1999--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef SCM_HASH_HH
21 #define SCM_HASH_HH
22
23 #include "smobs.hh"
24
25 /*
26   hash table.
27
28   1. ALWAYS USE THIS AS VIA A POINTER, i.e.
29
30   class Foo {
31   Scheme_hash_table * tab;
32   };
33
34   and NOT
35
36   class Foo {
37   Scheme_hash_table tab;
38   }
39
40
41   2. UPON DESTRUCTION, DO
42
43   scm_gc_unprotect_object (tab->self_scm_);
44 */
45
46 class Scheme_hash_table : public Smob<Scheme_hash_table>
47 {
48 public:
49   int print_smob (SCM, scm_print_state *);
50   SCM mark_smob ();
51   virtual ~Scheme_hash_table ();
52   bool try_retrieve (SCM key, SCM *val);
53   bool contains (SCM key) const;
54   void set (SCM k, SCM v);
55   SCM get (SCM k) const;
56   void remove (SCM k);
57   Scheme_hash_table ();
58   void operator = (Scheme_hash_table const &);
59   Scheme_hash_table (Scheme_hash_table const &);
60   SCM to_alist () const;
61
62 private:
63   SCM hash_tab_;
64   void copy (Scheme_hash_table const &src);
65 };
66
67 #endif /* SCM_HASH_HH */