/***************************************************************************
                          Vector.h  -  description
                             -------------------
    begin                : Don Feb 10 2005
    copyright            : (C) 2005 by klaus frieler
    email                : kgf@omniversum.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef _LIBMELODY_VECTOR_H
#define _LIBMELODY_VECTOR_H
#include "types.h"

typedef dData::iterator       v_iterator;
typedef dData::const_iterator v_const_iterator;

class Vector
{
public:
   Vector(){}
   Vector(const Vector& vector)
   {
      for(uint i = 0; i<vector.size();++i){
         push_back(vector[i]);
      }
   }
   Vector(const dData& vector)
   {
      for(uint i = 0; i<vector.size();++i){
         push_back(vector[i]);
      }
   }
   Vector(const iData& vector)
   {
      for(uint i = 0; i<vector.size();++i){
         push_back((double)vector[i]);
      }
   }
   ~Vector(){}
   
   //operators
   Vector&  operator =(const Vector& vector);
   Vector&  operator =(const dData& vector);
   Vector&  operator =(const iData& vector);
   void     operator+=(const Vector& vector);
   void     operator-=(const Vector& vector);
   double   operator*=(const Vector& vector);
   void     operator*=(const double lambda);
   void     operator/=(const double lambda);
   Vector   operator+(const Vector& vector)const;
   Vector   operator-(const Vector& vector)const;
   Vector   operator*(const double lambda)const;
   Vector   operator/(const double lambda)const;
   double   operator*(const Vector& vector)const;
   bool     operator==(const Vector& vector) const;
   
   //access
   v_iterator        begin()     { return m_data.begin();}
   v_const_iterator  begin()const{ return m_data.begin();}
   v_iterator        end()       { return m_data.end();}
   v_const_iterator  end()const  { return m_data.end();}
   double   operator[](const uint idx)const  { return m_data[idx];}
   double&  operator[](const uint idx)       { return m_data[idx];}
   double&  at(const uint idx)      { return m_data.at(idx);}
   double   at(const uint idx)const { return m_data.at(idx);}

   //manipulation
   void        push_back(const double val){ m_data.push_back(val);}
   void        pop_back(){ m_data.pop_back();}
   void        remove(const uint idx);
   void        clear(){m_data.clear();}
   v_iterator  erase(v_iterator start, v_iterator end ){ return m_data.erase(start, end);}
   v_iterator  erase(v_iterator start)                 { return m_data.erase(start);}
   void        assign(size_t count, double val){ 
      clear(); 
      m_data.insert(m_data.begin(), count, val);
   }

   //knowledge
   size_t   size()const{ return m_data.size();}
   bool     empty()const{ return m_data.empty();}
   
   //analysis
   Vector   getLocalMaxima(iData& positions, bool bStrict = false) const;
   Vector   getLocalMinima(iData& positions, bool bStrict = false) const;
   Vector   normalize()const;
   double   getMax() const;
   
   //debug
   void  dump(const char* text="")const;
protected:
   dData    m_data;
};
#endif
