Click here to Skip to main content
15,883,749 members
Articles / Mobile Apps
Article

The CxProgress Class - Time, progress and rate estimations made easy

Rate me:
Please Sign up or sign in to vote.
4.00/5 (12 votes)
13 Mar 20032 min read 53.2K   639   31   6
When you download a file from the Internet you have to find the transfer rate. This class does it with 3 easy lines of code !

Introduction

This article solves a simple yet tricky problem! Time estimations !

Did you ever create a function to download a file from the web but you couldn't calculate the transfer rate , estimate the time ...If you tried you got the Division By Zero fatal message! Well this class can do many great things just by a few function calls.

CxProgress

typedef unsigned long u_long;
typedef unsigned int u_int;

class CXProgress
{
public:
    CXProgress();
    void SetRange(u_long prgmin, u_long prgmax);
    const char * FormatLeftTime();
    const char * FormatElapsedTime();
    u_long ToComeSeconds();
    bool StepIt(u_long steps=1);
    bool SetStep(u_long step=1);
    u_long RatePerHour();
    u_long RatePerMinute();
    u_long RatePerSecond();
    u_long Rate(u_long milisecs=1000);
    u_long ElapsedMilisecs();
    u_long ElapsedDays();
    u_long ElapsedHours();
    u_long ElapsedMinutes();
    bool IsTimeElapsed();
    bool DecreaseMinPos(u_long num);
    bool EncreaseMinPos(u_long num);
    bool DecreaseMaxPos(u_long num);
    bool IncreaseMaxPos(u_long num);
    u_long ElapsedSeconds();
    u_int GetPercentLeft();
    u_int GetPercentElapsed();
    u_long GetLeftPos();
    u_long GetCurrentPos();
    bool Can();
    u_long LeftDays();
    u_long LeftHours();
    u_long LeftMinutes();
    u_long LeftSeconds();
    bool SetCurrentPos(u_long);
    CXProgress(u_long, u_long);
    virtual ~CXProgress();
private:
    // do not modify the variables below
    u_long startMom,nowMom;
    // they are private and by modifying them i don`t
    long startTime,nowTime;        
    // know how class will behave
    u_long prgMin;
    u_long prgMax;
    u_long curPos;
    u_long numStep;
    // interneal buffer for functions that return strings
    char buf[512];            
};
/*---------------------------------------------------------*/
/*CXProgress.cpp*/
// XProgress.cpp: implementation of the CXProgress class.
//
//////////////////////////////////////////////////////////////////////

Using the code

The code using method is most easy :

void main(void)
{
    CXProgress prg(0,100);
/*we create a prg with range 0-100*/
    int cur=0;
    while(cur<100)
    {
        cur++;
        prg.SetCurrentPos(cur);
/*we set it`s position to cur*/
        Sleep(1000);
        printf("%s -",prg.FormatElapsedTime());
        printf(" %s - Rate: %d\r",prg.FormatLeftTime(),prg.RatePerSecond());
/*run this example and see how it works*/
    }
}

As you see it's ideal for internet transfers , for getting rate ...

Documentations

How to use each function :

void SetRange

u_long prgmin - start range position=0

u_long prgmax - end range position

It can have values between the two values.

const char * FormatLeftTimeReturns 00:00:00 format of left time.
const char * FormatElapsedTimeReturns 00:00:00 format of elapsed time.
u_long ToComeSecondsleft time in seconds.
bool StepItu_long steps=1 - increase current position with steps*step
bool SetStepu_long step=1 - step size - usually 1
u_long RatePerHourEstimated progress rate per hour.
u_long RatePerMinuteEstimated progress rate per minute.
u_long RatePerSecondEstimated progress rate per second.
u_long Rateu_long milisecs=1000 - progress rate for intervals less a second.
u_long ElapsedMilisecsElapsed time in milliseconds.
u_long ElapsedDaysElapsed time in days.
u_long ElapsedHoursElapsed time in hours.
u_long ElapsedMinutes.Elapsed time in milliseconds.
bool IsTimeElapsedDid any time elapse from the beginning.
bool DecreaseMinPosu_long num - make minPos=minPos-num
bool EncreaseMinPosu_long num - make minPos=minPos+num
bool DecreaseMaxPosu_long num - makes maxPos=maxPos-num
bool IncreaseMaxPosu_long num - make maxPos=maxPos+num
u_long ElapsedSecondsElapsed time in seconds.
u_int GetPercentLeft% to come.
u_int GetPercentElapsed% over.
u_long GetLeftPosReturns left positions. (maxPos-curPos)
u_long GetCurrentPosReturns current position.
bool CanIf it has any internal valid times to estimate.
u_long LeftDaysLeft time in days.
u_long LeftHoursLeft time in hours.
u_long LeftMinutesLeft time in minutes.
u_long LeftSecondsLeft time in seconds.
bool SetCurrentPosu_long pos - set current pos to pos

History

  • Only release 6:31 AM 3/15/2003 (I think)

Last but not least

And if you did not understand anything look at the code. You can't miss it. You'll get it for sure! :~)

The source code will reveal its darkest secrets to your mortal eyes by only looking at it. And I'll let you in on another little secret of mine. You can use the very ancient but long forgotten copy-paste technique if the complexity of the source code overwhelms you. And if you need more information check the holy book of software engineers, the forbidden MSDN. Many words of wisdom will be discovered within its dirty and dusty pages.

And to find out the truth about our existence, humanity, universe and aliens mail me.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Romania Romania
I have been programming for the past 6 years in VBasic, Delphi, C, C++ .
I also have extended knowledge of webdesign (HTML, CSS, JavaScript, VBScript), webprogramming (PHP, ASP, ASP.NET (C#)) and database integration (mySql, MSSQL Server).
And when I`m not programming I`m working out or working on some personal projects .
Last but not least I`m looking for a project-based job in programming or webdesign .

Comments and Discussions

 
GeneralHi...looking for VB version Pin
Venu_938-Sep-03 0:42
Venu_938-Sep-03 0:42 
GeneralDISCLAIMER ! Pin
TomKat15-Mar-03 5:57
TomKat15-Mar-03 5:57 
Generalsweet Pin
Nitron15-Mar-03 5:00
Nitron15-Mar-03 5:00 
GeneralCool Pin
Ryan Binns14-Mar-03 18:33
Ryan Binns14-Mar-03 18:33 
GeneralNice! Pin
Ravi Bhavnani14-Mar-03 18:15
professionalRavi Bhavnani14-Mar-03 18:15 
GeneralRe: Nice! Pin
TomKat15-Mar-03 2:08
TomKat15-Mar-03 2:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.