Back to index

lightning-sunbird  0.9+nobinonly
rcinrval.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 ** C++ interval times (ref: prinrval.h)
00040 **
00041 **  An interval is a period of time. The start of the interval (epoch)
00042 **  must be defined by the application. The unit of time of an interval
00043 **  is platform dependent, therefore so is the maximum interval that is
00044 **  representable. However, that interval is never less than ~6 hours.
00045 */
00046 #if defined(_RCINTERVAL_H)
00047 #else
00048 #define _RCINTERVAL_H
00049 
00050 #include "rcbase.h"
00051 #include <prinrval.h>
00052 
00053 class PR_IMPLEMENT(RCInterval): public RCBase
00054 {
00055 public:
00056     typedef enum {now, no_timeout, no_wait} RCReservedInterval;
00057 
00058     virtual ~RCInterval();
00059 
00060     RCInterval();
00061 
00062     RCInterval(PRIntervalTime interval);
00063     RCInterval(const RCInterval& copy);
00064     RCInterval(RCReservedInterval special);
00065 
00066     void SetToNow();
00067 
00068     void operator=(const RCInterval&);
00069     void operator=(PRIntervalTime interval);
00070 
00071     PRBool operator<(const RCInterval&);
00072     PRBool operator>(const RCInterval&);
00073     PRBool operator==(const RCInterval&);
00074     PRBool operator>=(const RCInterval&);
00075     PRBool operator<=(const RCInterval&);
00076 
00077     RCInterval operator+(const RCInterval&);
00078     RCInterval operator-(const RCInterval&);
00079     RCInterval& operator+=(const RCInterval&);
00080     RCInterval& operator-=(const RCInterval&);
00081 
00082     RCInterval operator/(PRUint32);
00083     RCInterval operator*(PRUint32);
00084     RCInterval& operator/=(PRUint32);
00085     RCInterval& operator*=(PRUint32);
00086 
00087 
00088     PRUint32 ToSeconds() const;
00089     PRUint32 ToMilliseconds() const;
00090     PRUint32 ToMicroseconds() const;
00091     operator PRIntervalTime() const;
00092 
00093     static PRIntervalTime FromSeconds(PRUint32 seconds);
00094     static PRIntervalTime FromMilliseconds(PRUint32 milli);
00095     static PRIntervalTime FromMicroseconds(PRUint32 micro);
00096 
00097     friend class RCCondition;
00098 
00099 private:
00100     PRIntervalTime interval;
00101     
00102 };  /* RCInterval */
00103 
00104 
00105 inline RCInterval::RCInterval(): RCBase() { }
00106 
00107 inline RCInterval::RCInterval(const RCInterval& his): RCBase()
00108     { interval = his.interval; }
00109 
00110 inline RCInterval::RCInterval(PRIntervalTime ticks): RCBase()
00111     { interval = ticks; }
00112 
00113 inline void RCInterval::SetToNow() { interval = PR_IntervalNow(); }
00114 
00115 inline void RCInterval::operator=(const RCInterval& his)
00116     { interval = his.interval; }
00117 
00118 inline void RCInterval::operator=(PRIntervalTime his)
00119     { interval = his; }
00120 
00121 inline PRBool RCInterval::operator==(const RCInterval& his)
00122     { return (interval == his.interval) ? PR_TRUE : PR_FALSE; }
00123 inline PRBool RCInterval::operator<(const RCInterval& his)
00124     { return (interval < his.interval)? PR_TRUE : PR_FALSE; }
00125 inline PRBool RCInterval::operator>(const RCInterval& his)
00126     { return (interval > his.interval) ? PR_TRUE : PR_FALSE; }
00127 inline PRBool RCInterval::operator<=(const RCInterval& his)
00128     { return (interval <= his.interval) ? PR_TRUE : PR_FALSE; }
00129 inline PRBool RCInterval::operator>=(const RCInterval& his)
00130     { return (interval <= his.interval) ? PR_TRUE : PR_FALSE; }
00131 
00132 inline RCInterval RCInterval::operator+(const RCInterval& his)
00133     { return RCInterval((PRIntervalTime)(interval + his.interval)); }
00134 inline RCInterval RCInterval::operator-(const RCInterval& his)
00135     { return RCInterval((PRIntervalTime)(interval - his.interval)); }
00136 inline RCInterval& RCInterval::operator+=(const RCInterval& his)
00137     { interval += his.interval; return *this; }
00138 inline RCInterval& RCInterval::operator-=(const RCInterval& his)
00139     { interval -= his.interval; return *this; }
00140 
00141 inline RCInterval RCInterval::operator/(PRUint32 him)
00142     { return RCInterval((PRIntervalTime)(interval / him)); }
00143 inline RCInterval RCInterval::operator*(PRUint32 him)
00144     { return RCInterval((PRIntervalTime)(interval * him)); }
00145 
00146 inline RCInterval& RCInterval::operator/=(PRUint32 him)
00147     { interval /= him; return *this; }
00148 
00149 inline RCInterval& RCInterval::operator*=(PRUint32 him)
00150     { interval *= him; return *this; }
00151 
00152 inline PRUint32 RCInterval::ToSeconds() const
00153     { return PR_IntervalToSeconds(interval); }
00154 inline PRUint32 RCInterval::ToMilliseconds() const
00155     { return PR_IntervalToMilliseconds(interval); }
00156 inline PRUint32 RCInterval::ToMicroseconds() const
00157     { return PR_IntervalToMicroseconds(interval); }
00158 inline RCInterval::operator PRIntervalTime() const { return interval; }
00159 
00160 inline PRIntervalTime RCInterval::FromSeconds(PRUint32 seconds)
00161     { return PR_SecondsToInterval(seconds); }
00162 inline PRIntervalTime RCInterval::FromMilliseconds(PRUint32 milli)
00163     { return PR_MillisecondsToInterval(milli); }
00164 inline PRIntervalTime RCInterval::FromMicroseconds(PRUint32 micro)
00165     { return PR_MicrosecondsToInterval(micro); }
00166 
00167 #endif  /* defined(_RCINTERVAL_H) */
00168 
00169 /* RCInterval.h */