]> git.donarmstrong.com Git - lilypond.git/blob - lily/grob-array.cc
Issue 4082/3: Run scripts/auxiliar/smob-convert.sh
[lilypond.git] / lily / grob-array.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2014 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 "grob-array.hh"
21 #include "item.hh"
22 #include "spanner.hh"
23
24
25 Item *
26 Grob_array::item (vsize i)
27 {
28   return dynamic_cast<Item *> (grobs_.at (i));
29 }
30
31 Spanner *
32 Grob_array::spanner (vsize i)
33 {
34   return dynamic_cast<Spanner *> (grobs_.at (i));
35 }
36
37 Grob_array::Grob_array ()
38 {
39   ordered_ = true;
40 }
41
42 vector<Grob *> &
43 Grob_array::array_reference ()
44 {
45   return grobs_;
46 }
47
48 vector<Grob *> const &
49 Grob_array::array () const
50 {
51   return grobs_;
52 }
53
54 SCM
55 Grob_array::mark_smob (SCM s)
56 {
57   (void) s;
58
59 #if 0  /* see System::derived_mark () const */
60   Grob_array *ga = Grob_array::unsmob (s);
61   for (vsize i = 0; i < ga->grobs_.size (); i++)
62     scm_gc_mark (ga->grobs_[i]->self_scm ());
63 #endif
64   return SCM_UNDEFINED;
65 }
66
67 int
68 Grob_array::print_smob (SCM arr, SCM port, scm_print_state *)
69 {
70   scm_puts ("#<Grob_array", port);
71
72   Grob_array *grob_arr = unsmob (arr);
73   for (vsize i = 0; i < grob_arr->size (); i++)
74     {
75       scm_display (grob_arr->grob (i)->self_scm (), port);
76       scm_puts (" ", port);
77     }
78   scm_puts (">", port);
79   return 1;
80 }
81
82 SCM
83 Grob_array::make_array ()
84 {
85   Grob_array ga;
86   return ga.smobbed_copy ();
87 }
88
89 void
90 Grob_array::clear ()
91 {
92   grobs_.clear ();
93 }
94
95 void
96 Grob_array::remove_duplicates ()
97 {
98   assert (!ordered_);
99
100   uniquify (grobs_);
101 }
102
103 bool
104 Grob_array::empty () const
105 {
106   return grobs_.empty ();
107 }
108
109 void
110 Grob_array::set_array (vector<Grob *> const &src)
111 {
112   grobs_ = src;
113 }
114
115 const char Grob_array::type_p_name_[] = "ly:grob-array?";
116
117
118 SCM
119 grob_list_to_grob_array (SCM lst)
120 {
121   SCM arr_scm = Grob_array::make_array ();
122   Grob_array *ga = Grob_array::unsmob (arr_scm);
123   for (SCM s = lst; scm_is_pair (s); s = scm_cdr (s))
124     ga->add (Grob::unsmob (scm_car (s)));
125   return arr_scm;
126 }
127
128 SCM
129 grob_array_to_list (Grob_array *array)
130 {
131   SCM list = SCM_EOL;
132   SCM *tail = &list;
133
134   for (vsize i = 0; i < array->size (); i++)
135     {
136       *tail = scm_cons (array->grob (i)->self_scm (), SCM_EOL);
137       tail = SCM_CDRLOC (*tail);
138     }
139   return list;
140 }