]> git.donarmstrong.com Git - lilypond.git/blob - lily/pointer-group-interface.cc
Doc: Included/compile.itexi - CG 4.2 - Updated notes on reqs for compiling
[lilypond.git] / lily / pointer-group-interface.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "pointer-group-interface.hh"
21
22 #include "grob-array.hh"
23 #include "grob.hh"
24
25 using std::vector;
26
27 int
28 Pointer_group_interface::count (Grob *me, SCM sym)
29 {
30   Grob_array *arr = unsmob<Grob_array> (me->internal_get_object (sym));
31   return arr ? arr->size () : 0;
32 }
33
34 void
35 Pointer_group_interface::add_grob (Grob *me, SCM sym, SCM p)
36 {
37   add_grob (me, sym, unsmob<Grob> (p));
38 }
39
40 void
41 Pointer_group_interface::set_ordered (Grob *me, SCM sym, bool ordered)
42 {
43   Grob_array *arr = get_grob_array (me, sym);
44   arr->set_ordered (ordered);
45 }
46
47 Grob_array *
48 Pointer_group_interface::get_grob_array (Grob *me, SCM sym)
49 {
50   SCM scm_arr = me->internal_get_object (sym);
51   Grob_array *arr = unsmob<Grob_array> (scm_arr);
52   if (!arr)
53     {
54       scm_arr = Grob_array::make_array ();
55       arr = unsmob<Grob_array> (scm_arr);
56       me->set_object (sym, scm_arr);
57     }
58   return arr;
59 }
60
61 Grob *
62 Pointer_group_interface::find_grob (Grob *me, SCM sym, bool (*pred) (Grob *))
63 {
64   Grob_array *arr = get_grob_array (me, sym);
65
66   for (vsize i = 0; i < arr->size (); i++)
67     if (pred (arr->grob (i)))
68       return arr->grob (i);
69
70   return 0;
71 }
72
73 void
74 Pointer_group_interface::add_grob (Grob *me, SCM sym, Grob *p)
75 {
76   Grob_array *arr = get_grob_array (me, sym);
77   arr->add (p);
78 }
79
80 void
81 Pointer_group_interface::add_unordered_grob (Grob *me, SCM sym, Grob *p)
82 {
83   Grob_array *arr = get_grob_array (me, sym);
84   arr->add (p);
85   arr->set_ordered (false);
86 }
87
88 static vector<Grob *> empty_array;
89
90 vector<Grob *> const &
91 ly_scm2link_array (SCM x)
92 {
93   Grob_array *arr = unsmob<Grob_array> (x);
94   return arr ? arr->array () : empty_array;
95 }
96
97 vector<Grob *> const &
98 internal_extract_grob_array (Grob const *elt, SCM symbol)
99 {
100   return elt
101          ? ly_scm2link_array (elt->internal_get_object (symbol))
102          : empty_array;
103 }
104
105 vector<Item *>
106 internal_extract_item_array (Grob const *elt, SCM symbol)
107 {
108   Grob_array *arr = unsmob<Grob_array> (elt->internal_get_object (symbol));
109   vector<Item *> items;
110   for (vsize i = 0; arr && i < arr->size (); i++)
111     items.push_back (arr->item (i));
112
113   return items;
114 }