]> git.donarmstrong.com Git - lilypond.git/blob - src/pcol.cc
release: 0.0.22
[lilypond.git] / src / pcol.cc
1 #include "pcol.hh"
2 #include "pscore.hh"
3 #include "pstaff.hh"
4 #include "debug.hh"
5
6 Interval
7 PCol::width() const
8 {
9     Interval w;
10
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;
16 }
17
18 int
19 PCol::rank() const
20 {
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;
28 }
29
30 void
31 PCol::print() const
32 {
33 #ifndef NPRINT
34     mtor << "PCol {";
35
36     if (rank() >= 0)
37         mtor << "rank: " << rank() << '\n';
38
39     mtor << "# symbols: " << its.size() ;
40     if (breakable()){
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_p_" : "postbreak");
47     }
48     mtor << "extent: " << width().str() << "\n";
49     mtor << "}\n";
50 #endif 
51 }
52
53 int
54 PCol::compare(const PCol &c1, const PCol &c2)
55 {
56     PScore*ps_l = c1.pscore_l_;
57     PCursor<PCol*> ac(ps_l->find_col(&c1));
58     PCursor<PCol*> bc(ps_l->find_col(&c2));
59     assert(ac.ok() && bc.ok());
60     return ac - bc;
61 }
62
63 void
64 PCol::OK() const
65 {
66 #ifndef NDEBUG
67     if (prebreak_p_ || postbreak_p_ ) {
68         assert(prebreak_p_&&postbreak_p_);
69         assert(prebreak_p_->daddy_l_ == this);
70         assert(postbreak_p_->daddy_l_ == this);
71     }
72 #endif
73 }
74
75 void
76 PCol::set_breakable()
77 {
78     if (breakable())
79         return;
80
81     prebreak_p_ = new PCol(this);
82     postbreak_p_ = new PCol(this);
83     prebreak_p_->pscore_l_ = pscore_l_;
84     postbreak_p_->pscore_l_ = pscore_l_;
85 }
86
87 bool
88 PCol::breakable() const
89 {
90     return prebreak_p_||postbreak_p_;
91 }
92
93 PCol::PCol(PCol *parent)
94 {
95     daddy_l_ = parent;
96     prebreak_p_=0;
97     postbreak_p_=0;
98     line_l_=0;
99  
100     pscore_l_ = 0;
101 }
102
103 PCol::~PCol()
104 {
105     delete prebreak_p_;
106     delete postbreak_p_;        
107 }
108
109 void
110 PCol::add( Item *i)
111 {
112     its.bottom().add(i);
113     i->pcol_l_ = this; 
114 }
115
116 bool
117 PCol::used()const
118 {
119     return breakable() || its.size();
120 }