]> git.donarmstrong.com Git - lilypond.git/commitdiff
*** empty log message ***
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 16 Jul 2005 13:10:23 +0000 (13:10 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 16 Jul 2005 13:10:23 +0000 (13:10 +0000)
lily/include/pointer-group-interface.hh [new file with mode: 0644]
lily/pointer-group-interface.cc [new file with mode: 0644]

diff --git a/lily/include/pointer-group-interface.hh b/lily/include/pointer-group-interface.hh
new file mode 100644 (file)
index 0000000..0565b83
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+  pointer-group-interface.hh -- declare Pointer_group_interface
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+*/
+
+#ifndef POINTER_GROUP_INTERFACE_HH
+#define POINTER_GROUP_INTERFACE_HH
+
+#include "parray.hh"
+#include "lily-proto.hh"
+#include "lily-guile.hh"
+
+
+struct Pointer_group_interface
+{
+public:
+  static int count (Grob *, SCM);
+  static void add_grob (Grob *, SCM nm, Grob *e);
+  static void add_grob (Grob *, SCM nm, SCM x);
+};
+
+Link_array<Grob> const &internal_extract_grob_array (Grob const *elt, SCM symbol);
+Link_array<Item> internal_extract_item_array (Grob const *elt, SCM symbol);
+
+#define extract_grob_array(x,prop) internal_extract_grob_array (x, ly_symbol2scm (prop))
+#define extract_item_array(x,prop) internal_extract_item_array (x, ly_symbol2scm (prop))
+
+
+/*
+  This is dubious coding style, but lets not risk that we change the
+  representation of grob sets again.
+ */
+#define extract_grob_set(grob,prop,set) \
+  Link_array<Grob> const &set (internal_extract_grob_array (grob, ly_symbol2scm (prop))) 
+#define extract_item_set(grob,prop,set) \
+  Link_array<Item> set (internal_extract_item_array (grob, ly_symbol2scm (prop)))
+
+
+
+#endif /* POINTER_GROUP_INTERFACE_HH */
+
diff --git a/lily/pointer-group-interface.cc b/lily/pointer-group-interface.cc
new file mode 100644 (file)
index 0000000..07e49c3
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+  pointer-group-interface.cc -- implement Pointer_group_interface
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+*/
+
+#include "pointer-group-interface.hh"
+
+#include "lily-proto.hh"
+#include "item.hh"
+#include "grob-array.hh"
+#include "grob.hh"
+
+int
+Pointer_group_interface::count (Grob *me, SCM sym)
+{
+  Grob_array *arr = unsmob_grob_array (me->internal_get_object (sym));
+  return arr ? arr->size() : 0;
+}
+
+void
+Pointer_group_interface::add_grob (Grob *me, SCM sym, SCM p)
+{
+  add_grob (me, sym, unsmob_grob (p));
+}
+
+
+void
+Pointer_group_interface::add_grob (Grob *me, SCM sym, Grob *p)
+{
+  SCM scm_arr = me->internal_get_object (sym);
+  Grob_array *arr = unsmob_grob_array (scm_arr);
+  if (!arr)
+    {
+      scm_arr = Grob_array::make_array ();
+      arr = unsmob_grob_array (scm_arr);
+      me->internal_set_object (sym, scm_arr);
+    }
+  arr->add (p);
+}
+  
+static Link_array<Grob> empty_array;
+
+Link_array<Grob> const &
+ly_scm2link_array (SCM x)
+{
+  Grob_array *arr = unsmob_grob_array (x);
+  return arr ? arr->array () : empty_array;
+}
+  
+
+Link_array<Grob> const &
+internal_extract_grob_array (Grob const *elt, SCM symbol)
+{
+  return ly_scm2link_array (elt->internal_get_object (symbol));
+}
+
+Link_array<Item>
+internal_extract_item_array (Grob const *elt, SCM symbol)
+{
+  Grob_array *arr = unsmob_grob_array (elt->internal_get_object (symbol));
+  Link_array<Item> items;
+  for (int i = 0; arr && i < arr->size (); i++)
+    {
+      items.push (arr->item (i));
+    }
+
+  return items;
+}