]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-1.3.0
authorfred <fred>
Tue, 26 Oct 1999 17:48:17 +0000 (17:48 +0000)
committerfred <fred>
Tue, 26 Oct 1999 17:48:17 +0000 (17:48 +0000)
lily/include/scm-hash.hh [new file with mode: 0644]
lily/scm-hash.cc [new file with mode: 0644]

diff --git a/lily/include/scm-hash.hh b/lily/include/scm-hash.hh
new file mode 100644 (file)
index 0000000..a0382d0
--- /dev/null
@@ -0,0 +1,32 @@
+/*   
+  scm-hash.hh -- declare Scheme hasher.
+  
+  source file of the GNU LilyPond music typesetter
+  
+  (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  
+ */
+
+#ifndef SCM_HASH_HH
+#define SCM_HASH_HH
+
+#include "lily-guile.hh"
+#include "hash-table.hh"
+#include "smobs.hh"
+
+/**
+   auto resizing hash table. This should come from GUILE.
+ */
+class Scheme_hash_table : public Hash_table<SCM,SCM>
+{
+public:  
+  Scheme_hash_table ();
+  void operator = (Scheme_hash_table const &); 
+  Scheme_hash_table (Scheme_hash_table const &);
+  virtual ~Scheme_hash_table ();
+  DECLARE_SMOBS;
+  SCM to_alist () const;
+};
+
+#endif /* SCM_HASH_HH */
+
diff --git a/lily/scm-hash.cc b/lily/scm-hash.cc
new file mode 100644 (file)
index 0000000..043cb23
--- /dev/null
@@ -0,0 +1,93 @@
+/*   
+  scm-hash.cc --  implement Scheme_hash_table
+  
+  source file of the GNU LilyPond music typesetter
+  
+  (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  
+ */
+
+#include "scm-hash.hh"
+#include "hash-table-iter.hh"
+
+Scheme_hash_table::Scheme_hash_table ()
+{
+  hash_func_ = ly_scm_hash;
+  self_scm_ = SCM_EOL;
+  smobify_self ();
+}
+
+void
+Scheme_hash_table::operator =(Scheme_hash_table const & src)
+{
+  Hash_table<SCM,SCM>::operator = (src);
+       
+  // we do not copy the self_scm_ field!
+}
+
+void
+Scheme_hash_table::do_smobify_self ()
+{
+}
+
+#include "ly-smobs.icc"
+IMPLEMENT_SMOBS(Scheme_hash_table);
+
+SCM
+Scheme_hash_table::mark_smob (SCM s)
+{
+  /*
+    can't typecheck naively, since GC bit lives in CAR of S
+   */
+  //assert (SMOB_IS_TYPE_B (Scheme_hash_table, s));
+  
+  Scheme_hash_table *me = SMOB_TO_TYPE(Scheme_hash_table,s);
+  for (Hash_table_iter<SCM,SCM> i (*me); i.ok(); i++)
+    {
+      scm_gc_mark (i.key());
+      scm_gc_mark (i.val ());
+    }
+  return SCM_EOL;
+}
+
+
+Scheme_hash_table::Scheme_hash_table (Scheme_hash_table const &src)
+  : Hash_table<SCM,SCM> (src)
+{
+  hash_func_ = src.hash_func_;
+  self_scm_ = SCM_EOL;
+  smobify_self ();
+}
+
+int
+Scheme_hash_table::print_smob (SCM s, SCM p, scm_print_state*ps)
+{
+  assert (SMOB_IS_TYPE_B (Scheme_hash_table, s));
+  Scheme_hash_table *me = SMOB_TO_TYPE(Scheme_hash_table,s);
+  for (Hash_table_iter<SCM,SCM> i (*me); i.ok(); i++)
+    {
+      scm_display (i.key(), p);
+      scm_puts (" = ",p);      
+      scm_display (i.val (), p);
+      scm_puts ("\n",p);            
+    }
+  return 1;
+}
+
+
+
+
+Scheme_hash_table::~Scheme_hash_table( )
+{
+  unsmobify_self ();
+}
+
+SCM
+Scheme_hash_table::to_alist () const
+{
+  SCM l = SCM_EOL;
+  for (Hash_table_iter<SCM,SCM> i (*this); i.ok(); i++)
+    l = gh_cons (gh_cons (i.key (), i.val()), l);
+  return l;  
+}
+