lilypond-1.1.47
[lilypond.git] / flower / full-storage.cc
blobd144773e3e031c1fa916dc34a97794f051082397
1 /*
2 full-storage.cc -- implement Full_storage
4 source file of the Flower Library
6 (c) 1996, 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "full-storage.hh"
12 void
13 Full_storage::operator=(Full_storage const &fs)
15 resize (fs.height_i_, fs.width_i_);
16 OK();
17 fs.OK();
18 for (int i=0; i<height_i_; i++)
19 for (int j=0; j<width_i_; j++)
20 els_p_p_[i][j]= fs.els_p_p_[i][j];
24 void
25 Full_storage::OK() const
27 #ifndef NDEBUG
28 assert (max_height_i_ >= height_i_ && max_width_i_ >= width_i_);
29 assert (height_i_ >= 0 && width_i_ >= 0);
30 assert (els_p_p_||!max_height_i_);
31 #endif
37 Full_storage::~Full_storage()
39 for (int i=0; i < max_height_i_; i++)
40 delete [] els_p_p_[i];
41 delete[] els_p_p_;
44 void
45 Full_storage::resize (int rows, int cols)
47 OK();
48 resize_cols (rows);
49 resize_rows (cols);
50 band_i_ = rows >? cols;
53 void
54 Full_storage::delete_column (int k)
56 assert (0 <= k &&k<width_i_);
57 for (int i=0; i< height_i_ ; i++)
58 for (int j=k+1; j <width_i_; j++)
59 els_p_p_[i][j-1]=els_p_p_[i][j];
60 width_i_--;
64 void
65 Full_storage::delete_row (int k)
67 assert (0 <= k &&k<height_i_);
68 for (int i=k+1; i < height_i_ ; i++)
69 for (int j=0; j < width_i_; j++)
70 els_p_p_[i-1][j]=els_p_p_[i][j];
71 height_i_--;
76 void
77 Full_storage::insert_row (int k)
79 assert (0 <= k&& k <=height_i_);
80 resize_cols (height_i_+1);
81 for (int i=height_i_-1; i > k ; i--)
82 for (int j=0; j <width_i_; j++)
83 els_p_p_[i][j]=els_p_p_[i-1][j];
86 Array<Real>
87 Full_storage::row (int n) const
89 Array<Real> r;
90 for (int j = 0; j < cols(); j++)
91 r.push (elem (n,j));
92 return r;
95 Array<Real>
96 Full_storage::column (int n) const
98 Array<Real> r;
99 for (int i = 0; i < rows(); i++)
100 r.push (elem (i,n));
101 return r;
104 void
105 Full_storage::set_size (int rows, int cols)
107 resize (rows,cols);
110 void
111 Full_storage::set_size (int rows)
114 resize (rows);
119 void
120 Full_storage::resize_cols (int newh)
122 if (newh <= max_height_i_)
124 height_i_=newh;
125 return;
128 Real ** newa=new Real*[newh];
129 int j=0;
130 for (; j < height_i_; j++)
131 newa[j] = els_p_p_[j];
132 for (; j < newh; j++)
133 newa[j] = new Real[max_width_i_];
134 delete[] els_p_p_;
135 els_p_p_=newa;
137 height_i_ = max_height_i_ = newh;
142 void
143 Full_storage::resize_rows (int neww)
145 if (neww <= max_width_i_)
147 width_i_=neww;
148 return;
150 for (int i=0; i < max_height_i_ ; i++)
152 Real* newa = new Real[neww];
153 for (int k=0; k < width_i_; k++)
154 newa[k] = els_p_p_[i][k];
156 delete[] els_p_p_[i];
157 els_p_p_[i] = newa;
159 width_i_ = max_width_i_ = neww;
162 #ifdef INLINE
163 #undef INLINE
164 #endif
165 #define INLINE
168 #include "full-storage.icc"