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