/******************************************************************************
* NOMAD -  Nonlinear Optimization for Mixed vAriables and Derivatives.        *
* Copyright (C) 2001-2004  Gilles Couture - Ecole Polytechnique,              *
*                          Charles Audet - Ecole Polytechnique,               *
*		           John Dennis - Rice University.                     *
*                                                                             *
* Author: Gilles Couture                                                      *
* École Polytechnique de Montréal - GERAD                                     *
* C.P. 6079, Succ. Centre-ville, Montréal (Québec) H3C 3A7 Canada             *
* Tel:  (514) 340-6053 x6928                                                  *
* Email: Gilles.Couture@gerad.ca                                              *
* Fax: (514) 340-5665                                                         *
*                                                                             *
* 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. You can find the              *
* GNU General Public License at:                                              *
*             http://www.gnu.org/copyleft/gpl.html                            *
*                                                                             *
* This program 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 General Public License for more details.                                *
*                                                                             *
* You should have received a copy of the GNU General Public License           *
* along with this program; if not, write to the Free Software                 *
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. *
*                                                                             *
* You can find information on the NOMAD software at:                          *
*             http://www.gerad.ca/NOMAD/                                      *
******************************************************************************/

// direction.cpp -- Direction class methods. The methods of this class are
// called by the DirectionSet object, which manages a set of directions.

#include <fstream>
#include <iostream>
using namespace std;
#include "direction.h"

// Initializing the static class members.
int Direction::num_dir = 0;

// Public methods.
// ****************************************************************************

// Default constructor.
Direction::Direction(const std::vector<double> v)
{		
  int size = v.size();
  dir.reserve(size);
  // The vector is copied.
  for (int i = 0; i < size; i++)
	  dir.push_back(v[i]);

  // DEBUG!!!
  num_dir++;
  // cout << "Direction object created (DC): " << num_dir << "." << endl;
}

// Copy constructor.
Direction::Direction(const Direction & d)
{
  int size = d.dir.size();
	dir.reserve(size);
  // The vector is copied.
  for (int i = 0; i < size; i++)
		dir.push_back(d.dir[i]);
	
  // DEBUG!!!
  num_dir++;
  // cout << "Direction object created (CC): " << num_dir << "." << endl;
}


// Destructor.
Direction::~Direction()
{
  // DEBUG!!!
  // cout << "Direction object destroyed, ";
  --num_dir;
  // cout << num_dir << " left." << endl;

  dir.clear();
}

// Non-member functions.
// ****************************************************************************

// This method overloads the '<<' operator.
ostream & operator<<(ostream & os, const Direction & d)
{
  // We check if the direction is empty.
  if (d.dir.empty())
    os << "Empty vector!\n";
  else
    {
      int size = d.dir.size();
      // The direction is shown.
      for (int i = 0; i < size; i++)
				{
					os.width(6);
					os << d.dir[i] << " ";
				}
			os << "\n";
    }
  return os;
}
