summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJosh Blum2013-06-21 19:53:34 -0700
committerJosh Blum2013-06-21 19:53:34 -0700
commit78139a05aa2f1516688f29359538fbc09b8c3e2e (patch)
tree5e18889f2fc3cbcb22d722ac70176d5809f0ea27 /include
parentb6e5debf3d0b9fddd5f274bf16bd3d5e09219639 (diff)
parent90579c89748704dc1d7e9d80120c42988481197c (diff)
downloadsandhi-78139a05aa2f1516688f29359538fbc09b8c3e2e.tar.gz
sandhi-78139a05aa2f1516688f29359538fbc09b8c3e2e.tar.bz2
sandhi-78139a05aa2f1516688f29359538fbc09b8c3e2e.zip
Merge branch 'time_tag_work'
Diffstat (limited to 'include')
-rw-r--r--include/gras/CMakeLists.txt2
-rw-r--r--include/gras/time_tag.hpp65
-rw-r--r--include/gras/time_tag.i49
3 files changed, 116 insertions, 0 deletions
diff --git a/include/gras/CMakeLists.txt b/include/gras/CMakeLists.txt
index d0e3cfa..176d5e5 100644
--- a/include/gras/CMakeLists.txt
+++ b/include/gras/CMakeLists.txt
@@ -17,6 +17,8 @@ install(FILES
sbuffer.i
tags.hpp
tags.i
+ time_tag.hpp
+ time_tag.i
tag_iter.hpp
tag_iter.i
thread_pool.hpp
diff --git a/include/gras/time_tag.hpp b/include/gras/time_tag.hpp
new file mode 100644
index 0000000..9459f9f
--- /dev/null
+++ b/include/gras/time_tag.hpp
@@ -0,0 +1,65 @@
+// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information.
+
+#ifndef INCLUDED_GRAS_TIME_TAG_HPP
+#define INCLUDED_GRAS_TIME_TAG_HPP
+
+#include <gras/gras.hpp>
+#include <gras/chrono.hpp>
+#include <PMC/PMC.hpp>
+#include <boost/operators.hpp>
+
+namespace gras
+{
+
+/*!
+ * TimeTag represents an absolute time or a time delta.
+ * A TimeTag can be converted to and from a tick count.
+ * Conversion support is provided for the pseudo-standard
+ * PMCTuple format often used inside a StreamTag value.
+ * And TimeTag supports overloaded arithmetic operations.
+ */
+struct GRAS_API TimeTag :
+ boost::less_than_comparable<TimeTag>,
+ boost::additive<TimeTag>
+{
+ //! Default contructor - hold time 0
+ TimeTag(void);
+
+ //! Create a time tag from ticks w/ default ticks per second
+ static TimeTag from_ticks(const time_ticks_t ticks);
+
+ //! Create a time tag from ticks w/ specified ticks per second
+ static TimeTag from_ticks(const time_ticks_t ticks, const double rate);
+
+ //! Create a time tag from a PMC containing a PMCTuple<2>(uint64, double)
+ static TimeTag from_pmc(const PMCC &p);
+
+ //! Convert this time tag to ticks w/ default ticks per second
+ time_ticks_t to_ticks(void);
+
+ //! Convert this time tag to ticks w/ specified ticks per second
+ time_ticks_t to_ticks(const double rate);
+
+ //! Convert this time tag to a PMC containing a PMCTuple<2>(uint64, double)
+ PMCC to_pmc(void);
+
+ //! Addition for additive interface
+ TimeTag &operator+=(const TimeTag &);
+
+ //! Subtraction for additive interface
+ TimeTag &operator-=(const TimeTag &);
+
+ //! full seconds
+ time_ticks_t _fsecs;
+
+ //! fractional ticks
+ time_ticks_t _ticks;
+};
+
+GRAS_API bool operator<(const TimeTag &lhs, const TimeTag &rhs);
+
+GRAS_API bool operator==(const TimeTag &lhs, const TimeTag &rhs);
+
+} //namespace gras
+
+#endif /*INCLUDED_GRAS_TIME_TAG_HPP*/
diff --git a/include/gras/time_tag.i b/include/gras/time_tag.i
new file mode 100644
index 0000000..42deed7
--- /dev/null
+++ b/include/gras/time_tag.i
@@ -0,0 +1,49 @@
+// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information.
+
+#ifndef INCLUDED_GRAS_TIME_TAG_I
+#define INCLUDED_GRAS_TIME_TAG_I
+
+%{
+#include <gras/time_tag.hpp>
+%}
+
+////////////////////////////////////////////////////////////////////////
+// remove base class warning -- boost::less_than_comparable<TimeTag>
+// remove base class warning -- boost::additive<TimeTag>
+////////////////////////////////////////////////////////////////////////
+#pragma SWIG nowarn=401
+
+%include <gras/gras.hpp>
+%include <gras/chrono.hpp>
+%include <gras/time_tag.hpp>
+%import <PMC/PMC.i>
+
+////////////////////////////////////////////////////////////////////////
+// Make it pythonic
+////////////////////////////////////////////////////////////////////////
+%extend gras::TimeTag
+{
+ bool __nonzero__(void)
+ {
+ return ($self)->to_ticks() != 0;
+ }
+
+ int __cmp__(const TimeTag &other)
+ {
+ if ((*($self)) < other) return -1;
+ if ((*($self)) > other) return +1;
+ return 0;
+ }
+
+ TimeTag __add__(const TimeTag &other)
+ {
+ return (*($self)) + other;
+ }
+
+ TimeTag __sub__(const TimeTag &other)
+ {
+ return (*($self)) - other;
+ }
+}
+
+#endif /*INCLUDED_GRAS_TIME_TAG_I*/