conexus logo

timeval.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2009 by Rick L. Vinyard, Jr.                            *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This file is part of the conexus library.                             *
00006  *                                                                         *
00007  *   The conexus library is free software; you can redistribute it and/or  *
00008  *   modify it under the terms of the GNU General Public License           *
00009  *   version 3 as published by the Free Software Foundation.               *
00010  *                                                                         *
00011  *   The conexus library is distributed in the hope that it will be        *
00012  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty   *
00013  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
00014  *   General Public License for more details.                              *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU General Public License     *
00017  *   along with this software. If not see <http://www.gnu.org/licenses/>.  *
00018  ***************************************************************************/
00019 #ifndef CONEXUSTIME_H
00020 #define CONEXUSTIME_H
00021 
00022 #include <sys/time.h>
00023 #include <cstdint>
00024 #include <sigc++/sigc++.h>
00025 
00026 namespace Conexus
00027 {
00028 
00032   class TimeVal
00033   {
00034     public:
00035       TimeVal ( int64_t seconds=0, int64_t microseconds=0 );
00036       TimeVal ( const struct timeval& tv );
00037       TimeVal ( const TimeVal& other );
00038 
00039       ~TimeVal();
00040 
00041       int64_t seconds() const;
00042       int64_t microseconds() const;
00043 
00044       void set_seconds ( int64_t seconds );
00045       void set_microseconds ( int64_t microseconds );
00046       void set ( int64_t seconds, int64_t microseconds );
00047 
00048       TimeVal& operator= ( const struct timeval& tv );
00049 
00050       void clear();
00051 
00052       bool set_to_current_time();
00053 
00054       void add ( const TimeVal& other );
00055       void subtract ( const TimeVal& other );
00056       void add_seconds ( int64_t seconds );
00057       void subtract_seconds ( int64_t seconds );
00058       void add_milliseconds ( int64_t milliseconds );
00059       void subtract_milliseconds ( int64_t milliseconds );
00060       void add_microseconds ( int64_t microseconds );
00061       void subtract_microsecond ( int64_t microseconds );
00062 
00063       TimeVal  operator+ ( const TimeVal& other ) const;
00064       TimeVal  operator- ( const TimeVal& other ) const;
00065       TimeVal  operator+ ( int64_t seconds ) const;
00066       TimeVal  operator- ( int64_t seconds ) const;
00067       TimeVal& operator+= ( const TimeVal& other );
00068       TimeVal& operator-= ( const TimeVal& other );
00069       TimeVal& operator+= ( int64_t seconds );
00070       TimeVal& operator-= ( int64_t seconds );
00071 
00072       float as_float() const;
00073       double as_double() const;
00074       long double as_long_double() const;
00075 
00076       operator struct timeval() const;
00077       operator float() const;
00078       operator double() const;
00079       operator long double() const;
00080 
00081       bool negative() const;
00082 
00083     protected:
00084       int64_t m_seconds;
00085       int64_t m_microseconds;
00086 
00087       void cleanup();
00088 
00089   };
00090 
00091 }
00092 
00093 #endif

Generated on Wed Jul 8 15:50:08 2009 for conexus by doxygen 1.5.8