Back to index

lightning-sunbird  0.9+nobinonly
rctime.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /*
00039 ** Class definitions for calendar time routines (ref: prtime.h)
00040 */
00041 
00042 #if defined(_RCTIME_H)
00043 #else
00044 #define _RCTIME_H
00045 
00046 #include "rcbase.h"
00047 
00048 #include <prtime.h>
00049 
00050 /*
00051 ** Class: RCTime (ref: prtime.h)
00052 **
00053 ** RCTimes are objects that are intended to be used to represent calendar
00054 ** times. They maintain units internally as microseconds since the defined
00055 ** epoch (midnight, January 1, 1970, GMT). Conversions to and from external
00056 ** formats (PRExplodedTime) are available.
00057 **
00058 ** In general, NCTimes possess normal algebretic capabilities.
00059 */
00060 
00061 class PR_IMPLEMENT(RCTime): public RCBase
00062 {
00063 public:
00064     typedef enum {now} Current;
00065 
00066     RCTime();                       /* leaves the object unitialized */
00067     RCTime(Current);                /* initializes to current system time */
00068     RCTime(const RCTime&);          /* copy constructor */
00069     RCTime(const PRExplodedTime&);  /* construction from exploded representation */
00070 
00071     virtual ~RCTime();
00072 
00073     /* assignment operators */
00074     void operator=(const RCTime&); 
00075     void operator=(const PRExplodedTime&);
00076 
00077     /* comparitive operators */
00078     PRBool operator<(const RCTime&);
00079     PRBool operator>(const RCTime&);
00080     PRBool operator<=(const RCTime&);
00081     PRBool operator>=(const RCTime&);
00082     PRBool operator==(const RCTime&);
00083 
00084     /* associative operators */
00085     RCTime operator+(const RCTime&);
00086     RCTime operator-(const RCTime&);
00087     RCTime& operator+=(const RCTime&);
00088     RCTime& operator-=(const RCTime&);
00089 
00090     /* multiply and divide operators */
00091     RCTime operator/(PRUint64);
00092     RCTime operator*(PRUint64);
00093     RCTime& operator/=(PRUint64);
00094     RCTime& operator*=(PRUint64);
00095 
00096     void Now();                     /* assign current time to object */
00097 
00098 private:
00099     PRTime gmt;
00100 
00101 public:
00102 
00103     RCTime(PRTime);                 /* construct from raw PRTime */
00104     void operator=(PRTime);         /* assign from raw PRTime */
00105     operator PRTime() const;        /* extract internal representation */
00106 };  /* RCTime */
00107 
00108 inline RCTime::RCTime(): RCBase() { }
00109 
00110 inline void RCTime::Now() { gmt = PR_Now(); }
00111 inline RCTime::operator PRTime() const { return gmt; }
00112 
00113 inline void RCTime::operator=(PRTime his) { gmt = his; }
00114 inline void RCTime::operator=(const RCTime& his) { gmt = his.gmt; }
00115 
00116 inline PRBool RCTime::operator<(const RCTime& his)
00117     { return (gmt < his.gmt) ? PR_TRUE : PR_FALSE; }
00118 inline PRBool RCTime::operator>(const RCTime& his)
00119     { return (gmt > his.gmt) ? PR_TRUE : PR_FALSE; }
00120 inline PRBool RCTime::operator<=(const RCTime& his)
00121     { return (gmt <= his.gmt) ? PR_TRUE : PR_FALSE; }
00122 inline PRBool RCTime::operator>=(const RCTime& his)
00123     { return (gmt >= his.gmt) ? PR_TRUE : PR_FALSE; }
00124 inline PRBool RCTime::operator==(const RCTime& his)
00125     { return (gmt == his.gmt) ? PR_TRUE : PR_FALSE; }
00126 
00127 inline RCTime& RCTime::operator+=(const RCTime& his)
00128     { gmt += his.gmt; return *this; }
00129 inline RCTime& RCTime::operator-=(const RCTime& his)
00130     { gmt -= his.gmt; return *this; }
00131 inline RCTime& RCTime::operator/=(PRUint64 his)
00132     { gmt /= his; return *this; }
00133 inline RCTime& RCTime::operator*=(PRUint64 his)
00134     { gmt *= his; return *this; }
00135 
00136 #endif /* defined(_RCTIME_H) */
00137 
00138 /* RCTime.h */