timeval.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 
00035 
00036 #ifndef QOLYESTER_UTL_TIMEVAL_HH
00037 # define QOLYESTER_UTL_TIMEVAL_HH 1
00038 
00039 # include <sys/time.h>
00040 # include <cassert>
00041 # include <ostream>
00042 
00043 namespace olsr {
00044 
00045   namespace utl {
00046 
00053     class TimeVal {
00054       typedef TimeVal   This;
00055     public:
00062       inline
00063       TimeVal(unsigned sec, unsigned usec);
00064 
00068       inline
00069       TimeVal(const This& rhs);
00070 
00074       inline
00075       TimeVal(const ::timeval& rhs);
00076 
00080       inline
00081       TimeVal(const unsigned period);
00082 
00087       inline
00088       TimeVal(const int period);
00089 
00093       inline
00094       TimeVal(const double seconds);
00095 
00096       inline
00097       int       poll_time() const;
00098 
00102       inline
00103       This      operator+(const This& rhs) const;
00104 
00108       inline
00109       This      operator-(const This& rhs) const;
00110 
00114       inline
00115       This&     operator+=(const This& rhs);
00116 
00120       inline
00121       bool      operator==(const This& rhs) const;
00122 
00123       inline
00124       bool      operator!=(const This& rhs) const;
00125 
00129       inline
00130       bool      operator<(const This& rhs) const;
00131 
00135       inline
00136       bool      operator<=(const This& rhs) const;
00137 
00141       bool      operator>(const This& rhs) const { return !operator<=(rhs); }
00142 
00146       bool      operator>=(const This& rhs) const { return !operator<(rhs); }
00147 
00148       inline
00149       float     diff(const This& rhs = now()) const;
00150 
00154       inline
00155       This      distance(const This& rhs) const;
00156 
00165       inline
00166       bool      is_past(const This& now = now()) const;
00167 
00171       inline
00172       This      operator+(unsigned msec) const;
00173 
00177       inline
00178       This&     operator+=(unsigned msec);
00179 
00183       inline
00184       This      operator*(const double& f) const;
00185 
00189       inline
00190       This      operator/(const double& f) const;
00191 
00195       inline
00196       This      abs() const;
00197 
00201       operator ::timeval() const {
00202         return _tv;
00203       }
00204 
00210       inline
00211       static This       jitter(const This& j);
00212 
00216       inline
00217       static void       set_now(const This& now = TimeVal::real_now());
00218 
00222       inline
00223       float             to_float() const;
00224 
00228       static const TimeVal&     now() { return _now; }
00229 
00233       inline
00234       static const TimeVal      real_now();
00235 
00242       inline
00243       static const TimeVal      in(const This& x);
00244 
00251       static const TimeVal      in_jitter(const This& x) {
00252         return in(jitter(x));
00253       }
00254     private:
00255       timeval           _tv;    
00256       static This       _now;   
00257     };
00258 
00259     std::ostream& operator<<(std::ostream&, const TimeVal&);
00260 
00261   } // namespace utl
00262 
00263   typedef utl::TimeVal  timeval_t;
00264 
00265 } // namespace olsr
00266 
00267 # include "timeval.hxx"
00268 
00269 #endif // ! QOLYESTER_UTL_TIMEVAL_HH

Generated on Mon Sep 10 17:02:13 2007 for Qolyester daemon by  doxygen 1.5.1