]> git.donarmstrong.com Git - lilypond.git/blob - flower/tvsmat.hh
release: 0.0.2
[lilypond.git] / flower / tvsmat.hh
1 #ifndef VSMAT_HH
2 #define VSMAT_HH
3 #include "vray.hh"
4
5 /// a  matrix storage baseclass.
6 class virtual_smat {
7     
8
9 public:
10     /// check invariants
11     virtual void OK() const=0;
12     
13     /// height of matrix
14     virtual int rows() const = 0;
15
16     /// width of matrix
17     virtual int cols() const = 0;
18     
19     /// set the size. contents lost
20     virtual void set_size(int i, int j) = 0;
21     /**      
22       PRE
23       i >=0, j>=0
24     */
25     
26     /// set the size to square dimen. contents lost
27     virtual void set_size(int i) = 0;
28     /**
29       PRE
30       i>=0
31     */
32     /// set the size to i
33     virtual void resize(int i, int j) = 0;
34     /**
35
36       keep contents. If enlarged contents unspecified
37         
38       PRE
39       i>=0, j>=0
40     
41     */
42
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
47     
48     PRE
49     i>=0  
50     */
51     
52     /// access an element
53     virtual Real& elem(int i,int j) = 0;
54     /**
55     access an element.
56
57     Generate an errormessage, if this happens
58     in the 0-part of a sparse matrix.
59     */
60
61     /// access a element, no modify
62     virtual const Real& elem(int i, int j) const = 0;
63
64 #if 1
65     virtual svec<Real> row(int i) const = 0;
66     virtual svec<Real> column(int j) const = 0;
67 #endif
68
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
74
75       0 <= k <= rows()
76     */
77
78     /// delete a row 
79     virtual void delete_row(int k)=0;
80       /**
81       delete a row from this matrix.
82
83       PRE
84       0 <= k < rows();
85     */
86     virtual ~virtual_smat() { }
87     virtual virtual_smat *clone()=0;
88
89
90     /// is there a next?
91     virtual bool mult_ok(int i, int j) const=0;
92     /**
93       at end of matrix? when doing loop
94
95       for(i=0; i<h; i++)
96         for(j=0; j<w; j++)
97           ...
98
99     */
100     /// iterate
101     virtual void mult_next(int &i, int &j) const  = 0;
102     /**
103       walk through matrix (regular multiply)
104       get next j for row i, or get next row i and reset j.
105       this will make sparse matrix implementation easy.
106     
107       PRE
108       mult_ok(i,j)
109      */
110     virtual bool trans_ok(int i, int j) const=0;
111     /**
112       valid matrix entry. return false if at end of row
113     */
114     virtual void trans_next(int &i, int &j) const  = 0;
115     /**
116       walk through matrix (transposed multiply).
117       Get next i (for column j)
118     
119       PRE
120       ver_ok(i,j)
121      */
122
123     /// generate a "Full_storage" matrix    
124     virtual_smat<Real> *get_full(int n, int m);
125
126 };
127     
128 /** base class for interface with matrix storageclasses.  There are no
129     iterators for matrixclasses, since matrices are (like arrays)
130     explicitly int-indexed.
131
132     Iteration is provided by *_next, *_ok, which update and check both
133     index variables simultaneously.
134
135     TODO
136     determine type of product matrix.
137
138 */
139
140 #endif