| 1 | //
 | 
|---|
| 2 | // block.h
 | 
|---|
| 3 | //
 | 
|---|
| 4 | // Copyright (C) 1996 Limit Point Systems, Inc.
 | 
|---|
| 5 | //
 | 
|---|
| 6 | // Author: Curtis Janssen <cljanss@limitpt.com>
 | 
|---|
| 7 | // Maintainer: LPS
 | 
|---|
| 8 | //
 | 
|---|
| 9 | // This file is part of the SC Toolkit.
 | 
|---|
| 10 | //
 | 
|---|
| 11 | // The SC Toolkit is free software; you can redistribute it and/or modify
 | 
|---|
| 12 | // it under the terms of the GNU Library General Public License as published by
 | 
|---|
| 13 | // the Free Software Foundation; either version 2, or (at your option)
 | 
|---|
| 14 | // any later version.
 | 
|---|
| 15 | //
 | 
|---|
| 16 | // The SC Toolkit is distributed in the hope that it will be useful,
 | 
|---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
| 19 | // GNU Library General Public License for more details.
 | 
|---|
| 20 | //
 | 
|---|
| 21 | // You should have received a copy of the GNU Library General Public License
 | 
|---|
| 22 | // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
 | 
|---|
| 23 | // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 | 
|---|
| 24 | //
 | 
|---|
| 25 | // The U.S. Government is granted a limited license as per AL 91-7.
 | 
|---|
| 26 | //
 | 
|---|
| 27 | 
 | 
|---|
| 28 | #ifndef _math_scmat_block_h
 | 
|---|
| 29 | #define _math_scmat_block_h
 | 
|---|
| 30 | 
 | 
|---|
| 31 | #ifdef __GNUC__
 | 
|---|
| 32 | #pragma interface
 | 
|---|
| 33 | #endif
 | 
|---|
| 34 | 
 | 
|---|
| 35 | #include <util/state/state.h>
 | 
|---|
| 36 | 
 | 
|---|
| 37 | namespace sc {
 | 
|---|
| 38 | 
 | 
|---|
| 39 | class SCElementOp;
 | 
|---|
| 40 | class SCElementOp2;
 | 
|---|
| 41 | class SCElementOp3;
 | 
|---|
| 42 | 
 | 
|---|
| 43 | /** SCMatrixBlock is the base clase for all types of blocks
 | 
|---|
| 44 |     that comprise matrices and vectors. */
 | 
|---|
| 45 | class SCMatrixBlock: public SavableState {
 | 
|---|
| 46 |   public:
 | 
|---|
| 47 |     int blocki, blockj;
 | 
|---|
| 48 |   public:
 | 
|---|
| 49 |     SCMatrixBlock();
 | 
|---|
| 50 |     SCMatrixBlock(StateIn&s);
 | 
|---|
| 51 |     virtual ~SCMatrixBlock();
 | 
|---|
| 52 |     void save_data_state(StateOut&s);
 | 
|---|
| 53 | 
 | 
|---|
| 54 |     /** Return of copy of this.  A runtime error will be generated
 | 
|---|
| 55 |         for blocks that cannot do a deepcopy.  These routines are only used
 | 
|---|
| 56 |         internally in the matrix library. */
 | 
|---|
| 57 |     virtual SCMatrixBlock *deepcopy() const;
 | 
|---|
| 58 | 
 | 
|---|
| 59 |     /** Return a pointer to the block's data and the number of elements
 | 
|---|
| 60 |         in the block.  Some blocks cannot provide this information and
 | 
|---|
| 61 |         a runtime error will be generated if these members are called.
 | 
|---|
| 62 |         These routines are only used internally in the matrix library. */
 | 
|---|
| 63 |     virtual double *dat();
 | 
|---|
| 64 |     virtual int ndat() const;
 | 
|---|
| 65 | 
 | 
|---|
| 66 |     // These routines are obsolete.
 | 
|---|
| 67 |     virtual void process(SCElementOp*) = 0;
 | 
|---|
| 68 |     virtual void process(SCElementOp2*, SCMatrixBlock*) = 0;
 | 
|---|
| 69 |     virtual void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*) = 0;
 | 
|---|
| 70 | };
 | 
|---|
| 71 | 
 | 
|---|
| 72 | 
 | 
