flower-1.0.2
[lilypond.git] / vsmat.hh
blob4e1ea797b635e7ec4181ad3cb17b06c01ea31a23
1 #ifndef VSMAT_HH
2 #define VSMAT_HH
3 #include "vray.hh"
4 #include "real.hh"
5 /// a matrix storage baseclass.
6 class virtual_smat {
9 public:
10 /// check invariants
11 virtual void OK() const=0;
13 /// height of matrix
14 virtual int rows() const = 0;
16 /// width of matrix
17 virtual int cols() const = 0;
19 /// set the size. contents lost
20 virtual void set_size(int i, int j) = 0;
21 /**
22 PRE
23 i >=0, j>=0
26 /// set the size to square dimen. contents lost
27 virtual void set_size(int i) = 0;
28 /**
29 PRE
30 i>=0
32 /// set the size to i
33 virtual void resize(int i, int j) = 0;
34 /**
36 keep contents. If enlarged contents unspecified
38 PRE
39 i>=0, j>=0
43 /// set the size to square dimen. contents kept
44 virtual void resize(int i) = 0;
45 /**
46 Keep contents. If enlarged contents are unspecified
48 PRE
49 i>=0
52 /// access an element
53 virtual Real& elem(int i,int j) = 0;
54 /**
55 access an element.
57 Generate an errormessage, if this happens
58 in the 0-part of a sparse matrix.
61 /// access a element, no modify
62 virtual const Real& elem(int i, int j) const = 0;
64 #if 1
65 virtual svec<Real> row(int i) const = 0;
66 virtual svec<Real> column(int j) const = 0;
67 #endif
69 /// add a row
70 virtual void insert_row(int k)=0;
71 /**
72 add a row to the matrix before row k. Contents
73 of added row are unspecified
75 0 <= k <= rows()
78 /// delete a row
79 virtual void delete_row(int k)=0;
80 /**
81 delete a row from this matrix.
83 PRE
84 0 <= k < rows();
86 virtual void delete_column(int k)=0;
87 virtual ~virtual_smat() { }
88 virtual virtual_smat *clone()=0;
91 /// is there a next?
92 virtual bool mult_ok(int i, int j) const=0;
93 /**
94 at end of matrix? when doing loop
96 for(i=0; i<h; i++)
97 for(j=0; j<w; j++)
98 ...
101 /// iterate
102 virtual void mult_next(int &i, int &j) const = 0;
104 walk through matrix (regular multiply)
105 get next j for row i, or get next row i and reset j.
106 this will make sparse matrix implementation easy.
109 mult_ok(i,j)
111 virtual bool trans_ok(int i, int j) const=0;
113 valid matrix entry. return false if at end of row
115 virtual void trans_next(int &i, int &j) const = 0;
117 walk through matrix (transposed multiply).
118 Get next i (for column j)
121 ver_ok(i,j)
124 /// generate a "Full_storage" matrix
125 static virtual_smat *get_full(int n, int m);
129 /** base class for interface with matrix storageclasses. There are no
130 iterators for matrixclasses, since matrices are (like arrays)
131 explicitly int-indexed.
133 Iteration is provided by *_next, *_ok, which update and check both
134 index variables simultaneously.
136 TODO
137 determine type of product matrix.
141 #endif