]> git.donarmstrong.com Git - lilypond.git/blob - lily/p-col.cc
release: 0.0.70pre
[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_) prebreak_p_->clean_breakable_items();
33     if (postbreak_p_) postbreak_p_->clean_breakable_items();
34 }
35
36 int
37 PCol::rank_i() const
38 {
39     assert(rank_i_ != -1);
40     return rank_i_;
41 }
42
43 void
44 PCol::set_rank(int i)
45 {
46     rank_i_ = i;
47     if (prebreak_p_)
48         prebreak_p_->rank_i_ = i;
49     if (postbreak_p_)
50         postbreak_p_->rank_i_ = i;
51 }
52
53 void
54 PCol::print() const
55 {
56 #ifndef NPRINT
57     mtor << "PCol {";
58
59     mtor << "rank: " << rank_i_ << '\n';
60
61     mtor << "# symbols: " << its.size() ;
62     if (breakable_b()){
63         mtor << "\npre,post: ";
64         prebreak_p_->print();
65         postbreak_p_->print();
66     } else if (daddy_l_) {
67         mtor<<'\n' << ((this == daddy_l_->prebreak_p_) ?
68                        "prebreak" : "postbreak");
69         mtor << '\n';
70     }
71     mtor << "extent: " << width().str() << "\n";
72     mtor << "}\n";
73 #endif 
74 }
75
76 int
77 PCol::compare(PCol const &c1, PCol const &c2)
78 {
79     return c1.rank_i() - c2.rank_i();
80 }
81
82 void
83 PCol::OK() const
84 {
85 #ifndef NDEBUG
86     if (prebreak_p_ || postbreak_p_ ) {
87         assert(prebreak_p_&&postbreak_p_);
88         assert(prebreak_p_->daddy_l_ == this);
89         assert(postbreak_p_->daddy_l_ == this);
90     }
91 #endif
92 }
93
94 void
95 PCol::set_breakable()
96 {
97     if (breakable_b())
98         return;
99
100     prebreak_p_ = new PCol(this);
101     postbreak_p_ = new PCol(this);
102     prebreak_p_->pscore_l_ = pscore_l_;
103     postbreak_p_->pscore_l_ = pscore_l_;
104 }
105
106 bool
107 PCol::breakpoint_b() const
108 {
109     return !line_l_;
110 }
111
112 bool
113 PCol::breakable_b() const
114 {
115     return prebreak_p_||postbreak_p_;
116 }
117
118 PCol::PCol(PCol *parent)
119 {
120     error_mark_b_ = false;
121     daddy_l_ = parent;
122     prebreak_p_=0;
123     postbreak_p_=0;
124     line_l_=0;
125     hpos = -1.0;
126     pscore_l_ = 0;
127     rank_i_ = -1;
128 }
129
130 PCol::~PCol()
131 {
132     delete prebreak_p_;
133     delete postbreak_p_;        
134 }
135
136 void
137 PCol::add( Item *i)
138 {
139     its.bottom().add(i);
140     i->pcol_l_ = this; 
141 }
142
143 bool
144 PCol::used_b()const
145 {
146     return breakable_b() || its.size();
147 }