|---|
| 73 | class SCMatrixBlockListLink {
 | 
|---|
| 74 |   private:
 | 
|---|
| 75 |     void operator = (const SCMatrixBlockListLink&) {}  // disallowed
 | 
|---|
| 76 |     SCMatrixBlock* _block;
 | 
|---|
| 77 |     SCMatrixBlockListLink* _next;
 | 
|---|
| 78 |   public:
 | 
|---|
| 79 |     SCMatrixBlockListLink(SCMatrixBlock*, SCMatrixBlockListLink* = 0);
 | 
|---|
| 80 |     ~SCMatrixBlockListLink();
 | 
|---|
| 81 |     void block(SCMatrixBlock*);
 | 
|---|
| 82 |     void next(SCMatrixBlockListLink* link) { _next = link; }
 | 
|---|
| 83 |     SCMatrixBlock* block() { return _block; }
 | 
|---|
| 84 |     SCMatrixBlockListLink* next() { return _next; }
 | 
|---|
| 85 | };
 | 
|---|
| 86 | 
 | 
|---|
| 87 | class SCMatrixBlockListIter {
 | 
|---|
| 88 |   private:
 | 
|---|
| 89 |     SCMatrixBlockListLink* link;
 | 
|---|
| 90 |   public:
 | 
|---|
| 91 |     SCMatrixBlockListIter(): link(0) {}
 | 
|---|
| 92 |     SCMatrixBlockListIter(SCMatrixBlockListLink*l): link(l) {}
 | 
|---|
| 93 |     int operator !=(const SCMatrixBlockListIter p) const {
 | 
|---|
| 94 |         return link != p.link;
 | 
|---|
| 95 |       }
 | 
|---|
| 96 |     void operator ++() { link = link->next(); }
 | 
|---|
| 97 |     void operator ++(int) { link = link->next(); }
 | 
|---|
| 98 |     SCMatrixBlock* block() const { return link->block(); }
 | 
|---|
| 99 | };
 | 
|---|
| 100 | 
 | 
|---|
| 101 | class SCMatrixBlockList: public SavableState {
 | 
|---|
| 102 |   private:
 | 
|---|
| 103 |     SCMatrixBlockListLink* _begin;
 | 
|---|
| 104 |   public:
 | 
|---|
| 105 |     SCMatrixBlockList();
 | 
|---|
| 106 |     SCMatrixBlockList(StateIn&);
 | 
|---|
| 107 |     ~SCMatrixBlockList();
 | 
|---|
| 108 |     void save_data_state(StateOut&);
 | 
|---|
| 109 |     void insert(SCMatrixBlock*);
 | 
|---|
| 110 |     void append(SCMatrixBlock*);
 | 
|---|
| 111 |     SCMatrixBlockListIter begin() { return _begin; }
 | 
|---|
| 112 |     SCMatrixBlockListIter end() { return 0; }
 | 
|---|
| 113 |     SCMatrixBlockList *deepcopy();
 | 
|---|
| 114 | };
 | 
|---|
| 115 | 
 | 
|---|
| 116 | 
 | 
|---|
| 117 | /** The SCVectorSimpleBlock describes a piece of a
 | 
|---|
| 118 | vector.  The following bit of code illustrates the data layout:
 | 
|---|
| 119 | fill(double *vector, SCVectorSimpleBlock &b)
 | 
|---|
| 120 | {
 | 
|---|
| 121 |   int i,offset=0;
 | 
|---|
| 122 |   for (i=b.istart; i<b.iend; i++,offset++) {
 | 
|---|
| 123 |       vector[i] = b.data[offset];
 | 
|---|
| 124 |   }
 | 
|---|
| 125 | }
 | 
|---|
| 126 | */
 | 
|---|
| 127 | class SCVectorSimpleBlock: public SCMatrixBlock {
 | 
|---|
| 128 |   public:
 | 
|---|
| 129 |     SCVectorSimpleBlock(int istart,int iend);
 | 
|---|
| 130 |     SCVectorSimpleBlock(StateIn&);
 | 
|---|
| 131 |     virtual ~SCVectorSimpleBlock();
 | 
|---|
| 132 |     void save_data_state(StateOut&);
 | 
|---|
| 133 |     int istart;
 | 
|---|
| 134 |     int iend;
 | 
|---|
| 135 |     double* data;
 | 
|---|
| 136 | 
 | 
|---|
| 137 |     SCMatrixBlock *deepcopy() const;
 | 
|---|
| 138 | 
 | 
|---|
| 139 |     void process(SCElementOp*);
 | 
|---|
| 140 |     void process(SCElementOp2*, SCMatrixBlock*);
 | 
|---|
| 141 |     void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
 | 
|---|
| 142 | 
 | 
|---|
| 143 |     double *dat();
 | 
|---|
| 144 |     int ndat() const;
 | 
|---|
| 145 | };
 | 
