]> git.donarmstrong.com Git - lilypond.git/blob - lily/p-col.cc
release: 0.0.74pre
[lilypond.git] / lily / p-col.cc
1 /*
2   p-col.cc -- implement PCol
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "p-col.hh"
10 #include "p-score.hh"
11
12 #include "debug.hh"
13
14 Interval
15 PCol::width() const
16 {
17     Interval w;
18
19     for (iter_top(its,i); i.ok(); i++)
20         w.unite(i->width());
21     if (w.empty_b())
22         w.unite(Interval(0,0));
23     return w;
24 }
25
26 void
27 PCol::clean_breakable_items()
28 {
29     if (!line_l_) {
30         its.junk_links();
31     }
32     if (prebreak_p_) 
33         prebreak_p_->clean_breakable_items();
34     if (postbreak_p_) 
35         postbreak_p_->clean_breakable_items();
36 }
37
38 int
39 PCol::rank_i() const
40 {
41     return rank_i_;
42 }
43
44 void
45 PCol::set_rank(int i)
46 {
47     rank_i_ = i;
48     if (prebreak_p_)
49         prebreak_p_->rank_i_ = i;
50     if (postbreak_p_)
51         postbreak_p_->rank_i_ = i;
52 }
53
54 void
55 PCol::print() const
56 {
57 #ifndef NPRINT
58     mtor << "PCol {";
59
60     mtor << "rank: " << rank_i_ << '\n';
61
62     mtor << "# symbols: " << its.size() ;
63     if (breakable_b()){
64         mtor << "\npre,post: ";
65         prebreak_p_->print();
66         postbreak_p_->print();
67     } else if (daddy_l_) {
68         mtor<<'\n' << ((this == daddy_l_->prebreak_p_) ?
69                        "prebreak" : "postbreak");
70         mtor << '\n';
71     }
72     mtor << "extent: " << width().str() << "\n";
73     mtor << "}\n";
74 #endif 
75 }
76
77 int
78 PCol::compare(PCol const &c1, PCol const &c2)
79 {
80     return c1.rank_i() - c2.rank_i();
81 }
82
83 void
84 PCol::OK() const
85 {
86 #ifndef NDEBUG
87     if (prebreak_p_ || postbreak_p_ ) {
88         assert(prebreak_p_&&postbreak_p_);
89         assert(prebreak_p_->daddy_l_ == this);
90         assert(postbreak_p_->daddy_l_ == this);
91     }
92 #endif
93 }
94
95 void
96 PCol::set_breakable()
97 {
98     if (breakable_b())
99         return;
100
101     prebreak_p_ = new PCol(this);
102     postbreak_p_ = new PCol(this);
103     prebreak_p_->pscore_l_ = pscore_l_;
104     postbreak_p_->pscore_l_ = pscore_l_;
105 }
106
107 bool
108 PCol::breakpoint_b() const
109 {
110     return !line_l_;
111 }
112
113 bool
114 PCol::breakable_b() const
115 {
116     return prebreak_p_||postbreak_p_;
117 }
118
119 PCol::PCol(PCol *parent)
120 {
121     used_b_ = false;
122     error_mark_b_ = false;
123     daddy_l_ = parent;
124     prebreak_p_=0;
125     postbreak_p_=0;
126     line_l_=0;
127     hpos = -1.0;
128     pscore_l_ = 0;
129     rank_i_ = -1;
130 }
131
132 PCol::~PCol()
133 {
134     delete prebreak_p_;
135     delete postbreak_p_;        
136 }
137
138 void
139 PCol::add( Item *i)
140 {
141     its.bottom().add(i);
142     i->pcol_l_ = this; 
143 }
144
145 bool
146 PCol::used_b()const
147 {
148     return breakable_b() || its.size()|| used_b_;
149 }