]> git.donarmstrong.com Git - lilypond.git/blob - lily/pointer-group-interface.cc
Web-ja: update introduction
[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 int
26 Pointer_group_interface::count (Grob *me, SCM sym)
27 {
28   Grob_array *arr = unsmob<Grob_array> (me->internal_get_object (sym));
29   return arr ? arr->size () : 0;
30 }
31
32 void
33 Pointer_group_interface::add_grob (Grob *me, SCM sym, SCM p)
34 {
35   add_grob (me, sym, unsmob<Grob> (p));
36 }
37
38 void
39 Pointer_group_interface::set_ordered (Grob *me, SCM sym, bool ordered)
40 {
41   Grob_array *arr = get_grob_array (me, sym);
42   arr->set_ordered (ordered);
43 }
44
45 Grob_array *
46 Pointer_group_interface::get_grob_array (Grob *me, SCM sym)
47 {
48   SCM scm_arr = me->internal_get_object (sym);
49   Grob_array *arr = unsmob<Grob_array> (scm_arr);
50   if (!arr)
51     {
52       scm_arr = Grob_array::make_array ();
53       arr = unsmob<Grob_array> (scm_arr);
54       me->set_object (sym, scm_arr);
55     }
56   return arr;
57 }
58
59 Grob *
60 Pointer_group_interface::find_grob (Grob *me, SCM sym, bool (*pred) (Grob *))
61 {
62   Grob_array *arr = get_grob_array (me, sym);
63
64   for (vsize i = 0; i < arr->size (); i++)
65     if (pred (arr->grob (i)))
66       return arr->grob (i);
67
68   return 0;
69 }
70
71 void
72 Pointer_group_interface::add_grob (Grob *me, SCM sym, Grob *p)
73 {
74   Grob_array *arr = get_grob_array (me, sym);
75   arr->add (p);
76 }
77
78 void
79 Pointer_group_interface::add_unordered_grob (Grob *me, SCM sym, Grob *p)
80 {
81   Grob_array *arr = get_grob_array (me, sym);
82   arr->add (p);
83   arr->set_ordered (false);
84 }
85
86 static vector<Grob *> empty_array;
87
88 vector<Grob *> const &
89 ly_scm2link_array (SCM x)
90 {
91   Grob_array *arr = unsmob<Grob_array> (x);
92   return arr ? arr->array () : empty_array;
93 }
94
95 vector<Grob *> const &
96 internal_extract_grob_array (Grob const *elt, SCM symbol)
97 {
98   return elt
99          ? ly_scm2link_array (elt->internal_get_object (symbol))
100          : empty_array;
101 }
102
103 vector<Item *>
104 internal_extract_item_array (Grob const *elt, SCM symbol)
105 {
106   Grob_array *arr = unsmob<Grob_array> (elt->internal_get_object (symbol));
107   vector<Item *> items;
108   for (vsize i = 0; arr && i < arr->size (); i++)
109     items.push_back (arr->item (i));
110
111   return items;
112 }