|---|
| 146 | 
 | 
|---|
| 147 | 
 | 
|---|
| 148 | /** The SCVectorSimpleSubBlock describes a subblock of a
 | 
|---|
| 149 | vector.  The following bit of code illustrates the data layout:
 | 
|---|
| 150 | fill(double *vector, SCVectorSimpleSubBlock &b)
 | 
|---|
| 151 | {
 | 
|---|
| 152 |   int i,offset=b.offset;
 | 
|---|
| 153 |   for (i=b.istart; i<b.iend; i++,offset++) {
 | 
|---|
| 154 |       vector[i] = b.data[offset];
 | 
|---|
| 155 |   }
 | 
|---|
| 156 | }
 | 
|---|
| 157 | */
 | 
|---|
| 158 | class SCVectorSimpleSubBlock: public SCMatrixBlock {
 | 
|---|
| 159 |   public:
 | 
|---|
| 160 |     SCVectorSimpleSubBlock(int istart,int iend, int offset, double* data);
 | 
|---|
| 161 |     SCVectorSimpleSubBlock(StateIn&);
 | 
|---|
| 162 |     virtual ~SCVectorSimpleSubBlock();
 | 
|---|
| 163 |     void save_data_state(StateOut&);
 | 
|---|
| 164 |     int istart;
 | 
|---|
| 165 |     int iend;
 | 
|---|
| 166 |     int offset;
 | 
|---|
| 167 |     double* data;
 | 
|---|
| 168 | 
 | 
|---|
| 169 |     void process(SCElementOp*);
 | 
|---|
| 170 |     void process(SCElementOp2*, SCMatrixBlock*);
 | 
|---|
| 171 |     void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
 | 
|---|
| 172 | };
 | 
|---|
| 173 | 
 | 
|---|
| 174 | 
 | 
|---|
| 175 | /** The SCMatrixRectBlock describes a rectangular piece of a
 | 
|---|
| 176 | matrix.  The following bit of code illustrates the data layout:
 | 
|---|
| 177 | fill(double **matrix, SCMatrixRectBlock &b)
 | 
|---|
| 178 | {
 | 
|---|
| 179 |   int offset=0;
 | 
|---|
| 180 |   for (int i=b.istart; i<b.iend; i++) {
 | 
|---|
| 181 |     for (int j=b.jstart; j<b.jend; j++,offset++) {
 | 
|---|
| 182 |       matrix[i][j] = b.data[offset];
 | 
|---|
| 183 |     }
 | 
|---|
| 184 |   }
 | 
|---|
| 185 | }
 | 
|---|
| 186 | */
 | 
|---|
| 187 | class SCMatrixRectBlock: public SCMatrixBlock {
 | 
|---|
| 188 |   public:
 | 
|---|
| 189 |     SCMatrixRectBlock(int is, int ie, int js, int je);
 | 
|---|
| 190 |     SCMatrixRectBlock(StateIn&);
 | 
|---|
| 191 |     virtual ~SCMatrixRectBlock();
 | 
|---|
| 192 |     void save_data_state(StateOut&);
 | 
|---|
| 193 |     int istart;
 | 
|---|
| 194 |     int jstart;
 | 
|---|
| 195 |     int iend;
 | 
|---|
| 196 |     int jend;
 | 
|---|
| 197 |     double* data;
 | 
|---|
| 198 | 
 | 
|---|
| 199 |     SCMatrixBlock *deepcopy() const;
 | 
|---|
| 200 | 
 | 
|---|
| 201 |     void process(SCElementOp*);
 | 
|---|
| 202 |     void process(SCElementOp2*, SCMatrixBlock*);
 | 
|---|
| 203 |     void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
 | 
|---|
| 204 | 
 | 
|---|
| 205 |     double *dat();
 | 
|---|
| 206 |     int ndat() const;
 | 
|---|
| 207 | };
 | 
|---|
| 208 | 
 | 
|---|
| 209 | 
 | 
