00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef TOOL_MICROSECONDS_HXX_
00023 # define TOOL_MICROSECONDS_HXX_
00024
00025 # include <cassert>
00026
00027 # include <wipal/tool/gmp_64_wrapper.hh>
00028
00029 # include "microseconds.hh"
00030
00031 namespace tool
00032 {
00033
00034 inline
00035 microseconds::microseconds(const uint64_t i):
00036 mpz_class (tool::mpz_of_uint64(i))
00037 {
00038 }
00039
00040 inline
00041 microseconds::microseconds(const struct timeval& tv): mpz_class (tv.tv_sec)
00042 {
00043 *this *= 1000000;
00044 *this += tv.tv_usec;
00045 }
00046
00047 inline
00048 microseconds::microseconds(const mpz_type& z): mpz_class (z)
00049 {
00050 }
00051
00052 template <class T1, class T2>
00053 microseconds::microseconds(const __gmp_expr<T1, T2>& e): mpz_class (e)
00054 {
00055 }
00056
00057 inline
00058 uint32_t
00059 microseconds::get_prism_mactime() const
00060 {
00061 return sgn(*this) < 0? -get_ui(): get_ui();
00062 }
00063
00064 inline
00065 uint32_t
00066 microseconds::get_prism_hosttime() const
00067 {
00068 mpz_type r = *this / 10;
00069
00070 return sgn(r) < 0? -r.get_ui(): r.get_ui();
00071 }
00072
00073 inline
00074 uint64_t
00075 microseconds::get_uint64() const
00076 {
00077 return tool::uint64_of_mpz(*this);
00078 }
00079
00080 inline
00081 unsigned
00082 microseconds::get_div_by(unsigned d) const
00083 {
00084 assert(sgn(*this) >= 0);
00085
00086 mpz_type r = *this / d;
00087
00088 assert(r.fits_uint_p());
00089 return r.get_ui();
00090 }
00091
00092 inline
00093 struct timeval
00094 microseconds::get_timeval() const
00095 {
00096 struct timeval r;
00097 mpz_type q;
00098
00099 r.tv_usec = mpz_fdiv_q_ui(q.get_mpz_t(), get_mpz_t(), 1000000);
00100 assert(q.fits_sint_p());
00101 r.tv_sec = q.get_si();
00102
00103 return r;
00104 }
00105
00106 }
00107
00108 #endif // TOOL_MICROSECONDS_HXX_