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