]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/full-storage.hh
f9de76979c44bcf8d6bf2d13aeda479cac996f28
[lilypond.git] / flower / include / full-storage.hh
1 /*
2   full-storage.hh -- declare Full_storage
3
4   source file of the Flower Library
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9
10 #ifndef FULL_STORAGE_HH
11 #define FULL_STORAGE_HH
12
13 #include "array.hh"
14 #include "real.hh"
15
16 #ifndef INLINE
17 #define INLINE inline
18 #endif
19
20 /// simplest matrix storage. refer to its baseclass for the doco.
21 class Full_storage 
22 {
23   /// height, width
24   int height_i_;
25   int width_i_;
26   /// maxima.
27   int max_height_i_;
28   int max_width_i_;
29     
30   /// the storage
31   Real** els_p_p_;
32
33   INLINE void init() ;
34      
35   INLINE bool valid (int i, int j) const ; 
36
37   void resize_rows (int);
38   void resize_cols (int);
39
40 public:
41   int band_i_;                  // ugh
42
43   /// check invariants
44   void OK() const;
45     
46     /// height of matrix
47   INLINE int rows() const;
48
49   /// width of matrix
50   INLINE int cols() const;
51
52   /// size if square
53   INLINE int dim() const;
54       
55   /**  set the size. contents lost.       
56       PRE
57       i >=0, j>=0
58     */
59   void set_size (int rows, int cols) ;
60
61  
62   /**set the size to square dimen. contents lost
63       PRE
64       i>=0
65     */
66   void set_size (int i) ;
67   /**set the size to i.
68
69       keep contents. If enlarged contents unspecified
70         
71       PRE
72       i>=0, j>=0
73     
74     */
75   void resize (int rows, int cols);
76  
77   /**    
78     set the size to square dimen. contents kept
79     Keep contents. If enlarged contents are unspecified
80     
81     PRE
82     i>=0  
83     */
84   void resize (int i);
85   
86     
87   /**
88     access an element.
89
90     Generate an errormessage, if this happens
91     in the 0-part of a sparse matrix.
92     */
93
94   INLINE Real& elem (int i,int j);
95
96   /// access a element, no modify
97   INLINE Real elem (int i, int j) const;
98
99   Array<Real> row (int i) const ;
100   Array<Real> column (int j) const;
101
102     
103   /**
104     add a row to the matrix before  row k. Contents
105     of added row are unspecified
106
107       0 <= k <= rows()
108     */
109   void insert_row (int k);
110
111     
112   /**
113       delete a row from this matrix.
114
115       PRE
116       0 <= k < rows();
117     */
118   void delete_row (int k);
119   void delete_column (int k);
120
121
122     
123     /**
124       at end of matrix?. when doing loop
125
126       for (i=0; i<h; i++)
127         for (j=0; j<w; j++)
128           ..
129
130     */
131   INLINE bool mult_ok (int i, int j) const;
132
133   /**
134       walk through matrix (regular multiply).
135       get next j for row i, or get next row i and reset j.
136       this will make sparse matrix implementation easy.
137     
138       PRE
139       mult_ok (i,j)
140      */
141   INLINE void mult_next (int &i, int &j) const;
142
143   /**
144       valid matrix entry. return false if at end of row
145     */
146   INLINE bool trans_ok (int i, int j) const;
147
148   /**
149       walk through matrix (transposed multiply).
150       Get next i (for column j)
151     
152       PRE
153       ver_ok (i,j)
154      */
155
156   INLINE void trans_next (int &i, int &j) const;
157
158   INLINE Full_storage();
159   INLINE Full_storage (int i, int j);
160   INLINE Full_storage (Full_storage const&);
161   INLINE Full_storage (int i);
162   void operator=(Full_storage const &);
163     
164     
165   ~Full_storage();
166 };
167
168 #include "full-storage.icc"
169
170
171 #endif // FULL_STORAGE_HH