/**============================================================================
 *
 * \file   progress_bar.hpp
 * \brief  Contains declarations fo the ProgressBar class.
 *
 * Source:
 *
 * http://www.siteduzero.com/forum-83-691036-p1-barre-de-progression-console-c.html
 *
 * \author Leblanc Christophe
 * \date   01/01/2013
 * \email cleblancad@gmail.com
 *
 *===========================================================================*/

#ifndef PROGRESS_BAR_HPP
#define PROGRESS_BAR_HPP

#include <iostream>

namespace marinov {

/** \class ProgressBar
 * \brief Shows a progress bar in the console.
 * 
 * \ingroup Object
 */
class ProgressBar
{
public:
  /// \brief Constructor.
  /// \param[in] os display output.
  /// \param[in] length length of the progress bar.
  ProgressBar(std::ostream &os, const int &length = 30);
  
  /// \brief Copy constructor.
  /// \param[in] rhs object to copy.
  ProgressBar(const ProgressBar &rhs);
  
  /// \brief Destructor.
  ~ProgressBar() {}
  
  /// \brief Copy operator.
  /// \param[in] rhs object to copy.
  /// \return copied object
  ProgressBar& operator=(const ProgressBar &rhs);
  
  /// \brief Initializes the progress bar.
  void Init();
  
  /// \brief Updates the progress bar.
  /// \param[in] i current iteration number.
  /// \param[in] n total number of iterations.
  /// \return True if an update occurs, false otherwise.
  bool Update(const int i, const int n);
  
  /// \brief Marks progress bar as complete.
  void Complete();
  
private:
  int m_Length;	///< Progress bar's length.
  int m_Mark;		///< Current progress on progress bar.
  int m_Progress;	///< Current progress;
  std::ostream* m_Os;		///< Progress bar display output.
};

} // namespace marinov

#endif // PROGRESS_BAR_HPP
