]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/group-interface.hh
patch::: 1.3.33.jcn3
[lilypond.git] / lily / include / group-interface.hh
1 /*   
2   group-interface.hh -- declare Group_interface
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 GROUP_INTERFACE_HH
11 #define GROUP_INTERFACE_HH
12
13 #include "lily-proto.hh"
14 #include "string.hh"
15 #include "lily-guile.hh"
16 #include "smobs.hh"
17
18 /*
19   rename to list interface?
20  */
21
22 /**
23    Look at Score element ELT as thing which has a list property called
24    NAME_. Normally the list would contain Score_elements, but
25    sometimes it can be different things.
26 */
27 struct Group_interface
28 {
29   Score_element * elt_l_;
30   String name_;
31 public:
32   Group_interface (Score_element const*);
33   Group_interface (Score_element const*, String);
34   int count ();
35   void add_thing (SCM);
36   bool has_interface_b ();
37   void set_interface ();
38   void add_element (Score_element*);
39 };
40
41 Group_interface group (Score_element*);
42 Group_interface group (Score_element*, String);
43
44 /** 
45   Put all score elements of ELT's property called NAME into an array,
46   and return it.  */
47 template<class T>
48 Link_array<T>
49 Group_interface__extract_elements (Score_element const *elt, T *, String name)
50 {
51   Link_array<T> arr;
52
53   for (SCM s = elt->get_elt_property (name); gh_pair_p (s); s = gh_cdr (s))
54     {
55       SCM e = gh_car (s);
56       assert (SMOB_IS_TYPE_B(Score_element,e));
57       Score_element* se = SMOB_TO_TYPE(Score_element, e);
58       arr.push (dynamic_cast<T*> (se));
59     }
60
61   arr.reverse ();
62   return arr;
63 }
64
65
66
67
68 #endif /* GROUP_INTERFACE_HH */
69