|---|
| 210 | /** The SCMatrixRectSubBlock describes a rectangular piece of a
 | 
|---|
| 211 | matrix.  The following bit of code illustrates the data layout:
 | 
|---|
| 212 | fill(double **matrix, SCMatrixRectSubBlock &b)
 | 
|---|
| 213 | {
 | 
|---|
| 214 |   int offset=b.istart * b.istride + b.jstart;
 | 
|---|
| 215 |   for (int i=b.istart; i<b.iend; i++) {
 | 
|---|
| 216 |     for (int j=b.jstart; j<b.jend; j++,offset++) {
 | 
|---|
| 217 |       matrix[i][j] = b.data[offset];
 | 
|---|
| 218 |     }
 | 
|---|
| 219 |   offset += b.istride - (b.jend - b.jstart);
 | 
|---|
| 220 |   }
 | 
|---|
| 221 | }
 | 
|---|
| 222 | */
 | 
|---|
| 223 | class SCMatrixRectSubBlock: public SCMatrixBlock {
 | 
|---|
| 224 |   public:
 | 
|---|
| 225 |     SCMatrixRectSubBlock(int is, int ie, int istride, int js, int je,
 | 
|---|
| 226 |                          double* data);
 | 
|---|
| 227 |     SCMatrixRectSubBlock(StateIn&);
 | 
|---|
| 228 |     // does not delete the data member
 | 
|---|
| 229 |     virtual ~SCMatrixRectSubBlock();
 | 
|---|
| 230 |     // does not save the data member
 | 
|---|
| 231 |     void save_data_state(StateOut&);
 | 
|---|
| 232 |     int istart;
 | 
|---|
| 233 |     int jstart;
 | 
|---|
| 234 |     int iend;
 | 
|---|
| 235 |     int jend;
 | 
|---|
| 236 |     int istride;
 | 
|---|
| 237 |     double* data;
 | 
|---|
| 238 | 
 | 
|---|
| 239 |     void process(SCElementOp*);
 | 
|---|
| 240 |     void process(SCElementOp2*, SCMatrixBlock*);
 | 
|---|
| 241 |     void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
 | 
|---|
| 242 | };
 | 
|---|
| 243 | 
 | 
|---|
| 244 | 
 | 
|---|
| 245 | /** The SCMatrixLTriBlock describes a triangular piece of a
 | 
|---|
| 246 | matrix.  The following bit of code illustrates the data layout:
 | 
|---|
| 247 | fill(double **matrix, SCMatrixLTriBlock &b)
 | 
|---|
| 248 | {
 | 
|---|
| 249 |   int offset=0;
 | 
|---|
| 250 |   for (int i=b.start; i<b.end; i++) {
 | 
|---|
| 251 |     for (int j=b.start; j<=i; j++,offset++) {
 | 
|---|
| 252 |       matrix[i][j] = b.data[offset];
 | 
|---|
| 253 |     }
 | 
|---|
| 254 |   }
 | 
|---|
| 255 | }
 | 
|---|
| 256 | */
 | 
|---|
| 257 | class SCMatrixLTriBlock: public SCMatrixBlock {
 | 
|---|
| 258 |   public:
 | 
|---|
| 259 |     SCMatrixLTriBlock(int s,int e);
 | 
|---|
| 260 |     SCMatrixLTriBlock(StateIn&);
 | 
|---|
| 261 |     virtual ~SCMatrixLTriBlock();
 | 
|---|
| 262 |     void save_data_state(StateOut&);
 | 
|---|
| 263 |     int start;
 | 
|---|
| 264 |     int end;
 | 
|---|
| 265 |     double* data;
 | 
|---|
| 266 | 
 | 
|---|
| 267 |     SCMatrixBlock *deepcopy() const;
 | 
|---|
| 268 | 
 | 
|---|
| 269 |     void process(SCElementOp*);
 | 
|---|
| 270 |     void process(SCElementOp2*, SCMatrixBlock*);
 | 
|---|
| 271 |     void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
 | 
|---|
| 272 | 
 | 
|---|
| 273 |     double *dat();
 | 
|---|
| 274 |     int ndat() const;
 | 
|---|
| 275 | };
 | 
|---|
| 276 | 
 | 
|---|
| 277 | 
 | 
