lilypond-0.0.32
[lilypond.git] / flower / vsmat.hh
blob283b1e567b524375a4d17926475cd93229aa9bf7
1 #ifndef VSMAT_HH
2 #define VSMAT_HH
3 #include "varray.hh"
4 #include "real.hh"
5 /** base class for interface with matrix storageclasses. There are no
6 iterators for matrixclasses, since matrices are (like arrays)
7 explicitly int-indexed.
9 Iteration is provided by *_next, *_ok, which update and check both
10 index variables simultaneously.
12 TODO
13 determine type of product matrix.
16 class virtual_smat {
19 public:
20 /// check invariants
21 virtual void OK() const=0;
23 /// height of matrix
24 virtual int rows() const = 0;
26 /// width of matrix
27 virtual int cols() const = 0;
30 /** set the size. contents lost.
31 PRE
32 i >=0, j>=0
34 virtual void set_size(int i, int j) = 0;
36 /**set the size to square dimen. contents lost
37 PRE
38 i>=0
40 virtual void set_size(int i) = 0;
41 /**set the size to i.
43 keep contents. If enlarged contents unspecified
45 PRE
46 i>=0, j>=0
49 virtual void resize(int i, int j) = 0;
51 /**
52 set the size to square dimen. contents kept
53 Keep contents. If enlarged contents are unspecified
55 PRE
56 i>=0
58 virtual void resize(int i) = 0;
61 /**
62 access an element.
64 Generate an errormessage, if this happens
65 in the 0-part of a sparse matrix.
68 virtual Real& elem(int i,int j) = 0;
70 /// access a element, no modify
71 virtual const Real& elem(int i, int j) const = 0;
73 #if 1
74 virtual Array<Real> row(int i) const = 0;
75 virtual Array<Real> column(int j) const = 0;
76 #endif
79 /**
80 add a row to the matrix before row k. Contents
81 of added row are unspecified
83 0 <= k <= rows()
85 virtual void insert_row(int k)=0;
88 /**
89 delete a row from this matrix.
91 PRE
92 0 <= k < rows();
94 virtual void delete_row(int k)=0;
95 virtual void delete_column(int k)=0;
96 virtual ~virtual_smat() { }
97 virtual virtual_smat *clone()=0;
102 at end of matrix?. when doing loop
104 for(i=0; i<h; i++)
105 for(j=0; j<w; j++)
109 virtual bool mult_ok(int i, int j) const=0;
112 walk through matrix (regular multiply).
113 get next j for row i, or get next row i and reset j.
114 this will make sparse matrix implementation easy.
117 mult_ok(i,j)
119 virtual void mult_next(int &i, int &j) const = 0;
122 valid matrix entry. return false if at end of row
124 virtual bool trans_ok(int i, int j) const=0;
127 walk through matrix (transposed multiply).
128 Get next i (for column j)
131 ver_ok(i,j)
134 virtual void trans_next(int &i, int &j) const = 0;
135 /// generate a "Full_storage" matrix
136 static virtual_smat *get_full(int n, int m);
141 #endif