From d47f192f9edfc2332fa73e6ed6c4c1cdedefb96c Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 21 Jun 2013 00:33:31 -0700 Subject: gras: adding pythonic interface to time tag --- include/gras/CMakeLists.txt | 3 ++- include/gras/time_tag.hpp | 7 +++++++ include/gras/time_tag.i | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 include/gras/time_tag.i (limited to 'include') diff --git a/include/gras/CMakeLists.txt b/include/gras/CMakeLists.txt index becd6cb..176d5e5 100644 --- a/include/gras/CMakeLists.txt +++ b/include/gras/CMakeLists.txt @@ -16,8 +16,9 @@ install(FILES sbuffer.hpp sbuffer.i tags.hpp - time_tag.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 index d350fa2..9459f9f 100644 --- a/include/gras/time_tag.hpp +++ b/include/gras/time_tag.hpp @@ -11,6 +11,13 @@ 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, boost::additive diff --git a/include/gras/time_tag.i b/include/gras/time_tag.i new file mode 100644 index 0000000..fb3d721 --- /dev/null +++ b/include/gras/time_tag.i @@ -0,0 +1,39 @@ +// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. + +#ifndef INCLUDED_GRAS_TIME_TAG_I +#define INCLUDED_GRAS_TIME_TAG_I + +%{ +#include +%} + +//////////////////////////////////////////////////////////////////////// +// remove base class warning -- boost::less_than_comparable +// remove base class warning -- boost::additive +//////////////////////////////////////////////////////////////////////// +#pragma SWIG nowarn=401 + +%include +%include +%include +%import + +//////////////////////////////////////////////////////////////////////// +// 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; + } +} + +#endif /*INCLUDED_GRAS_TIME_TAG_I*/ -- cgit