Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

vtime.hxx

Go to the documentation of this file.
00001 // Copyright (C) 2003, 2004, 2005 Laboratoire de Recherche en Informatique
00002 
00003 // This file is part of Qolyester.
00004 
00005 // Qolyester is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 
00010 // Qolyester is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
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     // Construction of a Vtime from a second count.  This follows
00045     // exactly the procedure described in the draft in section 18.3.
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   } // namespace utl
00084 
00085 } // namespace olsr
00086 
00087 #endif // ! QOLYESTER_UTL_VTIME_HXX

Generated on Thu Dec 8 01:24:38 2005 for Qolyester daemon by  doxygen 1.4.3-20050530