|
PPL
0.12.1
|
00001 /* Time class implementation: inline functions. 00002 Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it> 00003 Copyright (C) 2010-2012 BUGSENG srl (http://bugseng.com) 00004 00005 This file is part of the Parma Polyhedra Library (PPL). 00006 00007 The PPL is free software; you can redistribute it and/or modify it 00008 under the terms of the GNU General Public License as published by the 00009 Free Software Foundation; either version 3 of the License, or (at your 00010 option) any later version. 00011 00012 The PPL is distributed in the hope that it will be useful, but WITHOUT 00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00015 for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software Foundation, 00019 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. 00020 00021 For the most up-to-date information see the Parma Polyhedra Library 00022 site: http://bugseng.com/products/ppl/ . */ 00023 00024 #ifndef PPL_Time_inlines_hh 00025 #define PPL_Time_inlines_hh 1 00026 00027 #include <cassert> 00028 00029 namespace Parma_Polyhedra_Library { 00030 00031 namespace Implementation { 00032 00033 namespace Watchdog { 00034 00035 inline 00036 Time::Time() 00037 : secs(0), microsecs(0) { 00038 assert(OK()); 00039 } 00040 00041 inline 00042 Time::Time(long centisecs) 00043 : secs(centisecs / CSECS_PER_SEC), 00044 microsecs((centisecs % CSECS_PER_SEC) * (USECS_PER_SEC/CSECS_PER_SEC)) { 00045 assert(OK()); 00046 } 00047 00048 inline 00049 Time::Time(long s, long m) 00050 : secs(s), 00051 microsecs(m) { 00052 if (microsecs >= USECS_PER_SEC) { 00053 secs += microsecs / USECS_PER_SEC; 00054 microsecs %= USECS_PER_SEC; 00055 } 00056 assert(OK()); 00057 } 00058 00059 inline long 00060 Time::seconds() const { 00061 return secs; 00062 } 00063 00064 inline long 00065 Time::microseconds() const { 00066 return microsecs; 00067 } 00068 00069 inline Time& 00070 Time::operator+=(const Time& y) { 00071 long r_secs = secs + y.secs; 00072 long r_microsecs = microsecs + y.microsecs; 00073 if (r_microsecs >= USECS_PER_SEC) { 00074 ++r_secs; 00075 r_microsecs %= USECS_PER_SEC; 00076 } 00077 secs = r_secs; 00078 microsecs = r_microsecs; 00079 assert(OK()); 00080 return *this; 00081 } 00082 00083 inline Time& 00084 Time::operator-=(const Time& y) { 00085 long r_secs = secs - y.secs; 00086 long r_microsecs = microsecs - y.microsecs; 00087 if (r_microsecs < 0) { 00088 --r_secs; 00089 r_microsecs += USECS_PER_SEC; 00090 } 00091 if (r_secs < 0) { 00092 r_secs = 0; 00093 r_microsecs = 0; 00094 } 00095 secs = r_secs; 00096 microsecs = r_microsecs; 00097 assert(OK()); 00098 return *this; 00099 } 00100 00101 inline Time 00102 operator+(const Time& x, const Time& y) { 00103 Time z = x; 00104 z += y; 00105 return z; 00106 } 00107 00108 inline Time 00109 operator-(const Time& x, const Time& y) { 00110 Time z = x; 00111 z -= y; 00112 return z; 00113 } 00114 00115 inline bool 00116 operator==(const Time& x, const Time& y) { 00117 assert(x.OK() && y.OK()); 00118 return x.seconds() == y.seconds() && y.microseconds() == y.microseconds(); 00119 } 00120 00121 inline bool 00122 operator!=(const Time& x, const Time& y) { 00123 assert(x.OK() && y.OK()); 00124 return !(x == y); 00125 } 00126 00127 inline bool 00128 operator<(const Time& x, const Time& y) { 00129 assert(x.OK() && y.OK()); 00130 return x.seconds() < y.seconds() 00131 || (x.seconds() == y.seconds() && x.microseconds() < y.microseconds()); 00132 } 00133 00134 inline bool 00135 operator<=(const Time& x, const Time& y) { 00136 return x < y || x == y; 00137 } 00138 00139 inline bool 00140 operator>(const Time& x, const Time& y) { 00141 return y < x; 00142 } 00143 00144 inline bool 00145 operator>=(const Time& x, const Time& y) { 00146 return y <= x; 00147 } 00148 00149 } // namespace Watchdog 00150 00151 } // namespace Implementation 00152 00153 } // namespace Parma_Polyhedra_Library 00154 00155 #endif // !defined(PPL_Time_inlines_hh)