]> git.donarmstrong.com Git - lilypond.git/blob - flower/full-storage.cc
release: 0.1.61
[lilypond.git] / flower / full-storage.cc
1 /*
2   full-storage.cc -- implement Full_storage
3
4   source file of the Flower Library
5
6   (c) 1996, 1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "full-storage.hh"
10
11
12 void
13 Full_storage::operator=(Full_storage const &fs)
14 {
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];
21 }
22
23
24 void
25 Full_storage::OK() const
26 {
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
32 }
33
34
35
36
37 Full_storage::~Full_storage() 
38 {
39   for (int i=0; i < max_height_i_; i++)
40     delete [] els_p_p_[i];
41   delete[] els_p_p_;
42 }
43
44 void
45 Full_storage::resize (int rows, int cols)
46 {
47   OK();
48   resize_cols (rows);
49   resize_rows (cols);
50   band_i_ = rows >? cols;
51 }
52
53 void
54 Full_storage::delete_column (int k)
55 {
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_--;
61 }
62
63
64 void
65 Full_storage::delete_row (int k)
66 {
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_--;
72 }
73
74
75
76 void
77 Full_storage::insert_row (int k)
78 {
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];
84
85 }
86 Array<Real>
87 Full_storage::row (int n) const
88 {
89   Array<Real> r;
90   for (int j = 0; j < cols(); j++)
91     r.push (elem (n,j));
92   return r;
93 }
94
95 Array<Real>
96 Full_storage::column (int n) const
97 {
98   Array<Real> r;
99   for (int i = 0; i < rows(); i++)
100     r.push (elem (i,n));
101   return r;
102 }
103
104 void
105 Full_storage::set_size (int rows, int cols)
106 {
107   resize (rows,cols);
108 }
109         
110 void
111 Full_storage::set_size (int rows)
112 {
113       
114   resize (rows);
115 }
116         
117
118
119 void
120 Full_storage::resize_cols (int newh)
121 {
122   if (newh <= max_height_i_) 
123     {
124       height_i_=newh;
125       return;
126     }
127    
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;
136
137   height_i_ = max_height_i_ = newh;
138 }
139
140
141
142 void
143 Full_storage::resize_rows (int neww)
144 {
145   if (neww <= max_width_i_) 
146     {
147       width_i_=neww;
148       return;
149     }
150   for (int i=0; i < max_height_i_ ; i++) 
151     {
152       Real* newa = new Real[neww];
153       for (int k=0; k < width_i_; k++)
154         newa[k] = els_p_p_[i][k];
155
156       delete[] els_p_p_[i];
157       els_p_p_[i] = newa;
158     }
159   width_i_ = max_width_i_ = neww;       
160 }
161
162 #ifdef INLINE
163 #undef INLINE
164 #endif
165 #define INLINE
166
167
168 #include "full-storage.icc"