feisty meow concerns codebase  2.140
time_stamp.h
Go to the documentation of this file.
1 #ifndef TIME_STAMP_CLASS
2 #define TIME_STAMP_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : time_stamp *
7 * Author : Chris Koeritz *
8 * *
9 *******************************************************************************
10 * Copyright (c) 1995-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
17 
18 #include <basis/astring.h>
19 #include <basis/contracts.h>
20 #include <basis/definitions.h>
21 
22 // forward.
23 class rollover_record;
24 struct timeval;
25 
26 namespace timely {
27 
29 
37 class time_stamp : public virtual basis::orderable
38 {
39 public:
40  DEFINE_CLASS_NAME("time_stamp");
41 
42  typedef double time_representation;
44 
45  time_stamp();
47 
50 
53  static double rolling_uptime();
55 
56  void reset();
58  void reset(time_representation offset);
60 
61  time_representation value() const { return c_stamp; }
63 
65 
68 
72  static basis::astring notarize(bool add_space = true);
74 
78  // standard operators: keep in mind that time is represented by an ever
79  // increasing number. so, if a value A is less than a value B, that means
80  // that A is older than B, since it occurred at an earlier time.
81  virtual bool less_than(const basis::orderable &that) const {
82  const time_stamp *cast = dynamic_cast<const time_stamp *>(&that);
83  if (!cast) return false;
84  return c_stamp < cast->c_stamp;
85  }
86 
87  virtual bool equal_to(const basis::equalizable &that) const {
88  const time_stamp *cast = dynamic_cast<const time_stamp *>(&that);
89  if (!cast) return false;
90  return c_stamp == cast->c_stamp;
91  }
92 
93  // helper functions for using the OS's time support.
94 
95  static void fill_timeval_ms(timeval &time_point, int milliseconds);
97 
101 private:
102  time_representation c_stamp;
103 
104  void fill_in_time();
105 
106  static time_representation get_time_now();
108 
109  static rollover_record &rollover_rover();
110 };
111 
112 } //namespace.
113 
114 #endif
115 
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
Base class for object that can tell itself apart from other instances.
Definition: contracts.h:44
A base for objects that can be alphabetically (lexicographically) ordered.
Definition: contracts.h:57
Represents a point in time relative to the operating system startup time.
Definition: time_stamp.h:38
virtual bool equal_to(const basis::equalizable &that) const
Definition: time_stamp.h:87
static basis::astring notarize(bool add_space=true)
a useful method for getting a textual version of the time "right now".
Definition: time_stamp.cpp:45
basis::astring text_form(stamp_display_style style=STAMP_RELATIVE) const
returns a simple textual representation of the time_stamp.
Definition: time_stamp.cpp:61
void reset()
sets the stamp time back to now.
Definition: time_stamp.cpp:59
static double rolling_uptime()
give the OS uptime in a more durable form that handles rollovers.
Definition: time_stamp.cpp:121
time_stamp()
creates a time_stamp containing the current time.
Definition: time_stamp.cpp:54
double time_representation
the representation of time for this universe, measured in milliseconds.
Definition: time_stamp.h:42
DEFINE_CLASS_NAME("time_stamp")
static void fill_timeval_ms(timeval &time_point, int milliseconds)
returns a timeval system object that represents the "milliseconds".
Definition: time_stamp.cpp:141
time_representation value() const
returns the time_stamp in terms of the lower level type.
Definition: time_stamp.h:61
virtual bool less_than(const basis::orderable &that) const
Definition: time_stamp.h:81
Constants and objects used throughout HOOPLE.
#include <time.h>
Definition: earth_time.cpp:37