lilypond-1.1.23
[lilypond.git] / src / pcol.cc
blob4f1b65dcd716fe74d2a312475ab8671e3386a685
1 #include "pcol.hh"
2 #include "pscore.hh"
3 #include "pstaff.hh"
4 #include "debug.hh"
6 Interval
7 PCol::width() const
9 Interval w;
11 for (iter_top(its,i); i.ok(); i++)
12 w.unite(i->width());
13 if (w.empty())
14 w.unite(Interval(0,0));
15 return w;
18 int
19 PCol::rank() const
21 if(!pscore_l_)
22 return -1;
23 PCursor<PCol*> me=pscore_l_->find_col( (PCol*)this);
24 if (!me.ok())
25 return -1;
26 PCursor<PCol*> bot(pscore_l_->cols.top());
27 return me - bot;
30 void
31 PCol::print() const
33 #ifndef NPRINT
34 mtor << "PCol {";
36 if (rank() >= 0)
37 mtor << "rank: " << rank() << '\n';
39 mtor << "# symbols: " << its.size() ;
40 if (breakable_b()){
41 mtor << "\npre,post: ";
42 prebreak_p_->print();
43 postbreak_p_->print();
44 } else if (daddy_l_) {
45 mtor<<'\n' << ((this == daddy_l_->prebreak_p_) ?
46 "prebreak" : "postbreak");
47 mtor << '\n';
49 mtor << "extent: " << width().str() << "\n";
50 mtor << "}\n";
51 #endif
54 int
55 PCol::compare(const PCol &c1, const PCol &c2)
57 PScore*ps_l = c1.pscore_l_;
58 PCursor<PCol*> ac(ps_l->find_col(&c1));
59 PCursor<PCol*> bc(ps_l->find_col(&c2));
60 assert(ac.ok() && bc.ok());
61 return ac - bc;
64 void
65 PCol::OK() const
67 #ifndef NDEBUG
68 if (prebreak_p_ || postbreak_p_ ) {
69 assert(prebreak_p_&&postbreak_p_);
70 assert(prebreak_p_->daddy_l_ == this);
71 assert(postbreak_p_->daddy_l_ == this);
73 #endif
76 void
77 PCol::set_breakable()
79 if (breakable_b())
80 return;
82 prebreak_p_ = new PCol(this);
83 postbreak_p_ = new PCol(this);
84 prebreak_p_->pscore_l_ = pscore_l_;
85 postbreak_p_->pscore_l_ = pscore_l_;
88 bool
89 PCol::breakable_b() const
91 return prebreak_p_||postbreak_p_;
94 PCol::PCol(PCol *parent)
96 daddy_l_ = parent;
97 prebreak_p_=0;
98 postbreak_p_=0;
99 line_l_=0;
100 hpos = -1.0;
101 pscore_l_ = 0;
104 PCol::~PCol()
106 delete prebreak_p_;
107 delete postbreak_p_;
110 void
111 PCol::add( Item *i)
113 its.bottom().add(i);
114 i->pcol_l_ = this;
117 bool
118 PCol::used_b()const
120 return breakable_b() || its.size();