00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00026
00027 #ifndef QOLYESTER_UTL_VTIME_HXX
00028 # define QOLYESTER_UTL_VTIME_HXX 1
00029
00030 # include "vtime.hh"
00031
00032 namespace olsr {
00033
00034 namespace utl {
00035
00036 Vtime::Vtime(const Vtime& other) :
00037 _value(other._value)
00038 {}
00039
00040 Vtime::Vtime(const byte_t other) :
00041 _value(*(raw*)&other)
00042 {}
00043
00044
00045
00046 Vtime::Vtime(const float fsecs) :
00047 _value(0, 0) {
00048 assert(fsecs != 0.f);
00049
00050 float fsecsnormed(fsecs / C_CONSTANT);
00051
00052 unsigned b = 0;
00053 while (fsecsnormed > (float)(1 << b))
00054 ++b;
00055 --b;
00056
00057 unsigned a = (unsigned)
00058 roundf(16 * (fsecs / (C_CONSTANT * (float)(1 << b)) - 1));
00059 b += a / 16;
00060 a %= 16;
00061
00062 _value.mantissa = a;
00063 _value.exponent = b;
00064 }
00065
00066 Vtime::Vtime(const timeval_t& other) :
00067 _value(Vtime(((::timeval)other).tv_sec +
00068 (float) ((::timeval)other).tv_usec / 1e6f)._value)
00069 {}
00070
00071 std::ostream&
00072 Vtime::output(std::ostream& o) const {
00073 return o << "{ m = " << (int) _value.mantissa
00074 << ", e = " << (int) _value.exponent << " }";
00075 }
00076
00077 inline
00078 std::ostream& operator<<(std::ostream& o, const Vtime& v)
00079 {
00080 return v.output(o);
00081 }
00082
00083 }
00084
00085 }
00086
00087 #endif // ! QOLYESTER_UTL_VTIME_HXX