1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/src/cplus/rctime.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,106 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 +** Class definitions for calendar time routines (ref: prtime.h) 1.11 +*/ 1.12 + 1.13 +#if defined(_RCTIME_H) 1.14 +#else 1.15 +#define _RCTIME_H 1.16 + 1.17 +#include "rcbase.h" 1.18 + 1.19 +#include <prtime.h> 1.20 + 1.21 +/* 1.22 +** Class: RCTime (ref: prtime.h) 1.23 +** 1.24 +** RCTimes are objects that are intended to be used to represent calendar 1.25 +** times. They maintain units internally as microseconds since the defined 1.26 +** epoch (midnight, January 1, 1970, GMT). Conversions to and from external 1.27 +** formats (PRExplodedTime) are available. 1.28 +** 1.29 +** In general, NCTimes possess normal algebretic capabilities. 1.30 +*/ 1.31 + 1.32 +class PR_IMPLEMENT(RCTime): public RCBase 1.33 +{ 1.34 +public: 1.35 + typedef enum {now} Current; 1.36 + 1.37 + RCTime(); /* leaves the object unitialized */ 1.38 + RCTime(Current); /* initializes to current system time */ 1.39 + RCTime(const RCTime&); /* copy constructor */ 1.40 + RCTime(const PRExplodedTime&); /* construction from exploded representation */ 1.41 + 1.42 + virtual ~RCTime(); 1.43 + 1.44 + /* assignment operators */ 1.45 + void operator=(const RCTime&); 1.46 + void operator=(const PRExplodedTime&); 1.47 + 1.48 + /* comparitive operators */ 1.49 + PRBool operator<(const RCTime&); 1.50 + PRBool operator>(const RCTime&); 1.51 + PRBool operator<=(const RCTime&); 1.52 + PRBool operator>=(const RCTime&); 1.53 + PRBool operator==(const RCTime&); 1.54 + 1.55 + /* associative operators */ 1.56 + RCTime operator+(const RCTime&); 1.57 + RCTime operator-(const RCTime&); 1.58 + RCTime& operator+=(const RCTime&); 1.59 + RCTime& operator-=(const RCTime&); 1.60 + 1.61 + /* multiply and divide operators */ 1.62 + RCTime operator/(PRUint64); 1.63 + RCTime operator*(PRUint64); 1.64 + RCTime& operator/=(PRUint64); 1.65 + RCTime& operator*=(PRUint64); 1.66 + 1.67 + void Now(); /* assign current time to object */ 1.68 + 1.69 +private: 1.70 + PRTime gmt; 1.71 + 1.72 +public: 1.73 + 1.74 + RCTime(PRTime); /* construct from raw PRTime */ 1.75 + void operator=(PRTime); /* assign from raw PRTime */ 1.76 + operator PRTime() const; /* extract internal representation */ 1.77 +}; /* RCTime */ 1.78 + 1.79 +inline RCTime::RCTime(): RCBase() { } 1.80 + 1.81 +inline void RCTime::Now() { gmt = PR_Now(); } 1.82 +inline RCTime::operator PRTime() const { return gmt; } 1.83 + 1.84 +inline void RCTime::operator=(PRTime his) { gmt = his; } 1.85 +inline void RCTime::operator=(const RCTime& his) { gmt = his.gmt; } 1.86 + 1.87 +inline PRBool RCTime::operator<(const RCTime& his) 1.88 + { return (gmt < his.gmt) ? PR_TRUE : PR_FALSE; } 1.89 +inline PRBool RCTime::operator>(const RCTime& his) 1.90 + { return (gmt > his.gmt) ? PR_TRUE : PR_FALSE; } 1.91 +inline PRBool RCTime::operator<=(const RCTime& his) 1.92 + { return (gmt <= his.gmt) ? PR_TRUE : PR_FALSE; } 1.93 +inline PRBool RCTime::operator>=(const RCTime& his) 1.94 + { return (gmt >= his.gmt) ? PR_TRUE : PR_FALSE; } 1.95 +inline PRBool RCTime::operator==(const RCTime& his) 1.96 + { return (gmt == his.gmt) ? PR_TRUE : PR_FALSE; } 1.97 + 1.98 +inline RCTime& RCTime::operator+=(const RCTime& his) 1.99 + { gmt += his.gmt; return *this; } 1.100 +inline RCTime& RCTime::operator-=(const RCTime& his) 1.101 + { gmt -= his.gmt; return *this; } 1.102 +inline RCTime& RCTime::operator/=(PRUint64 his) 1.103 + { gmt /= his; return *this; } 1.104 +inline RCTime& RCTime::operator*=(PRUint64 his) 1.105 + { gmt *= his; return *this; } 1.106 + 1.107 +#endif /* defined(_RCTIME_H) */ 1.108 + 1.109 +/* RCTime.h */