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 wpl
00032 {
00033 
00034   namespace tool
00035   {
00036 
00037     inline
00038     microseconds::microseconds(const uint64_t i):
00039       mpz_class (tool::mpz_of_uint64(i))
00040     {
00041     }
00042 
00043     inline
00044     microseconds::microseconds(const struct timeval& tv): mpz_class (tv.tv_sec)
00045     {
00046       *this *= 1000000;
00047       *this += tv.tv_usec;
00048     }
00049 
00050     inline
00051     microseconds::microseconds(const mpz_type& z): mpz_class (z)
00052     {
00053     }
00054 
00055     template <class T1, class T2>
00056     microseconds::microseconds(const __gmp_expr<T1, T2>& e): mpz_class (e)
00057     {
00058     }
00059 
00060     inline
00061     uint32_t
00062     microseconds::get_prism_mactime() const
00063     {
00064       return sgn(*this) < 0? -get_ui(): get_ui();
00065     }
00066 
00067     inline
00068     uint32_t
00069     microseconds::get_prism_hosttime() const
00070     {
00071       mpz_type  r = *this / 10;
00072 
00073       return sgn(r) < 0? -r.get_ui(): r.get_ui();
00074     }
00075 
00076     inline
00077     uint64_t
00078     microseconds::get_uint64() const
00079     {
00080       return tool::uint64_of_mpz(*this);
00081     }
00082 
00083     inline
00084     unsigned
00085     microseconds::get_div_by(unsigned d) const
00086     {
00087       assert(sgn(*this) >= 0);
00088 
00089       mpz_type  r = *this / d;
00090 
00091       assert(r.fits_uint_p());
00092       return r.get_ui();
00093     }
00094 
00095     inline
00096     struct timeval
00097     microseconds::get_timeval() const
00098     {
00099       struct timeval    r;
00100       mpz_type          q;
00101 
00102       r.tv_usec = mpz_fdiv_q_ui(q.get_mpz_t(), get_mpz_t(), 1000000);
00103       assert(q.fits_sint_p());
00104       r.tv_sec = q.get_si();
00105 
00106       return r;
00107     }
00108 
00109   } 
00110 
00111 } 
00112 
00113 #endif // TOOL_MICROSECONDS_HXX_