]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/scm-hash.hh
release: 1.3.118
[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. 
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
52
53    TODO:
54
55   - This should come from GUILE. We're typically doing double work,
56    because KEY already is a symbol, and is looked up in a symbol
57    hashtable.
58
59   - use GUILE hashtables iso STL.
60  */
61 class Scheme_hash_table :  private Scm_stl_map
62 {
63 public:
64   bool try_retrieve (SCM key, SCM *val);
65   bool elem_b (SCM key) const;
66
67   /**
68      WARNING: putting something in assumes responsibility for cleaning
69      up.  */
70   void set (SCM k, SCM v);
71   SCM get (SCM k) const; 
72   
73   Scheme_hash_table ();
74   void operator = (Scheme_hash_table const &); 
75   Scheme_hash_table (Scheme_hash_table const &);
76
77   SCM to_alist () const;
78   DECLARE_SMOBS(Scheme_hash_table,foo);
79 };
80
81 #endif /* SCM_HASH_HH */
82