|---|
| 278 | /** The SCMatrixLTriSubBlock describes a triangular subblock of a
 | 
|---|
| 279 | matrix.  The following bit of code illustrates the data layout:
 | 
|---|
| 280 | fill(double **matrix, SCMatrixLTriSubBlock &b)
 | 
|---|
| 281 | {
 | 
|---|
| 282 |   int offset=(b.istart*(b.istart+1)>>1) + b.jstart;
 | 
|---|
| 283 |   for (int i=b.start; i<b.end; i++) {
 | 
|---|
| 284 |     for (int j=b.start; j<=i && j<b.jend; j++,offset++) {
 | 
|---|
| 285 |       matrix[i][j] = b.data[offset];
 | 
|---|
| 286 |     }
 | 
|---|
| 287 |   if (j>i) offset += b.istart;
 | 
|---|
| 288 |   else offset += i + b.jstart - b.jend;
 | 
|---|
| 289 |   }
 | 
|---|
| 290 | }
 | 
|---|
| 291 | */
 | 
|---|
| 292 | class SCMatrixLTriSubBlock: public SCMatrixBlock {
 | 
|---|
| 293 |   public:
 | 
|---|
| 294 |     SCMatrixLTriSubBlock(int is,int ie,int js,int je,double*data);
 | 
|---|
| 295 |     SCMatrixLTriSubBlock(StateIn&);
 | 
|---|
| 296 |     // does not delete the data member
 | 
|---|
| 297 |     virtual ~SCMatrixLTriSubBlock();
 | 
|---|
| 298 |     // does not save the data member
 | 
|---|
| 299 |     void save_data_state(StateOut&);
 | 
|---|
| 300 |     int istart;
 | 
|---|
| 301 |     int iend;
 | 
|---|
| 302 |     int jstart;
 | 
|---|
| 303 |     int jend;
 | 
|---|
| 304 |     double* data;
 | 
|---|
| 305 | 
 | 
|---|
| 306 |     void process(SCElementOp*);
 | 
|---|
| 307 |     void process(SCElementOp2*, SCMatrixBlock*);
 | 
|---|
| 308 |     void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
 | 
|---|
| 309 | };
 | 
|---|
| 310 | 
 | 
|---|
| 311 | 
 | 
|---|
| 312 | /** The SCMatrixDiagBlock describes a diagonal piece of a
 | 
|---|
| 313 | matrix.  The following bit of code illustrates the data layout:
 | 
|---|
| 314 | fill(double **matrix, SCMatrixDiagBlock &b)
 | 
|---|
| 315 | {
 | 
|---|
| 316 |   int i,j,offset=0;
 | 
|---|
| 317 |   for (i=b.istart,j=b.jstart; i<b.iend; i++,j++,offset++) {
 | 
|---|
| 318 |       matrix[i][j] = b.data[offset];
 | 
|---|
| 319 |   }
 | 
|---|
| 320 | }
 | 
|---|
| 321 | */
 | 
|---|
| 322 | class SCMatrixDiagBlock: public SCMatrixBlock {
 | 
|---|
| 323 |   public:
 | 
|---|
| 324 |     SCMatrixDiagBlock(int istart,int iend,int jstart);
 | 
|---|
| 325 |     SCMatrixDiagBlock(int istart,int iend);
 | 
|---|
| 326 |     SCMatrixDiagBlock(StateIn&);
 | 
|---|
| 327 |     virtual ~SCMatrixDiagBlock();
 | 
|---|
| 328 |     void save_data_state(StateOut&);
 | 
|---|
| 329 |     int istart;
 | 
|---|
| 330 |     int jstart;
 | 
|---|
| 331 |     int iend;
 | 
|---|
| 332 |     double* data;
 | 
|---|
| 333 | 
 | 
|---|
| 334 |     SCMatrixBlock *deepcopy() const;
 | 
|---|
| 335 | 
 | 
|---|
| 336 |     void process(SCElementOp*);
 | 
|---|
| 337 |     void process(SCElementOp2*, SCMatrixBlock*);
 | 
|---|
| 338 |     void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
 | 
|---|
| 339 | 
 | 
|---|
| 340 |     double *dat();
 | 
|---|
| 341 |     int ndat() const;
 | 
|---|
| 342 | };
 | 
|---|
| 343 | 
 | 
|---|
| 344 | 
 | 
|---|
| 345 | /** The SCMatrixDiagSubBlock describes a diagonal subblock of a
 | 
|---|
| 346 | matrix.  The following bit of code illustrates the data layout:
 | 
|---|
| 347 | fill(double **matrix, SCMatrixDiagSubBlock &b)
 | 
|---|
| 348 | {
 | 
|---|
| 349 |   int i,j,offset=b.offset;
 | 
|---|
| 350 |   for (i=b.istart,j=b.jstart; i<b.iend; i++,j++,offset++) {
 | 
|---|
| 351 |       matrix[i][j] = b.data[offset];
 | 
|---|
| 352 |   }
 | 
|---|
| 353 | }
 | 
|---|
| 354 | */
 | 
