From d08b195de44d2e85467de1764884c14973f92115 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 21 Jun 2013 00:08:01 -0700 Subject: gras: first cut at time tag class --- include/gras/CMakeLists.txt | 1 + include/gras/time_tag.hpp | 58 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 include/gras/time_tag.hpp (limited to 'include/gras') diff --git a/include/gras/CMakeLists.txt b/include/gras/CMakeLists.txt index d0e3cfa..becd6cb 100644 --- a/include/gras/CMakeLists.txt +++ b/include/gras/CMakeLists.txt @@ -16,6 +16,7 @@ install(FILES sbuffer.hpp sbuffer.i tags.hpp + time_tag.hpp tags.i tag_iter.hpp tag_iter.i diff --git a/include/gras/time_tag.hpp b/include/gras/time_tag.hpp new file mode 100644 index 0000000..d350fa2 --- /dev/null +++ b/include/gras/time_tag.hpp @@ -0,0 +1,58 @@ +// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. + +#ifndef INCLUDED_GRAS_TIME_TAG_HPP +#define INCLUDED_GRAS_TIME_TAG_HPP + +#include +#include +#include +#include + +namespace gras +{ + +struct GRAS_API TimeTag : + boost::less_than_comparable, + boost::additive +{ + //! 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*/ -- cgit