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

vtime.hh

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 
00030 #ifndef QOLYESTER_UTL_VTIME_HH
00031 # define QOLYESTER_UTL_VTIME_HH 1
00032 
00033 # include <sys/types.h>
00034 # include <cmath>
00035 # include "timeval.hh"
00036 # include "cst/constants.hh"
00037 
00038 namespace olsr {
00039 
00040   namespace utl {
00041 
00046     class Vtime {
00047       typedef u_int8_t  byte_t;
00048       typedef unsigned  secs_t;
00049     public:
00053       Vtime(const Vtime& other);
00054 
00060       explicit Vtime(const byte_t other);
00061 
00067       Vtime(const float fsecs);
00068 
00074       Vtime(const timeval_t& other);
00075 
00079       operator byte_t() { return *(byte_t*)&_value; }
00080 
00084       operator float() {
00085         return C_CONSTANT * (1 + (float) _value.mantissa / 16) *
00086           (float)(1 << _value.exponent);
00087       }
00088 
00092       operator timeval_t() {
00093         float secs = floorf(*this);
00094         return timeval_t((unsigned) secs,
00095                          (unsigned)(((float) *this - secs) * 1e6f));
00096       }
00097 
00101       std::ostream&     output(std::ostream& o) const;
00102 
00103     private:
00108       struct raw {
00109         raw(const int m, const int e) : exponent(e), mantissa(m) {}
00110         byte_t exponent:4;
00111         byte_t mantissa:4;
00112       };
00113       raw               _value; 
00114     };
00115 
00116     inline
00117     std::ostream& operator<<(std::ostream&, const Vtime&);
00118 
00119   } // namespace utl
00120 
00121 } // namespace olsr
00122 
00123 # ifndef QOLYESTER_DONTINCLUDE_HXX
00124 #  include "vtime.hxx"
00125 # endif
00126 
00127 #endif // ! QOLYESTER_UTL_VTIME_HH

Generated on Thu Jul 28 21:21:49 2005 for Qolyester daemon by  doxygen 1.4.1