00001 #ifndef TIME_STAMP_CLASS 00002 #define TIME_STAMP_CLASS 00003 00004 /*****************************************************************************\ 00005 * * 00006 * Name : time_stamp * 00007 * Author : Chris Koeritz * 00008 * * 00009 ******************************************************************************* 00010 * Copyright (c) 1995-$now By Author. This program is free software; you can * 00011 * redistribute it and/or modify it under the terms of the GNU General Public * 00012 * License as published by the Free Software Foundation; either version 2 of * 00013 * the License or (at your option) any later version. This is online at: * 00014 * http://www.fsf.org/copyleft/gpl.html * 00015 * Please send any updates to: fred@gruntose.com * 00016 \*****************************************************************************/ 00017 00018 #include <basis/astring.h> 00019 #include <basis/contracts.h> 00020 #include <basis/definitions.h> 00021 00022 // forward. 00023 class rollover_record; 00024 struct timeval; 00025 00026 namespace timely { 00027 00029 00037 class time_stamp : public virtual basis::orderable 00038 { 00039 public: 00040 typedef double time_representation; 00042 00043 time_stamp(); 00045 00046 time_stamp(time_representation offset); 00048 00051 static double rolling_uptime(); 00053 00054 void reset(); 00056 void reset(time_representation offset); 00058 00059 time_representation value() const { return c_stamp; } 00061 00062 enum stamp_display_style { STAMP_RELATIVE, STAMP_ABSOLUTE }; 00063 00064 basis::astring text_form(stamp_display_style style = STAMP_RELATIVE) const; 00066 00070 static basis::astring notarize(bool add_space = true); 00072 00076 // standard operators: keep in mind that time is represented by an ever 00077 // increasing number. so, if a value A is less than a value B, that means 00078 // that A is older than B, since it occurred at an earlier time. 00079 virtual bool less_than(const basis::orderable &that) const { 00080 const time_stamp *cast = dynamic_cast<const time_stamp *>(&that); 00081 if (!cast) return false; 00082 return c_stamp < cast->c_stamp; 00083 } 00084 00085 virtual bool equal_to(const basis::equalizable &that) const { 00086 const time_stamp *cast = dynamic_cast<const time_stamp *>(&that); 00087 if (!cast) return false; 00088 return c_stamp == cast->c_stamp; 00089 } 00090 00091 // helper functions for using the OS's time support. 00092 00093 static timeval fill_timeval_ms(int milliseconds); 00095 00099 private: 00100 time_representation c_stamp; 00101 00102 void fill_in_time(); 00103 00104 static time_representation get_time_now(); 00106 00107 static rollover_record &rollover_rover(); 00108 }; 00109 00110 } //namespace. 00111 00112 #endif 00113
1.6.3