|---|
| 355 | class SCMatrixDiagSubBlock: public SCMatrixBlock {
 | 
|---|
| 356 |   public:
 | 
|---|
| 357 |     SCMatrixDiagSubBlock(int istart,int iend,int jstart, int offset,
 | 
|---|
| 358 |                          double*data);
 | 
|---|
| 359 |     SCMatrixDiagSubBlock(int istart,int iend, int offset, double*data);
 | 
|---|
| 360 |     SCMatrixDiagSubBlock(StateIn&);
 | 
|---|
| 361 |     // does not delete the data member
 | 
|---|
| 362 |     virtual ~SCMatrixDiagSubBlock();
 | 
|---|
| 363 |     // does not save the data member
 | 
|---|
| 364 |     void save_data_state(StateOut&);
 | 
|---|
| 365 |     int istart;
 | 
|---|
| 366 |     int jstart;
 | 
|---|
| 367 |     int iend;
 | 
|---|
| 368 |     int offset;
 | 
|---|
| 369 |     double* data;
 | 
|---|
| 370 | 
 | 
|---|
| 371 |     void process(SCElementOp*);
 | 
|---|
| 372 |     void process(SCElementOp2*, SCMatrixBlock*);
 | 
|---|
| 373 |     void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
 | 
|---|
| 374 | };
 | 
|---|
| 375 | 
 | 
|---|
| 376 | 
 | 
|---|
| 377 | // //////////////////////////////////////////////////////////////////
 | 
|---|
| 378 | // Classes that iterate through the blocks of a matrix.
 | 
|---|
| 379 | 
 | 
|---|
| 380 | /** Objects of class SCMatrixSubblockIter are used to iterate through the
 | 
|---|
| 381 |     blocks of a matrix.  The object must be deleted before using the matrix
 | 
|---|
| 382 |     that owns the blocks that SCMatrixSubblockIter is iterating through. */
 | 
|---|
| 383 | class SCMatrixSubblockIter: public RefCount {
 | 
|---|
| 384 |   public:
 | 
|---|
| 385 |     enum Access { Read, Write, Accum, None };
 | 
|---|
| 386 |   protected:
 | 
|---|
| 387 |     Access access_;
 | 
|---|
| 388 |   public:
 | 
|---|
| 389 |     /** The access variable should be one of Read, Write, Accum, and None,
 | 
|---|
| 390 |         with the SCMatrixSubblockIter:: scope operator applied. */
 | 
|---|
| 391 |     SCMatrixSubblockIter(Access access): access_(access) {}
 | 
|---|
| 392 |     ~SCMatrixSubblockIter();
 | 
|---|
| 393 |     /// Start at the beginning.
 | 
|---|
| 394 |     virtual void begin() = 0;
 | 
|---|
| 395 |     /// Returns nonzero if there is another block.
 | 
|---|
| 396 |     virtual int ready() = 0;
 | 
|---|
| 397 |     /// Proceed to the next block.
 | 
|---|
| 398 |     virtual void next() = 0;
 | 
|---|
| 399 |     /// Return the current block.
 | 
|---|
| 400 |     virtual SCMatrixBlock *block() = 0;
 | 
|---|
| 401 |     /// Return the type of Access allowed for these blocks.
 | 
|---|
| 402 |     Access access() const { return access_; }
 | 
|---|
| 403 | };
 | 
|---|
| 404 | 
 | 
|---|
| 405 | 
 | 
|---|
| 406 | class SCMatrixSimpleSubblockIter: public SCMatrixSubblockIter {
 | 
|---|
| 407 |   protected:
 | 
|---|
| 408 |     Ref<SCMatrixBlock> block_;
 | 
|---|
| 409 |     int ready_;
 | 
|---|
| 410 |   public:
 | 
|---|
| 411 |     SCMatrixSimpleSubblockIter(Access, const Ref<SCMatrixBlock> &b);
 | 
|---|
| 412 |     void begin();
 | 
|---|
| 413 |     int ready();
 | 
|---|
| 414 |     void next();
 | 
|---|
| 415 |     SCMatrixBlock *block();
 | 
|---|
| 416 | };
 | 
