block.h
//
// block.h
//
// Copyright (C) 1996 Limit Point Systems, Inc.
//
// Author: Curtis Janssen <cljanss@limitpt.com>
// Maintainer: LPS
//
// This file is part of the SC Toolkit.
//
// The SC Toolkit is free software; you can redistribute it and/or modify
// it under the terms of the GNU Library General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
//
// The SC Toolkit is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public License
// along with the SC Toolkit; see the file COPYING.LIB. If not, write to
// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
//
// The U.S. Government is granted a limited license as per AL 91-7.
//
#ifndef _math_scmat_block_h
#define _math_scmat_block_h
#ifdef __GNUC__
#pragma interface
#endif
#include <util/state/state.h>
namespace sc {
class SCElementOp;
class SCElementOp2;
class SCElementOp3;
class SCMatrixBlock: public SavableState {
public:
int blocki, blockj;
public:
SCMatrixBlock();
SCMatrixBlock(StateIn&s);
virtual ~SCMatrixBlock();
void save_data_state(StateOut&s);
virtual SCMatrixBlock *deepcopy() const;
virtual double *dat();
virtual int ndat() const;
// These routines are obsolete.
virtual void process(SCElementOp*) = 0;
virtual void process(SCElementOp2*, SCMatrixBlock*) = 0;
virtual void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*) = 0;
};
class SCMatrixBlockListLink {
private:
void operator = (const SCMatrixBlockListLink&) {} // disallowed
SCMatrixBlock* _block;
SCMatrixBlockListLink* _next;
public:
SCMatrixBlockListLink(SCMatrixBlock*, SCMatrixBlockListLink* = 0);
~SCMatrixBlockListLink();
void block(SCMatrixBlock*);
void next(SCMatrixBlockListLink* link) { _next = link; }
SCMatrixBlock* block() { return _block; }
SCMatrixBlockListLink* next() { return _next; }
};
class SCMatrixBlockListIter {
private:
SCMatrixBlockListLink* link;
public:
SCMatrixBlockListIter(): link(0) {}
SCMatrixBlockListIter(SCMatrixBlockListLink*l): link(l) {}
int operator !=(const SCMatrixBlockListIter p) const {
return link != p.link;
}
void operator ++() { link = link->next(); }
void operator ++(int) { link = link->next(); }
SCMatrixBlock* block() const { return link->block(); }
};
class SCMatrixBlockList: public SavableState {
private:
SCMatrixBlockListLink* _begin;
public:
SCMatrixBlockList();
SCMatrixBlockList(StateIn&);
~SCMatrixBlockList();
void save_data_state(StateOut&);
void insert(SCMatrixBlock*);
void append(SCMatrixBlock*);
SCMatrixBlockListIter begin() { return _begin; }
SCMatrixBlockListIter end() { return 0; }
SCMatrixBlockList *deepcopy();
};
class SCVectorSimpleBlock: public SCMatrixBlock {
public:
SCVectorSimpleBlock(int istart,int iend);
SCVectorSimpleBlock(StateIn&);
virtual ~SCVectorSimpleBlock();
void save_data_state(StateOut&);
int istart;
int iend;
double* data;
SCMatrixBlock *deepcopy() const;
void process(SCElementOp*);
void process(SCElementOp2*, SCMatrixBlock*);
void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
double *dat();
int ndat() const;
};
class SCVectorSimpleSubBlock: public SCMatrixBlock {
public:
SCVectorSimpleSubBlock(int istart,int iend, int offset, double* data);
SCVectorSimpleSubBlock(StateIn&);
virtual ~SCVectorSimpleSubBlock();
void save_data_state(StateOut&);
int istart;
int iend;
int offset;
double* data;
void process(SCElementOp*);
void process(SCElementOp2*, SCMatrixBlock*);
void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
};
class SCMatrixRectBlock: public SCMatrixBlock {
public:
SCMatrixRectBlock(int is, int ie, int js, int je);
SCMatrixRectBlock(StateIn&);
virtual ~SCMatrixRectBlock();
void save_data_state(StateOut&);
int istart;
int jstart;
int iend;
int jend;
double* data;
SCMatrixBlock *deepcopy() const;
void process(SCElementOp*);
void process(SCElementOp2*, SCMatrixBlock*);
void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
double *dat();
int ndat() const;
};
class SCMatrixRectSubBlock: public SCMatrixBlock {
public:
SCMatrixRectSubBlock(int is, int ie, int istride, int js, int je,
double* data);
SCMatrixRectSubBlock(StateIn&);
// does not delete the data member
virtual ~SCMatrixRectSubBlock();
// does not save the data member
void save_data_state(StateOut&);
int istart;
int jstart;
int iend;
int jend;
int istride;
double* data;
void process(SCElementOp*);
void process(SCElementOp2*, SCMatrixBlock*);
void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
};
class SCMatrixLTriBlock: public SCMatrixBlock {
public:
SCMatrixLTriBlock(int s,int e);
SCMatrixLTriBlock(StateIn&);
virtual ~SCMatrixLTriBlock();
void save_data_state(StateOut&);
int start;
int end;
double* data;
SCMatrixBlock *deepcopy() const;
void process(SCElementOp*);
void process(SCElementOp2*, SCMatrixBlock*);
void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
double *dat();
int ndat() const;
};
class SCMatrixLTriSubBlock: public SCMatrixBlock {
public:
SCMatrixLTriSubBlock(int is,int ie,int js,int je,double*data);
SCMatrixLTriSubBlock(StateIn&);
// does not delete the data member
virtual ~SCMatrixLTriSubBlock();
// does not save the data member
void save_data_state(StateOut&);
int istart;
int iend;
int jstart;
int jend;
double* data;
void process(SCElementOp*);
void process(SCElementOp2*, SCMatrixBlock*);
void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
};
class SCMatrixDiagBlock: public SCMatrixBlock {
public:
SCMatrixDiagBlock(int istart,int iend,int jstart);
SCMatrixDiagBlock(int istart,int iend);
SCMatrixDiagBlock(StateIn&);
virtual ~SCMatrixDiagBlock();
void save_data_state(StateOut&);
int istart;
int jstart;
int iend;
double* data;
SCMatrixBlock *deepcopy() const;
void process(SCElementOp*);
void process(SCElementOp2*, SCMatrixBlock*);
void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
double *dat();
int ndat() const;
};
class SCMatrixDiagSubBlock: public SCMatrixBlock {
public:
SCMatrixDiagSubBlock(int istart,int iend,int jstart, int offset,
double*data);
SCMatrixDiagSubBlock(int istart,int iend, int offset, double*data);
SCMatrixDiagSubBlock(StateIn&);
// does not delete the data member
virtual ~SCMatrixDiagSubBlock();
// does not save the data member
void save_data_state(StateOut&);
int istart;
int jstart;
int iend;
int offset;
double* data;
void process(SCElementOp*);
void process(SCElementOp2*, SCMatrixBlock*);
void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
};
// //////////////////////////////////////////////////////////////////
// Classes that iterate through the blocks of a matrix.
class SCMatrixSubblockIter: public RefCount {
public:
enum Access { Read, Write, Accum, None };
protected:
Access access_;
public:
SCMatrixSubblockIter(Access access): access_(access) {}
~SCMatrixSubblockIter();
virtual void begin() = 0;
virtual int ready() = 0;
virtual void next() = 0;
virtual SCMatrixBlock *block() = 0;
Access access() const { return access_; }
};
class SCMatrixSimpleSubblockIter: public SCMatrixSubblockIter {
protected:
Ref<SCMatrixBlock> block_;
int ready_;
public:
SCMatrixSimpleSubblockIter(Access, const Ref<SCMatrixBlock> &b);
void begin();
int ready();
void next();
SCMatrixBlock *block();
};
class SCMatrixListSubblockIter: public SCMatrixSubblockIter {
protected:
Ref<SCMatrixBlockList> list_;
SCMatrixBlockListIter iter_;
public:
SCMatrixListSubblockIter(Access, const Ref<SCMatrixBlockList> &list);
void begin();
int ready();
void next();
SCMatrixBlock *block();
};
class SCMatrixNullSubblockIter: public SCMatrixSubblockIter {
public:
SCMatrixNullSubblockIter();
SCMatrixNullSubblockIter(Access);
void begin();
int ready();
void next();
SCMatrixBlock *block();
};
class SCMatrixCompositeSubblockIter: public SCMatrixSubblockIter {
protected:
int niters_;
Ref<SCMatrixSubblockIter> *iters_;
int iiter_;
public:
SCMatrixCompositeSubblockIter(Access, int niter);
SCMatrixCompositeSubblockIter(Ref<SCMatrixSubblockIter>&,
Ref<SCMatrixSubblockIter>&);
~SCMatrixCompositeSubblockIter();
void set_iter(int i, const Ref<SCMatrixSubblockIter> &);
void begin();
int ready();
void next();
SCMatrixBlock *block();
int current_block() const { return iiter_; }
};
class SCMatrixJointSubblockIter: public SCMatrixSubblockIter {
protected:
int niters_;
Ref<SCMatrixSubblockIter> *iters_;
public:
SCMatrixJointSubblockIter(const Ref<SCMatrixSubblockIter>&,
const Ref<SCMatrixSubblockIter>&,
const Ref<SCMatrixSubblockIter>& = 0,
const Ref<SCMatrixSubblockIter>& = 0,
const Ref<SCMatrixSubblockIter>& = 0);
~SCMatrixJointSubblockIter();
void begin();
int ready();
void next();
SCMatrixBlock *block();
SCMatrixBlock *block(int i);
};
}
#endif
// Local Variables:
// mode: c++
// c-file-style: "CLJ"
// End: