]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/scm-hash.hh
release: 1.3.92
[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  */
60 class Scheme_hash_table :  private Scm_stl_map
61 {
62 public:
63   bool try_retrieve (SCM key, SCM *val);
64   bool elem_b (SCM key) const;
65
66   /**
67      WARNING: putting something in assumes responsibility for cleaning
68      up.  */
69   void set (SCM k, SCM v);
70   SCM get (SCM k) const; 
71   
72   Scheme_hash_table ();
73   void operator = (Scheme_hash_table const &); 
74   Scheme_hash_table (Scheme_hash_table const &);
75
76   SCM to_alist () const;
77   DECLARE_SMOBS(Scheme_hash_table,foo);
78 };
79
80 #endif /* SCM_HASH_HH */
81