Boost logo

Boost :

From: Sergey Panov (sipan_at_[hidden])
Date: 2000-04-16 17:13:55


> I found it usefull to have general "time" class. ...

I am sorry for the multitude of errors in my English and
sample/prototipe C++ class definition. I took my working
code and edited it a bit before posting. Now I get modified
version to work.

  "time" was a bad choice as a name for that class -- even hiding in
the special namespace did not help. I had to change name to "chron"

 I also think now that internal implementation should be is platform
dependent. E.g. on UNIX platforms it is reasonable to store time
in "timeval" structure, but on WIN32 platforms it is more efficient
to store it as uint64_t value.

Here is a new version of proposed "chron"(was "time") class:

class chron
{

public:

        enum set_mode
        {
                zero,
                now
        };

        enum chron_mode
        {
                real,
                process,
                system,
                user,
                children_sys,
                childred_user
        };

        enum chron_units
        {
                nsec,
                usec,
                msec,
                sec,
                assumed
        };

private:
// Private part is irrelevant for now
public:

        // chron(chron::now) will set to current time
        chron(set_mode s = zero, // "set to" option
              chron_units u = msec, // assumed units
              chron_mode m = real); // timing mode

        chron(int t,
              chron_units u = msec,
              chron_mode m = real);

        // Set to current time
        chron& set_now();

        // Set to time to zero [ Epoch (00:00:00 UTC, January 1, 1970) ]
        chron& set_zero();

        // Convert into parts of a second
        int get(chron_units u = assumed);

        // now - *this
        int elapsed(chron_units u = assumed);

        // sleep at least time specified ( on some system > 2-10msec)
        void sleep();

        // delay execution by empty cycles(short delays)
        int delay();

        // Set time
        chron& set(int t, chron_units u = assumed);

        // Get value in parts of s second
        chron& add(int t, chron_units u = assumed);

        // Get date in the printable format
        char* date();

        // Get part that is less then a second [T%(sec)]
        // Possible use:
        // cout << t.date() << " " << t.extra() << " msec" << endl;
        int extra(chron_units u = assumed);

        // Arithmetic operators
        chron& operator+=(const chron& t);
        chron& operator-=(const chron& t);

        chron operator+(const chron& t);
        chron operator-(const chron& t);

        // Comparison
        bool operator==(const chron& t) const;
        bool operator!=(const chron& t) const;
        bool operator<(const chron& t) const;
        bool operator>(const chron& t) const;
        bool operator<=(const chron& t) const;
        bool operator>=(const chron& t) const;

};

Missing: casting to timespec and timeval.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk