Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

more/sys/time.h

Go to the documentation of this file.
00001 //  more/sys/time.h
00002 //  Copyright (C) 1998--2001  Petter Urkedal (petter.urkedal@matfys.lth.se)
00003 //
00004 //  This file is free software; you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation; either version 2 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This file is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program; if not, write to the Free Software
00016 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 //
00018 //  As a special exception, you may use this file as part of a free
00019 //  software library without restriction.  Specifically, if other files
00020 //  instantiate templates or use macros or inline functions from this
00021 //  file, or you compile this file and link it with other files to
00022 //  produce an executable, this file does not by itself cause the
00023 //  resulting executable to be covered by the GNU General Public
00024 //  License.  This exception does not however invalidate any other
00025 //  reasons why the executable file might be covered by the GNU General
00026 //  Public License.
00027 //
00028 //  $Id: time.h,v 1.1 2002/05/30 18:01:40 petter_urkedal Exp $
00029 
00030 
00031 
00032 #ifndef MORE_SYS_TIME_H
00033 #define MORE_SYS_TIME_H
00034 
00035 #include <ctime>
00036 #include <stdexcept>
00037 #include <iosfwd>
00038 
00039 
00040 namespace more {
00041 namespace sys {
00042 
00043   /** A floating point type used to represent time.  Some philosopies
00044       regards time as a discrete sequence of moments.  A more common
00045       view is that time is continuous.
00046 
00047       Precision.  Assume this is a 64 bits double with a 53 bits
00048       mantissa.  If we use 33 bits for the year, 2↑33 s ≃ 272 y,
00049       i.e. in year 2242 there is still 20 bits left for subsecond
00050       precision down to 2^(-20) s = 0.95 μs.  For relative time within
00051       12 days ≃ 2↑20 s the precision is about 0.1 ns, but at the
00052       moment the OS calls limit the precision to 1 μs.  */
00053   typedef double time_t;
00054 
00055   /** The current real-world time.  More precisely, the time
00056       difference in seconds between present and Epoch (1970-01-01
00057       00:00:00 UTC).  If the \c gettimeofday is available on your
00058       system, the returned time will have 1 μs precision, otherwise it
00059       will have 1 s precision. */
00060   time_t current_time();
00061 
00062   /** Return the current real-world time relative to \a t_ref.  By
00063       supplying a reference point close to the current time, time
00064       differences may be calculated with better precision then when
00065       using Epoch times.  (At the moment the precision is most likely
00066       limited by the OS call, though.)  */
00067   time_t current_time(time_t const& t_ref);
00068 
00069   /** Return the processor time spent in this process.  If getrusage
00070       is not available \c clock(), which may overflow, is used. */
00071   time_t process_time();
00072 //   inline time_t process_time() { return std::clock()/(time_t)CLOCKS_PER_SEC; }
00073 
00074   // XXX Maybe this should be in the IO module
00075   void print_time_nicely(std::ostream& out, double t);
00076 
00077   /** Sleep for the given time.  If nanosleep is available on the
00078       system, the precision may be down to ns, else if setitimer is
00079       available, the precision may be down to μs, otherwise the
00080       precision is down to s, but in any case the precision is limited
00081       by the scheduler. */
00082   void sleep(double);
00083 
00084 } // sys
00085   using sys::time_t;
00086   using sys::current_time;
00087   using sys::process_time;
00088   using sys::print_time_nicely;
00089 } // more
00090 
00091 #endif
00092 
00093 // Local Variables:
00094 // coding: utf-8
00095 // End:

Generated on Sat Sep 7 19:11:22 2002 for more with Doxygen 1.2.13.1. Doxygen 1.2.13.1 is written and copyright 1997-2002 by Dimitri van Heesch.