summaryrefslogtreecommitdiff
path: root/utils/Time.cc
diff options
context:
space:
mode:
Diffstat (limited to 'utils/Time.cc')
-rw-r--r--utils/Time.cc90
1 files changed, 90 insertions, 0 deletions
diff --git a/utils/Time.cc b/utils/Time.cc
new file mode 100644
index 0000000..6780178
--- /dev/null
+++ b/utils/Time.cc
@@ -0,0 +1,90 @@
+/*
+ * CENA C++ Utilities
+ *
+ * by Stephane Chatty
+ *
+ * Copyright 1992
+ * Centre d'Etudes de la Navigation Aerienne (CENA)
+ *
+ * time management
+ *
+ * $Id$
+ * $CurLog$
+ */
+
+#include "Time.h"
+#include <sys/time.h>
+extern "C" int gettimeofday (struct timeval *, struct timezone *);
+
+/*?class CcuTimeStamp
+The class \var{CcuTimeStamp} provides variables that can be manipulated as
+integers, but whose initial value is set according to the current time.
+The following example should be self-explanatory:
+\begin{ccode}
+ CcuTimeStamp before;
+ long_task ();
+ CcuTimeStamp after;
+ Millisecond delay = after - before;
+\end{ccode}
+The values of \typ{CcuTimeStamp}s are expressed in milliseconds.
+The type \typ{Millisecond} is currently defined as \typ{long int}.
+?*/
+
+/*?
+Create a time stamp. Its value is set according to the current time.
+?*/
+CcuTimeStamp :: CcuTimeStamp ()
+{
+ struct timeval tv;
+ gettimeofday (&tv, 0);
+ Value = 1000 * tv.tv_sec + tv.tv_usec / 1000;
+}
+
+#ifdef DOC
+/*?
+Get the value of a time stamp.
+?*/
+CcuTimeStamp :: operator Millisecond () const
+{
+}
+#endif /* DOC */
+
+/*?class CcuTime
+The class \typ{CcuTime} provides a simple way of manipulating real-time. Objects
+of this class are used like integer variables whose value would change with time.
+That behavior is obtained through the redefinition of the operator yielding the
+integer value.
+
+Time values are expressed with the type \typ{Millisecond}, which is currently implemented
+as \typ{long int}. You may initialize a \typ{CcuTime} with a negative value.
+?*/
+
+/*?
+Initialize a time variable with initial value \var{t}.
+?*/
+CcuTime :: CcuTime (Millisecond t)
+{
+ CcuTimeStamp now;
+ Offset = now - t;
+}
+
+/*?
+Get the current value of a time variable.
+?*/
+CcuTime :: operator Millisecond () const
+{
+ CcuTimeStamp now;
+ return now - Offset;
+}
+
+/*?
+Reinitialize a time variable to the value \var{t}.
+?*/
+CcuTime&
+CcuTime :: operator = (Millisecond t)
+{
+ CcuTimeStamp now;
+ Offset = now - t;
+ return *this;
+}
+