//@author Roland Bramm //@version $LastChangedRevision: 736 $ //@date $LastChangedDate: 2006-02-01 13:31:48 +0100 (Wed, 01 Feb 2006) $ #include "ProgressBar.h" ProgressBar::ProgressBar(char bullet, int width, int maxCounter, string actionName) : fbullet(bullet), fwidth(width), fmaxCounter(maxCounter), factionName(actionName){ fprintedBulletCounter = 0; printStart(); } ProgressBar::~ProgressBar() { if(fprintedBulletCounter < getWidthofBar()){ for(int i = 0; i < (getWidthofBar() - fprintedBulletCounter) ; i++){ cout << fbullet << flush; } } cout << endl; } void ProgressBar::setBulletChar(char bullet){ fbullet = bullet; } void ProgressBar::setWidth(int width){ fwidth = width; } void ProgressBar::setMaxCounter(int maxCounter){ fmaxCounter = maxCounter; } void ProgressBar::setActionName(string actionName){ factionName = actionName; } int ProgressBar::getWidthofBar(){ int retval = 0; //Length of Action name retval = fwidth - factionName.length(); //start and end of Bar retval = retval - 2 - 1; return retval; } int ProgressBar::getBulletEvery(){ return (int)(fmaxCounter/(float)getWidthofBar()+1); } int ProgressBar::getBulletsEvery(){ return (int)(getWidthofBar()/(float)fmaxCounter); } void ProgressBar::printStart(){ //cout << " fbullet: " << fbullet << " fwidth " << fwidth << " getWidthofBar " << getWidthofBar() << " maxCounter " << fmaxCounter << " getBulletEvery " << getBulletEvery() << endl; cout << factionName << " ["; for(int i = 0; i < getWidthofBar(); i++){ cout << " "; } cout << "]\r"; cout << factionName << " [" << flush; } void ProgressBar::print(int iterator){ if(fwidth < fmaxCounter){ if(iterator%getBulletEvery() == 0){ cout << fbullet << flush; //cout << iterator << endl; fprintedBulletCounter++; } }else{ for(int i = 0; i < getBulletsEvery(); i++){ cout << fbullet << flush; fprintedBulletCounter++; } } } /* Char_t bullet; bullet = '-'; for(int jititer = 0; jititer < numoftimesteps; jititer++) { cout << setw(3) << jititer << ": [" << flush; if(iter%bulletevery==0){ cout << bullet << flush; } remainingTime = ((int)((endLoopTime - startTime)/(float)jititer*(numoftimesteps-jititer))); elapsedTime = (endLoopTime - startTime); cout << "] " << setw(3) << ( (100*(jititer+1))/numoftimesteps) << "% Elapsed Time = " << (elapsedTime/60) << ":" << setw(2) << setfill('0') << (elapsedTime%60); cout << " Remaining Time " << (remainingTime/60) << ":" << setw(2) << setfill('0') << (remainingTime%60) << " \r"; if(bullet == '-') bullet = '='; else bullet = '-'; endLoopTime = time(0); } */