lilypond-1.3.138
[lilypond.git] / lily / include / scm-hash.hh
blob5215476963749460ed3201b81440538726e9c146
1 /*
2 scm-hash.hh -- declare Scheme hasher.
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #ifndef SCM_HASH_HH
11 #define SCM_HASH_HH
14 #include <map>
16 #include "lily-guile.hh"
17 #include "smobs.hh"
20 struct SCM_less
22 bool operator () (SCM s1, SCM s2) const
24 return long (s1) < long (s2);
28 typedef map<SCM,SCM, SCM_less> Scm_stl_map;
30 /**
31 auto resizing hash table.
33 1. ALWAYS USE THIS AS VIA A POINTER, i.e.
35 class Foo {
36 Scheme_hash_table * tab;
39 and NOT
41 class Foo {
42 Scheme_hash_table tab;
46 2. UPON DESTRUCTION, DO
48 scm_unprotect_object (tab->self_scm_);
53 TODO:
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.
59 - use GUILE hashtables iso STL.
61 class Scheme_hash_table : private Scm_stl_map
63 public:
64 bool try_retrieve (SCM key, SCM *val);
65 bool elem_b (SCM key) const;
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 void remove (SCM k);
73 Scheme_hash_table ();
74 void operator = (Scheme_hash_table const &);
75 Scheme_hash_table (Scheme_hash_table const &);
77 SCM to_alist () const;
78 DECLARE_SMOBS (Scheme_hash_table,foo);
81 #endif /* SCM_HASH_HH */