Wed, 31 Dec 2014 06:55:46 +0100
Added tag TORBROWSER_REPLICA for changeset 6474c204b198
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* |
michael@0 | 7 | ** C++ interval times (ref: prinrval.h) |
michael@0 | 8 | ** |
michael@0 | 9 | ** An interval is a period of time. The start of the interval (epoch) |
michael@0 | 10 | ** must be defined by the application. The unit of time of an interval |
michael@0 | 11 | ** is platform dependent, therefore so is the maximum interval that is |
michael@0 | 12 | ** representable. However, that interval is never less than ~6 hours. |
michael@0 | 13 | */ |
michael@0 | 14 | #if defined(_RCINTERVAL_H) |
michael@0 | 15 | #else |
michael@0 | 16 | #define _RCINTERVAL_H |
michael@0 | 17 | |
michael@0 | 18 | #include "rcbase.h" |
michael@0 | 19 | #include <prinrval.h> |
michael@0 | 20 | |
michael@0 | 21 | class PR_IMPLEMENT(RCInterval): public RCBase |
michael@0 | 22 | { |
michael@0 | 23 | public: |
michael@0 | 24 | typedef enum {now, no_timeout, no_wait} RCReservedInterval; |
michael@0 | 25 | |
michael@0 | 26 | virtual ~RCInterval(); |
michael@0 | 27 | |
michael@0 | 28 | RCInterval(); |
michael@0 | 29 | |
michael@0 | 30 | RCInterval(PRIntervalTime interval); |
michael@0 | 31 | RCInterval(const RCInterval& copy); |
michael@0 | 32 | RCInterval(RCReservedInterval special); |
michael@0 | 33 | |
michael@0 | 34 | void SetToNow(); |
michael@0 | 35 | |
michael@0 | 36 | void operator=(const RCInterval&); |
michael@0 | 37 | void operator=(PRIntervalTime interval); |
michael@0 | 38 | |
michael@0 | 39 | PRBool operator<(const RCInterval&); |
michael@0 | 40 | PRBool operator>(const RCInterval&); |
michael@0 | 41 | PRBool operator==(const RCInterval&); |
michael@0 | 42 | PRBool operator>=(const RCInterval&); |
michael@0 | 43 | PRBool operator<=(const RCInterval&); |
michael@0 | 44 | |
michael@0 | 45 | RCInterval operator+(const RCInterval&); |
michael@0 | 46 | RCInterval operator-(const RCInterval&); |
michael@0 | 47 | RCInterval& operator+=(const RCInterval&); |
michael@0 | 48 | RCInterval& operator-=(const RCInterval&); |
michael@0 | 49 | |
michael@0 | 50 | RCInterval operator/(PRUint32); |
michael@0 | 51 | RCInterval operator*(PRUint32); |
michael@0 | 52 | RCInterval& operator/=(PRUint32); |
michael@0 | 53 | RCInterval& operator*=(PRUint32); |
michael@0 | 54 | |
michael@0 | 55 | |
michael@0 | 56 | PRUint32 ToSeconds() const; |
michael@0 | 57 | PRUint32 ToMilliseconds() const; |
michael@0 | 58 | PRUint32 ToMicroseconds() const; |
michael@0 | 59 | operator PRIntervalTime() const; |
michael@0 | 60 | |
michael@0 | 61 | static PRIntervalTime FromSeconds(PRUint32 seconds); |
michael@0 | 62 | static PRIntervalTime FromMilliseconds(PRUint32 milli); |
michael@0 | 63 | static PRIntervalTime FromMicroseconds(PRUint32 micro); |
michael@0 | 64 | |
michael@0 | 65 | friend class RCCondition; |
michael@0 | 66 | |
michael@0 | 67 | private: |
michael@0 | 68 | PRIntervalTime interval; |
michael@0 | 69 | |
michael@0 | 70 | }; /* RCInterval */ |
michael@0 | 71 | |
michael@0 | 72 | |
michael@0 | 73 | inline RCInterval::RCInterval(): RCBase() { } |
michael@0 | 74 | |
michael@0 | 75 | inline RCInterval::RCInterval(const RCInterval& his): RCBase() |
michael@0 | 76 | { interval = his.interval; } |
michael@0 | 77 | |
michael@0 | 78 | inline RCInterval::RCInterval(PRIntervalTime ticks): RCBase() |
michael@0 | 79 | { interval = ticks; } |
michael@0 | 80 | |
michael@0 | 81 | inline void RCInterval::SetToNow() { interval = PR_IntervalNow(); } |
michael@0 | 82 | |
michael@0 | 83 | inline void RCInterval::operator=(const RCInterval& his) |
michael@0 | 84 | { interval = his.interval; } |
michael@0 | 85 | |
michael@0 | 86 | inline void RCInterval::operator=(PRIntervalTime his) |
michael@0 | 87 | { interval = his; } |
michael@0 | 88 | |
michael@0 | 89 | inline PRBool RCInterval::operator==(const RCInterval& his) |
michael@0 | 90 | { return (interval == his.interval) ? PR_TRUE : PR_FALSE; } |
michael@0 | 91 | inline PRBool RCInterval::operator<(const RCInterval& his) |
michael@0 | 92 | { return (interval < his.interval)? PR_TRUE : PR_FALSE; } |
michael@0 | 93 | inline PRBool RCInterval::operator>(const RCInterval& his) |
michael@0 | 94 | { return (interval > his.interval) ? PR_TRUE : PR_FALSE; } |
michael@0 | 95 | inline PRBool RCInterval::operator<=(const RCInterval& his) |
michael@0 | 96 | { return (interval <= his.interval) ? PR_TRUE : PR_FALSE; } |
michael@0 | 97 | inline PRBool RCInterval::operator>=(const RCInterval& his) |
michael@0 | 98 | { return (interval <= his.interval) ? PR_TRUE : PR_FALSE; } |
michael@0 | 99 | |
michael@0 | 100 | inline RCInterval RCInterval::operator+(const RCInterval& his) |
michael@0 | 101 | { return RCInterval((PRIntervalTime)(interval + his.interval)); } |
michael@0 | 102 | inline RCInterval RCInterval::operator-(const RCInterval& his) |
michael@0 | 103 | { return RCInterval((PRIntervalTime)(interval - his.interval)); } |
michael@0 | 104 | inline RCInterval& RCInterval::operator+=(const RCInterval& his) |
michael@0 | 105 | { interval += his.interval; return *this; } |
michael@0 | 106 | inline RCInterval& RCInterval::operator-=(const RCInterval& his) |
michael@0 | 107 | { interval -= his.interval; return *this; } |
michael@0 | 108 | |
michael@0 | 109 | inline RCInterval RCInterval::operator/(PRUint32 him) |
michael@0 | 110 | { return RCInterval((PRIntervalTime)(interval / him)); } |
michael@0 | 111 | inline RCInterval RCInterval::operator*(PRUint32 him) |
michael@0 | 112 | { return RCInterval((PRIntervalTime)(interval * him)); } |
michael@0 | 113 | |
michael@0 | 114 | inline RCInterval& RCInterval::operator/=(PRUint32 him) |
michael@0 | 115 | { interval /= him; return *this; } |
michael@0 | 116 | |
michael@0 | 117 | inline RCInterval& RCInterval::operator*=(PRUint32 him) |
michael@0 | 118 | { interval *= him; return *this; } |
michael@0 | 119 | |
michael@0 | 120 | inline PRUint32 RCInterval::ToSeconds() const |
michael@0 | 121 | { return PR_IntervalToSeconds(interval); } |
michael@0 | 122 | inline PRUint32 RCInterval::ToMilliseconds() const |
michael@0 | 123 | { return PR_IntervalToMilliseconds(interval); } |
michael@0 | 124 | inline PRUint32 RCInterval::ToMicroseconds() const |
michael@0 | 125 | { return PR_IntervalToMicroseconds(interval); } |
michael@0 | 126 | inline RCInterval::operator PRIntervalTime() const { return interval; } |
michael@0 | 127 | |
michael@0 | 128 | inline PRIntervalTime RCInterval::FromSeconds(PRUint32 seconds) |
michael@0 | 129 | { return PR_SecondsToInterval(seconds); } |
michael@0 | 130 | inline PRIntervalTime RCInterval::FromMilliseconds(PRUint32 milli) |
michael@0 | 131 | { return PR_MillisecondsToInterval(milli); } |
michael@0 | 132 | inline PRIntervalTime RCInterval::FromMicroseconds(PRUint32 micro) |
michael@0 | 133 | { return PR_MicrosecondsToInterval(micro); } |
michael@0 | 134 | |
michael@0 | 135 | #endif /* defined(_RCINTERVAL_H) */ |
michael@0 | 136 | |
michael@0 | 137 | /* RCInterval.h */ |