]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/scm-hash.hh
Merge branch 'master' of ssh+git://gpercival@git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / lily / include / scm-hash.hh
1 /*
2   scm-hash.hh -- declare Scheme hasher.
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1999--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #ifndef SCM_HASH_HH
10 #define SCM_HASH_HH
11
12 #include "smobs.hh"
13
14 /**
15    auto resizing hash table.
16
17    1. ALWAYS USE THIS AS VIA A POINTER, i.e.
18
19    class Foo {
20    Scheme_hash_table * tab;
21    };
22
23    and NOT
24
25    class Foo {
26    Scheme_hash_table tab;
27    }
28
29
30    2. UPON DESTRUCTION, DO
31
32    scm_gc_unprotect_object (tab->self_scm_);
33 */
34
35 class Scheme_hash_table
36 {
37 public:
38   bool try_retrieve (SCM key, SCM *val);
39   bool contains (SCM key) const;
40
41   /**
42      WARNING: putting something in assumes responsibility for cleaning
43      up.  */
44   void set (SCM k, SCM v);
45   SCM get (SCM k) const;
46   void remove (SCM k);
47   Scheme_hash_table ();
48   void operator = (Scheme_hash_table const &);
49   Scheme_hash_table (Scheme_hash_table const &);
50
51   SCM to_alist () const;
52
53 private:
54   SCM hash_tab_;
55   unsigned elt_count_;
56
57   DECLARE_SMOBS (Scheme_hash_table);
58 };
59
60 #endif /* SCM_HASH_HH */
61