chxavtimevalue.h
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:4k
- /*============================================================================*
- *
- * (c) 1995-2002 RealNetworks, Inc. Patents pending. All rights reserved.
- *
- *============================================================================*/
-
- #ifndef UT_TIME_VALUE_H
- #define UT_TIME_VALUE_H
- /*
- * CHXAvTimeValue: Wrapper class for system time.
- *
- *
- * This wrapper for time was lifted for the most part from
- * the ACE Networking Package.
- */
- #include <sys/time.h>
- #include <e32std.h>
- class CHXAvTimeValue {
- public:
- CHXAvTimeValue(long sec = 0, long usec = 0);
- CHXAvTimeValue(const CHXAvTimeValue&);
- CHXAvTimeValue& operator=(const CHXAvTimeValue&);
- long sec() const;
- long usec() const;
- CHXAvTimeValue& operator+=(const CHXAvTimeValue&);
- CHXAvTimeValue& operator-=(const CHXAvTimeValue&);
- CHXAvTimeValue operator+(const CHXAvTimeValue&)const;
- CHXAvTimeValue operator-(const CHXAvTimeValue&)const;
- int operator<(const CHXAvTimeValue&) const;
- int operator>(const CHXAvTimeValue&) const;
- int operator<=(const CHXAvTimeValue&) const;
- int operator>=(const CHXAvTimeValue&) const;
- int operator==(const CHXAvTimeValue&) const;
- int operator!=(const CHXAvTimeValue&) const;
- // get current time
- static int now(CHXAvTimeValue&);
- CHXAvTimeValue zero() const { return CHXAvTimeValue(0, 0); } // zero constant.
- private:
- void normalize();
- static bool GetTimeofDay(long& sec, long& usec);
- long sec_;
- long usec_;
- };
- inline
- TTime UnixStart()
- {
- return TDateTime(1970, EJanuary, 0, 00, 0, 0, 0);
- }
- inline
- bool CHXAvTimeValue::GetTimeofDay(long& sec, long& usec)
- {
- TTime utc;
- utc.UniversalTime();
-
- TInt64 unixTime = utc.Int64() - UnixStart().Int64();
- sec = (unixTime/1000000).GetTInt();
- usec = (unixTime%1000000).GetTInt();
- return true;
- }
- inline
- CHXAvTimeValue::CHXAvTimeValue(long sec, long usec)
- : sec_(sec), usec_(usec)
- {
- normalize();
- }
-
- inline
- CHXAvTimeValue::CHXAvTimeValue(const CHXAvTimeValue& tv)
- : sec_(tv.sec_), usec_(tv.usec_)
- {}
- inline
- CHXAvTimeValue& CHXAvTimeValue::operator=(const CHXAvTimeValue& tv)
- {
- if (this != &tv) {
- sec_ = tv.sec_;
- usec_ = tv.usec_;
- }
- return *this;
- }
- inline
- CHXAvTimeValue& CHXAvTimeValue::operator+=(const CHXAvTimeValue& tv)
- {
- sec_ += tv.sec_;
- usec_ += tv.usec_;
- normalize();
- return *this;
- }
- inline
- CHXAvTimeValue& CHXAvTimeValue::operator-=(const CHXAvTimeValue& tv)
- {
- sec_ -= tv.sec_;
- usec_ -= tv.usec_;
- normalize();
- return *this;
- }
- inline
- long CHXAvTimeValue::sec() const
- {
- return sec_;
- }
- inline
- long CHXAvTimeValue::usec() const
- {
- return usec_;
- }
- inline
- CHXAvTimeValue CHXAvTimeValue::operator+(const CHXAvTimeValue& tv) const
- {
- CHXAvTimeValue sum(*this);
- return sum += tv;
- }
- inline
- CHXAvTimeValue CHXAvTimeValue::operator-(const CHXAvTimeValue& tv) const
- {
- CHXAvTimeValue delta(*this);
- return delta -= tv;
- }
- inline
- int CHXAvTimeValue::operator<(const CHXAvTimeValue& tv) const
- {
- return sec_ < tv.sec_ || (sec_ == tv.sec_ && usec_ < tv.usec_);
- }
- inline
- int CHXAvTimeValue::operator>(const CHXAvTimeValue& tv) const
- {
- return sec_ > tv.sec_ || (sec_ == tv.sec_ && usec_ > tv.usec_);
- }
- inline
- int CHXAvTimeValue::operator<=(const CHXAvTimeValue& tv) const
- {
- return sec_ < tv.sec_ || (sec_ == tv.sec_ && usec_ <= tv.usec_);
- }
- inline
- int CHXAvTimeValue::operator>=(const CHXAvTimeValue& tv) const
- {
- return sec_ > tv.sec_ || (sec_ == tv.sec_ && usec_ >= tv.usec_);
- }
- inline
- int CHXAvTimeValue::operator==(const CHXAvTimeValue& tv) const
- {
- return sec_ == tv.sec_ && usec_ == tv.usec_;
- }
- inline
- int CHXAvTimeValue::operator!=(const CHXAvTimeValue& tv) const
- {
- return sec_ != tv.sec_ || usec_ != tv.usec_;
- }
- // CHXAvTimeValue::now:
- // Get current time
- inline
- int CHXAvTimeValue::now(CHXAvTimeValue& tv)
- {
- int ok = 0;
-
- if ((ok = (GetTimeofDay(tv.sec_, tv.usec_))))
- tv.normalize();
- return ok;
- }
- #endif // UT_STREAM_VALUE_H