]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/scm-hash.hh
release: 1.5.14
[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--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #ifndef SCM_HASH_HH
11 #define SCM_HASH_HH
12
13
14 #include "lily-guile.hh"
15 #include "smobs.hh"
16
17
18 /**
19    auto resizing hash table. 
20
21    1. ALWAYS USE THIS AS VIA A POINTER, i.e.
22
23    class Foo {
24     Scheme_hash_table * tab;
25    };
26
27    and NOT
28
29    class Foo {
30     Scheme_hash_table tab;
31    }
32
33
34    2. UPON DESTRUCTION, DO
35
36    scm_gc_unprotect_object (tab->self_scm_);
37
38
39
40
41    TODO:
42
43   - This should come from GUILE. We're typically doing double work,
44    because KEY already is a symbol, and is looked up in a symbol
45    hashtable.
46
47   - use GUILE hashtables iso STL.
48  */
49
50 class Scheme_hash_table
51 {  
52 public:
53   bool try_retrieve (SCM key, SCM *val);
54   bool elem_b (SCM key) const;
55
56   /**
57      WARNING: putting something in assumes responsibility for cleaning
58      up.  */
59   void set (SCM k, SCM v);
60   SCM get (SCM k) const; 
61   void remove (SCM k);
62   Scheme_hash_table ();
63   void operator = (Scheme_hash_table const &); 
64   Scheme_hash_table (Scheme_hash_table const &);
65
66   SCM to_alist () const;
67 private:
68   SCM hash_tab_;
69   unsigned elt_count_;
70   
71   DECLARE_SMOBS (Scheme_hash_table,foo);
72 };
73
74
75 #endif /* SCM_HASH_HH */
76