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.

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

mercurial