|---|
| 417 | 
 | 
|---|
| 418 | class SCMatrixListSubblockIter: public SCMatrixSubblockIter {
 | 
|---|
| 419 |   protected:
 | 
|---|
| 420 |     Ref<SCMatrixBlockList> list_;
 | 
|---|
| 421 |     SCMatrixBlockListIter iter_;
 | 
|---|
| 422 |   public:
 | 
|---|
| 423 |     SCMatrixListSubblockIter(Access, const Ref<SCMatrixBlockList> &list);
 | 
|---|
| 424 |     void begin();
 | 
|---|
| 425 |     int ready();
 | 
|---|
| 426 |     void next();
 | 
|---|
| 427 |     SCMatrixBlock *block();
 | 
|---|
| 428 | };
 | 
|---|
| 429 | 
 | 
|---|
| 430 | class SCMatrixNullSubblockIter: public SCMatrixSubblockIter {
 | 
|---|
| 431 |   public:
 | 
|---|
| 432 |     SCMatrixNullSubblockIter();
 | 
|---|
| 433 |     SCMatrixNullSubblockIter(Access);
 | 
|---|
| 434 |     void begin();
 | 
|---|
| 435 |     int ready();
 | 
|---|
| 436 |     void next();
 | 
|---|
| 437 |     SCMatrixBlock *block();
 | 
|---|
| 438 | };
 | 
|---|
| 439 | 
 | 
|---|
| 440 | class SCMatrixCompositeSubblockIter: public SCMatrixSubblockIter {
 | 
|---|
| 441 |   protected:
 | 
|---|
| 442 |     int niters_;
 | 
|---|
| 443 |     Ref<SCMatrixSubblockIter> *iters_;
 | 
|---|
| 444 |     int iiter_;
 | 
|---|
| 445 |   public:
 | 
|---|
| 446 |     SCMatrixCompositeSubblockIter(Access, int niter);
 | 
|---|
| 447 |     SCMatrixCompositeSubblockIter(Ref<SCMatrixSubblockIter>&,
 | 
|---|
| 448 |                                   Ref<SCMatrixSubblockIter>&);
 | 
|---|
| 449 |     ~SCMatrixCompositeSubblockIter();
 | 
|---|
| 450 |     void set_iter(int i, const Ref<SCMatrixSubblockIter> &);
 | 
|---|
| 451 |     void begin();
 | 
|---|
| 452 |     int ready();
 | 
|---|
| 453 |     void next();
 | 
|---|
| 454 |     SCMatrixBlock *block();
 | 
|---|
| 455 |     int current_block() const { return iiter_; }
 | 
|---|
| 456 | };
 | 
|---|
| 457 | 
 | 
|---|
| 458 | 
 | 
|---|
| 459 | class SCMatrixJointSubblockIter: public SCMatrixSubblockIter {
 | 
|---|
| 460 |   protected:
 | 
|---|
| 461 |     int niters_;
 | 
|---|
| 462 |     Ref<SCMatrixSubblockIter> *iters_;
 | 
|---|
| 463 |   public:
 | 
|---|
| 464 |     SCMatrixJointSubblockIter(const Ref<SCMatrixSubblockIter>&,
 | 
|---|
| 465 |                               const Ref<SCMatrixSubblockIter>&,
 | 
|---|
| 466 |                               const Ref<SCMatrixSubblockIter>& = 0,
 | 
|---|
| 467 |                               const Ref<SCMatrixSubblockIter>& = 0,
 | 
|---|
| 468 |                               const Ref<SCMatrixSubblockIter>& = 0);
 | 
|---|
| 469 |     ~SCMatrixJointSubblockIter();
 | 
|---|
| 470 |     void begin();
 | 
|---|
| 471 |     int ready();
 | 
|---|
| 472 |     void next();
 | 
|---|
| 473 |     SCMatrixBlock *block();
 | 
|---|
| 474 |     SCMatrixBlock *block(int i);
 | 
|---|
| 475 | };
 | 
|---|
| 476 | 
 | 
|---|
| 477 | }
 | 
|---|
| 478 | 
 | 
|---|
| 479 | #endif
 | 
|---|
| 480 | 
 | 
|---|
| 481 | // Local Variables:
 | 
|---|
| 482 | // mode: c++
 | 
|---|
| 483 | // c-file-style: "CLJ"
 | 
|---|
| 484 | // End:
 | 
|---|