nsprpub/pr/src/cplus/rctime.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 ** Class definitions for calendar time routines (ref: prtime.h)
michael@0 8 */
michael@0 9
michael@0 10 #if defined(_RCTIME_H)
michael@0 11 #else
michael@0 12 #define _RCTIME_H
michael@0 13
michael@0 14 #include "rcbase.h"
michael@0 15
michael@0 16 #include <prtime.h>
michael@0 17
michael@0 18 /*
michael@0 19 ** Class: RCTime (ref: prtime.h)
michael@0 20 **
michael@0 21 ** RCTimes are objects that are intended to be used to represent calendar
michael@0 22 ** times. They maintain units internally as microseconds since the defined
michael@0 23 ** epoch (midnight, January 1, 1970, GMT). Conversions to and from external
michael@0 24 ** formats (PRExplodedTime) are available.
michael@0 25 **
michael@0 26 ** In general, NCTimes possess normal algebretic capabilities.
michael@0 27 */
michael@0 28
michael@0 29 class PR_IMPLEMENT(RCTime): public RCBase
michael@0 30 {
michael@0 31 public:
michael@0 32 typedef enum {now} Current;
michael@0 33
michael@0 34 RCTime(); /* leaves the object unitialized */
michael@0 35 RCTime(Current); /* initializes to current system time */
michael@0 36 RCTime(const RCTime&); /* copy constructor */
michael@0 37 RCTime(const PRExplodedTime&); /* construction from exploded representation */
michael@0 38
michael@0 39 virtual ~RCTime();
michael@0 40
michael@0 41 /* assignment operators */
michael@0 42 void operator=(const RCTime&);
michael@0 43 void operator=(const PRExplodedTime&);
michael@0 44
michael@0 45 /* comparitive operators */
michael@0 46 PRBool operator<(const RCTime&);
michael@0 47 PRBool operator>(const RCTime&);
michael@0 48 PRBool operator<=(const RCTime&);
michael@0 49 PRBool operator>=(const RCTime&);
michael@0 50 PRBool operator==(const RCTime&);
michael@0 51
michael@0 52 /* associative operators */
michael@0 53 RCTime operator+(const RCTime&);
michael@0 54 RCTime operator-(const RCTime&);
michael@0 55 RCTime& operator+=(const RCTime&);
michael@0 56 RCTime& operator-=(const RCTime&);
michael@0 57
michael@0 58 /* multiply and divide operators */
michael@0 59 RCTime operator/(PRUint64);
michael@0 60 RCTime operator*(PRUint64);
michael@0 61 RCTime& operator/=(PRUint64);
michael@0 62 RCTime& operator*=(PRUint64);
michael@0 63
michael@0 64 void Now(); /* assign current time to object */
michael@0 65
michael@0 66 private:
michael@0 67 PRTime gmt;
michael@0 68
michael@0 69 public:
michael@0 70
michael@0 71 RCTime(PRTime); /* construct from raw PRTime */
michael@0 72 void operator=(PRTime); /* assign from raw PRTime */
michael@0 73 operator PRTime() const; /* extract internal representation */
michael@0 74 }; /* RCTime */
michael@0 75
michael@0 76 inline RCTime::RCTime(): RCBase() { }
michael@0 77
michael@0 78 inline void RCTime::Now() { gmt = PR_Now(); }
michael@0 79 inline RCTime::operator PRTime() const { return gmt; }
michael@0 80
michael@0 81 inline void RCTime::operator=(PRTime his) { gmt = his; }
michael@0 82 inline void RCTime::operator=(const RCTime& his) { gmt = his.gmt; }
michael@0 83
michael@0 84 inline PRBool RCTime::operator<(const RCTime& his)
michael@0 85 { return (gmt < his.gmt) ? PR_TRUE : PR_FALSE; }
michael@0 86 inline PRBool RCTime::operator>(const RCTime& his)
michael@0 87 { return (gmt > his.gmt) ? PR_TRUE : PR_FALSE; }
michael@0 88 inline PRBool RCTime::operator<=(const RCTime& his)
michael@0 89 { return (gmt <= his.gmt) ? PR_TRUE : PR_FALSE; }
michael@0 90 inline PRBool RCTime::operator>=(const RCTime& his)
michael@0 91 { return (gmt >= his.gmt) ? PR_TRUE : PR_FALSE; }
michael@0 92 inline PRBool RCTime::operator==(const RCTime& his)
michael@0 93 { return (gmt == his.gmt) ? PR_TRUE : PR_FALSE; }
michael@0 94
michael@0 95 inline RCTime& RCTime::operator+=(const RCTime& his)
michael@0 96 { gmt += his.gmt; return *this; }
michael@0 97 inline RCTime& RCTime::operator-=(const RCTime& his)
michael@0 98 { gmt -= his.gmt; return *this; }
michael@0 99 inline RCTime& RCTime::operator/=(PRUint64 his)
michael@0 100 { gmt /= his; return *this; }
michael@0 101 inline RCTime& RCTime::operator*=(PRUint64 his)
michael@0 102 { gmt *= his; return *this; }
michael@0 103
michael@0 104 #endif /* defined(_RCTIME_H) */
michael@0 105
michael@0 106 /* RCTime.h */

mercurial