michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: ** C++ interval times (ref: prinrval.h) michael@0: ** michael@0: ** An interval is a period of time. The start of the interval (epoch) michael@0: ** must be defined by the application. The unit of time of an interval michael@0: ** is platform dependent, therefore so is the maximum interval that is michael@0: ** representable. However, that interval is never less than ~6 hours. michael@0: */ michael@0: #if defined(_RCINTERVAL_H) michael@0: #else michael@0: #define _RCINTERVAL_H michael@0: michael@0: #include "rcbase.h" michael@0: #include michael@0: michael@0: class PR_IMPLEMENT(RCInterval): public RCBase michael@0: { michael@0: public: michael@0: typedef enum {now, no_timeout, no_wait} RCReservedInterval; michael@0: michael@0: virtual ~RCInterval(); michael@0: michael@0: RCInterval(); michael@0: michael@0: RCInterval(PRIntervalTime interval); michael@0: RCInterval(const RCInterval& copy); michael@0: RCInterval(RCReservedInterval special); michael@0: michael@0: void SetToNow(); michael@0: michael@0: void operator=(const RCInterval&); michael@0: void operator=(PRIntervalTime interval); michael@0: michael@0: PRBool operator<(const RCInterval&); michael@0: PRBool operator>(const RCInterval&); michael@0: PRBool operator==(const RCInterval&); michael@0: PRBool operator>=(const RCInterval&); michael@0: PRBool operator<=(const RCInterval&); michael@0: michael@0: RCInterval operator+(const RCInterval&); michael@0: RCInterval operator-(const RCInterval&); michael@0: RCInterval& operator+=(const RCInterval&); michael@0: RCInterval& operator-=(const RCInterval&); michael@0: michael@0: RCInterval operator/(PRUint32); michael@0: RCInterval operator*(PRUint32); michael@0: RCInterval& operator/=(PRUint32); michael@0: RCInterval& operator*=(PRUint32); michael@0: michael@0: michael@0: PRUint32 ToSeconds() const; michael@0: PRUint32 ToMilliseconds() const; michael@0: PRUint32 ToMicroseconds() const; michael@0: operator PRIntervalTime() const; michael@0: michael@0: static PRIntervalTime FromSeconds(PRUint32 seconds); michael@0: static PRIntervalTime FromMilliseconds(PRUint32 milli); michael@0: static PRIntervalTime FromMicroseconds(PRUint32 micro); michael@0: michael@0: friend class RCCondition; michael@0: michael@0: private: michael@0: PRIntervalTime interval; michael@0: michael@0: }; /* RCInterval */ michael@0: michael@0: michael@0: inline RCInterval::RCInterval(): RCBase() { } michael@0: michael@0: inline RCInterval::RCInterval(const RCInterval& his): RCBase() michael@0: { interval = his.interval; } michael@0: michael@0: inline RCInterval::RCInterval(PRIntervalTime ticks): RCBase() michael@0: { interval = ticks; } michael@0: michael@0: inline void RCInterval::SetToNow() { interval = PR_IntervalNow(); } michael@0: michael@0: inline void RCInterval::operator=(const RCInterval& his) michael@0: { interval = his.interval; } michael@0: michael@0: inline void RCInterval::operator=(PRIntervalTime his) michael@0: { interval = his; } michael@0: michael@0: inline PRBool RCInterval::operator==(const RCInterval& his) michael@0: { return (interval == his.interval) ? PR_TRUE : PR_FALSE; } michael@0: inline PRBool RCInterval::operator<(const RCInterval& his) michael@0: { return (interval < his.interval)? PR_TRUE : PR_FALSE; } michael@0: inline PRBool RCInterval::operator>(const RCInterval& his) michael@0: { return (interval > his.interval) ? PR_TRUE : PR_FALSE; } michael@0: inline PRBool RCInterval::operator<=(const RCInterval& his) michael@0: { return (interval <= his.interval) ? PR_TRUE : PR_FALSE; } michael@0: inline PRBool RCInterval::operator>=(const RCInterval& his) michael@0: { return (interval <= his.interval) ? PR_TRUE : PR_FALSE; } michael@0: michael@0: inline RCInterval RCInterval::operator+(const RCInterval& his) michael@0: { return RCInterval((PRIntervalTime)(interval + his.interval)); } michael@0: inline RCInterval RCInterval::operator-(const RCInterval& his) michael@0: { return RCInterval((PRIntervalTime)(interval - his.interval)); } michael@0: inline RCInterval& RCInterval::operator+=(const RCInterval& his) michael@0: { interval += his.interval; return *this; } michael@0: inline RCInterval& RCInterval::operator-=(const RCInterval& his) michael@0: { interval -= his.interval; return *this; } michael@0: michael@0: inline RCInterval RCInterval::operator/(PRUint32 him) michael@0: { return RCInterval((PRIntervalTime)(interval / him)); } michael@0: inline RCInterval RCInterval::operator*(PRUint32 him) michael@0: { return RCInterval((PRIntervalTime)(interval * him)); } michael@0: michael@0: inline RCInterval& RCInterval::operator/=(PRUint32 him) michael@0: { interval /= him; return *this; } michael@0: michael@0: inline RCInterval& RCInterval::operator*=(PRUint32 him) michael@0: { interval *= him; return *this; } michael@0: michael@0: inline PRUint32 RCInterval::ToSeconds() const michael@0: { return PR_IntervalToSeconds(interval); } michael@0: inline PRUint32 RCInterval::ToMilliseconds() const michael@0: { return PR_IntervalToMilliseconds(interval); } michael@0: inline PRUint32 RCInterval::ToMicroseconds() const michael@0: { return PR_IntervalToMicroseconds(interval); } michael@0: inline RCInterval::operator PRIntervalTime() const { return interval; } michael@0: michael@0: inline PRIntervalTime RCInterval::FromSeconds(PRUint32 seconds) michael@0: { return PR_SecondsToInterval(seconds); } michael@0: inline PRIntervalTime RCInterval::FromMilliseconds(PRUint32 milli) michael@0: { return PR_MillisecondsToInterval(milli); } michael@0: inline PRIntervalTime RCInterval::FromMicroseconds(PRUint32 micro) michael@0: { return PR_MicrosecondsToInterval(micro); } michael@0: michael@0: #endif /* defined(_RCINTERVAL_H) */ michael@0: michael@0: /* RCInterval.h */