omni_time.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2007,2008 Free Software Foundation, Inc.
00004  * 
00005  * This file is part of GNU Radio
00006  * 
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  * 
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License along
00018  * with this program; if not, write to the Free Software Foundation, Inc.,
00019  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00020  */
00021 #ifndef INCLUDED_OMNI_TIME_H
00022 #define INCLUDED_OMNI_TIME_H
00023 
00024 struct omni_time {
00025   long int d_secs;      // seconds.
00026   long int d_nsecs;     // nanoseconds.  Always in [0, 1e9-1]
00027 
00028   omni_time() : d_secs(0), d_nsecs(0) {}
00029   omni_time(long secs, long nanosecs=0) : d_secs(secs), d_nsecs(nanosecs) {}
00030 
00031   // N.B., this only makes sense for differences between times.
00032   // Double doesn't have enough bits to precisely represent an absolute time.
00033   omni_time(double secs);
00034 
00035   // N.B. This only makes sense for differences between times.
00036   // Double doesn't have enough bits to precisely represent an absolute time.
00037   double double_time() const { return (double)d_secs + d_nsecs * 1e-9; }
00038 
00045   static omni_time time(const omni_time &relative_offset = omni_time());
00046 };
00047 
00048 
00049 inline static bool
00050 operator<(const omni_time &x, const omni_time &y)
00051 {
00052   return ((x.d_secs < y.d_secs)
00053           || (x.d_secs == y.d_secs && x.d_nsecs < y.d_nsecs));
00054 }
00055 
00056 inline static bool
00057 operator>(const omni_time &x, const omni_time &y)
00058 {
00059   return ((x.d_secs > y.d_secs)
00060           || (x.d_secs == y.d_secs && x.d_nsecs > y.d_nsecs));
00061 }
00062 
00063 inline static bool
00064 operator>=(const omni_time &x, const omni_time &y)
00065 {
00066   return ((x.d_secs > y.d_secs)
00067           || (x.d_secs == y.d_secs && x.d_nsecs >= y.d_nsecs));
00068 }
00069 
00070 inline static bool
00071 operator<=(const omni_time &x, const omni_time &y)
00072 {
00073   return ((x.d_secs < y.d_secs)
00074           || (x.d_secs == y.d_secs && x.d_nsecs <= y.d_nsecs));
00075 }
00076 
00077 inline static bool
00078 operator==(const omni_time &x, const omni_time &y)
00079 {
00080   return (x.d_secs == y.d_secs && x.d_nsecs == y.d_nsecs);
00081 }
00082 
00083 
00084 omni_time operator+(const omni_time &x, const omni_time &y);
00085 omni_time operator+(const omni_time &x, double y);
00086 omni_time operator-(const omni_time &x, const omni_time &y);
00087 omni_time operator-(const omni_time &x, double y);
00088 
00089 #endif /* INCLUDED_OMNI_TIME_H */

Generated on Thu Mar 5 09:01:14 2009 for GNU Radio 3.1.3 by  doxygen 1.5.8