Category : C++ Source Code
Archive   : BLFMATH.ZIP
Filename : SIMPMAT.H
// simpmat.h: Class definition for simple dynamic matrices.
// Copyright(c) 1993 Azarona Software. All rights reserved.
/////////////////////////////////////////////////////////////////
#ifndef H_SIMPLEMAT
#define H_SIMPLEMAT
#include "vecptr.h"
#define INLINE
// Note: You can define the macro constant VECTORPTRRETURNS
// to change the class to return vector pointers for rows
// instead of ordinary pointers. By switching back and forth
// you can see for yourself what kind of overhead vector
// pointers do or don't have over ordinary pointers.
template
class SimpleMatrix {
private:
TYPE *data;
unsigned nrows, ncols;
public:
SimpleMatrix(unsigned nr, unsigned nc);
SimpleMatrix(const SimpleMatrix
~SimpleMatrix();
void Copy(const SimpleMatrix
SimpleMatrix
#ifndef VECTORPTRRETURNS
TYPE *operator[](unsigned r);
#else
VecPtr
#endif
VecPtr
VecPtr
VecPtr
VecPtr
#ifndef VECTORPTRRETURNS
const TYPE *operator[](unsigned r) const;
#else
VecPtr
#endif
VecPtr
VecPtr
VecPtr
VecPtr
unsigned NRows() const;
unsigned NCols() const;
unsigned NElems() const;
};
template
INLINE SimpleMatrix
{
delete[] data;
}
template
INLINE SimpleMatrix
SimpleMatrix
{
if (this != &m) Copy(m); // Trap assignment to self
return *this;
}
// Selectors for non-const matrices
#ifndef VECTORPTRRETURNS
template
INLINE TYPE *SimpleMatrix
// Returns an ordinary pointer (stride 1) to row r
{
return data + r*ncols;
}
#else
template
INLINE VecPtr
// Returns an vector pointer (stride 1) to row r
{
return VecPtr
}
#endif
template
INLINE VecPtr
// Return a row vector pointer
{
return VecPtr
}
template
INLINE VecPtr
// Return a column vector pointer
{
return VecPtr
}
template
INLINE VecPtr
// Return a diagonal vector pointer. In case matrix
// isn't square, the smallest dimension is used to
// determine the diagonal length.
{
unsigned dstride = ((nrows > ncols) ? ncols : nrows) + 1;
return VecPtr
}
template
INLINE VecPtr
// Return pointer to all elements of the matrix
{
return VecPtr
}
// Selectors for const matrices
#ifndef VECTORPTRRETURNS
template
INLINE const TYPE *SimpleMatrix
// Returns an ordinary pointer (stride 1) to row r
{
return data + r*ncols;
}
#else
template
INLINE VecPtr
// Returns an vector pointer (stride 1) to row r
{
return VecPtr
}
#endif
template
INLINE VecPtr
// Return a row vector pointer
{
return VecPtr
}
template
INLINE VecPtr
// Return a column vector pointer
{
return VecPtr
}
template
INLINE VecPtr
// Return a diagonal vector pointer. In case matrix
// isn't square, the smallest dimension is used to
// determine the diagonal length.
{
unsigned dstride = ((nrows > ncols) ? ncols : nrows) + 1;
return VecPtr
}
template
INLINE VecPtr
// Return pointer to all elements of the matrix
{
return VecPtr
}
template
INLINE unsigned SimpleMatrix
{
return nrows;
}
template
INLINE unsigned SimpleMatrix
{
return ncols;
}
template
INLINE unsigned SimpleMatrix
{
return nrows * ncols;
}
#undef INLINE
// Whether or not we should include the non-line methods for
// our class templates here is implementation dependent.
#include "simpmat.mth"
#endif
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/