/*
 *  Open BEAGLE
 *  Copyright (C) 2001-2004 by Christian Gagne and Marc Parizeau
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library 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
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  Contact:
 *  Laboratoire de Vision et Systemes Numeriques
 *  Departement de genie electrique et de genie informatique
 *  Universite Laval, Quebec, Canada, G1K 7P4
 *  http://vision.gel.ulaval.ca
 *
 */

/*!
 *  \file   beagle/Vector.hpp
 *  \brief  Definition of the class Vector.
 *  \author Christian Gagne
 *  \author Marc Parizeau
 *  $Revision: 1.5 $
 *  $Date: 2004/10/28 16:50:42 $
 */

#ifndef Beagle_Vector_hpp
#define Beagle_Vector_hpp

#include "beagle/config.hpp"
#include "beagle/macros.hpp"
#include "beagle/Object.hpp"
#include "beagle/AllocatorT.hpp"
#include "beagle/PointerT.hpp"
#include "beagle/ContainerT.hpp"
#include "beagle/Tokenizer.hpp"
#include "beagle/XMLNode.hpp"
#include "beagle/XMLParser.hpp"
#include "beagle/XMLStreamer.hpp"
#include "beagle/AssertException.hpp"
#include "beagle/Matrix.hpp"

namespace Beagle {


/*!
 *  \class Vector beagle/Vector.hpp "beagle/Vector.hpp"
 *  \brief Real-valued vector class, defined as a special case of a matrix.
 *  \ingroup OOF
 *  \ingroup Utils
 */
class Vector : public Matrix {

public:

  //! Vector allocator type.
  typedef AllocatorT<Vector,Matrix::Alloc>
          Alloc;
  //! Vector handle type.
  typedef PointerT<Vector,Matrix::Handle>
          Handle;
  //! Vector bag type.
  typedef ContainerT<Vector,Matrix::Bag>
          Bag;

  explicit Vector(unsigned int inSize=0, double inValue=0.0);
           Vector(const std::vector<double>& inDoubleVector);
           Vector(const Matrix& inMatrix);
  virtual ~Vector() { }  //!< Vector destructor (do nothing).

  /*!
   *  \brief Get vector value a index inN.
   *  \param inN Index of the value to get in the vector.
   *  \return Value in matrix index inN.
   *  \throw Beagle::AssertException If the index given is out-of-bound.
   */
  inline const double& operator[](unsigned int inN) const
  {
    Beagle_BoundCheckAssertM(inN,0,mRows-1);
    return *(begin()+inN);
  }

  /*!
   *  \brief Get vector value a index inN.
   *  \param inN Index of the value to get in the vector.
   *  \return Value in matrix index inN.
   *  \throw Beagle::AssertException If the index given is out-of-bound.
   */
  inline double& operator[](unsigned int inN)
  {
    Beagle_BoundCheckAssertM(inN,0,mRows-1);
    return *(begin()+inN);
  }

  Vector& operator=(const Matrix& inRightMatrix);
  Vector& operator=(const std::vector<double>& inRightVector);
  
  virtual bool isLess(const Object& inRightObj) const;
  virtual void read(XMLNode::Handle& inNode);
          void resize(unsigned int inSize, double inValue=0.0);

protected:

  double computeDeterminant() const;
  void   computeEigenSystem(Vector&,Matrix&) const;
  void   inverse();
  void   resize(unsigned int,unsigned int,double=0.0);

};

}

#endif // Beagle_Vector_hpp


