/////////////////////////////////////////////////////////////////////////
//                                                                     //
// This file contains the declaration and implementation of the        //
// CSquareMatrix class.                                                //
//                                                                     //
/////////////////////////////////////////////////////////////////////////
#ifndef __CSQUAREMATRIX_HPP__
#define __CSQUAREMATRIX_HPP__

#include "CMatrix.hpp"


/////////////////////////////////////////////////////////////////////////
//                                                                     //
// This is a simple square matrix class.                               //
//                                                                     //
/////////////////////////////////////////////////////////////////////////
template <typename T, int DIM>
class CSquareMatrix : public CMatrix<T,DIM,DIM>
{
public:
  CSquareMatrix();
  CSquareMatrix(const CSquareMatrix& m);

  CSquareMatrix& operator=(const CMatrix<T,DIM,DIM>& m);

  CSquareMatrix transpose() const;
  void loadIdentity();
};




// Default constructor
template <typename T, int DIM>
inline CSquareMatrix<T,DIM>::CSquareMatrix()
  : CMatrix<T,DIM,DIM>()
{
}


// Copy constructor
template <typename T, int DIM>
inline CSquareMatrix<T,DIM>::CSquareMatrix(const CSquareMatrix& m)
  : CMatrix<T,DIM,DIM>(m)
{
}


// Assignment operator
template <typename T, int DIM>
inline CSquareMatrix<T,DIM>& CSquareMatrix<T,DIM>::operator=(const CMatrix<T,DIM,DIM>& m)
{
  if (this != &m)
    Copy(m);

  return (*this);
}


// Transposition of the square matrix
template <typename T, int DIM>
inline CSquareMatrix<T,DIM> CSquareMatrix<T,DIM>::transpose() const
{
  CSquareMatrix<T,DIM> transposeMat;

  for (int i = 0; i < DIM; ++i)
    for (int j = 0; j < DIM; ++j)
      transposeMat(i,j) = (*this)(j,i);

  return transposeMat;
}


// Fill the matrix with the identity matrix
template <typename T, int DIM>
inline void CSquareMatrix<T,DIM>::loadIdentity()
{
  for (int i = 0; i < DIM; ++i)
    for (int j = 0; j < DIM; ++j)
      (*this)(i,j) = ( (i == j) ? 1 : 0 );
}


#endif // __CSQUAREMATRIX_HPP__
