Skip to content
Snippets Groups Projects
AlgorithmHistory.cpp 2.95 KiB
Newer Older
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/AlgorithmHistory.h"
Nick Draper's avatar
Nick Draper committed
#include "boost/date_time/posix_time/posix_time.hpp"
Dickon Champion's avatar
Dickon Champion committed
  namespace API
  {
Dickon Champion's avatar
Dickon Champion committed
    /// Constructor
Dickon Champion's avatar
Dickon Champion committed
    AlgorithmHistory::AlgorithmHistory(const std::string& name, const int& version, 
Dickon Champion's avatar
Dickon Champion committed
      const dateAndTime& start, const double& duration,
      const std::vector<AlgorithmParameter>& parameters):
Dickon Champion's avatar
Dickon Champion committed
      m_version(version),
      m_executionDate(start),
      m_executionDuration(duration),
      m_parameters(parameters)
    {  
    }
Dickon Champion's avatar
Dickon Champion committed
    /// Default Constructor
    AlgorithmHistory::AlgorithmHistory()
      // strings have their own default constructor
      :
    m_executionDuration(0.0)
    {
    }
Dickon Champion's avatar
Dickon Champion committed
    /// Destructor
    AlgorithmHistory::~AlgorithmHistory()
    {
    }
    /*!
    Standard Copy Constructor
    \param A :: AlgorithmHistory Item to copy
    */

    AlgorithmHistory::AlgorithmHistory(const AlgorithmHistory& A)
      :
    m_name(A.m_name),m_version(A.m_version),m_executionDate(A.m_executionDate),
      m_executionDuration(A.m_executionDuration),m_parameters(A.m_parameters)
    {
    }
    /** Prints a text representation of itself
    * @param os The ouput stream to write to
Dickon Champion's avatar
Dickon Champion committed
	* @param indent an indentation value to make pretty printing of object and sub-objects
Dickon Champion's avatar
Dickon Champion committed
    */
    void AlgorithmHistory::printSelf(std::ostream& os, const int indent)const
    {
      os << std::string(indent,' ') << "Name : " << m_name << std::endl;
      os << std::string(indent,' ') << "Version: " << m_version << std::endl;
      char buffer [25];
      strftime (buffer,25,"%Y-%b-%d %H:%M:%S",localtime(&m_executionDate));
      os << std::string(indent,' ') << "Execution Date: " << buffer<<std::endl;
      os << std::string(indent,' ') << "Execution Duration: "<< m_executionDuration << " seconds" << std::endl; 
      std::vector<AlgorithmParameter>::const_iterator it;
      os << std::string(indent,' ') << "Parameters:" <<std::endl;

      for (it=m_parameters.begin();it!=m_parameters.end();it++)
      {
        os << std::endl;
        it->printSelf( os, indent+2 );
      }
    }
 
    /*!
    Standard Assignment operator
    \param A :: AlgorithmHistory Item to assign to 'this'
    */
    AlgorithmHistory& AlgorithmHistory::operator=(const AlgorithmHistory& A)
    {
      if (this!=&A)
      {
        m_name=A.m_name;
        m_version=A.m_version;
        m_executionDate=A.m_executionDate;
        m_executionDuration=A.m_executionDuration;
        m_parameters=A.m_parameters;
      }
      return *this;
    }
    /** Prints a text representation
    * @param os The ouput stream to write to
    * @param AH The AlgorithmHistory to output
Dickon Champion's avatar
Dickon Champion committed
    * @returns The ouput stream
    */
    std::ostream& operator<<(std::ostream& os, const AlgorithmHistory& AH)
Dickon Champion's avatar
Dickon Champion committed
      AH.printSelf(os);
      return os;
Dickon Champion's avatar
Dickon Champion committed
  } // namespace API