diff options
author | Josh Blum | 2013-06-21 00:33:31 -0700 |
---|---|---|
committer | Josh Blum | 2013-06-21 00:33:31 -0700 |
commit | d47f192f9edfc2332fa73e6ed6c4c1cdedefb96c (patch) | |
tree | 9a7e3be6fc923b5e274b6cb634e751aa39e29ccd | |
parent | d08b195de44d2e85467de1764884c14973f92115 (diff) | |
download | sandhi-d47f192f9edfc2332fa73e6ed6c4c1cdedefb96c.tar.gz sandhi-d47f192f9edfc2332fa73e6ed6c4c1cdedefb96c.tar.bz2 sandhi-d47f192f9edfc2332fa73e6ed6c4c1cdedefb96c.zip |
gras: adding pythonic interface to time tag
-rw-r--r-- | include/gras/CMakeLists.txt | 3 | ||||
-rw-r--r-- | include/gras/time_tag.hpp | 7 | ||||
-rw-r--r-- | include/gras/time_tag.i | 39 | ||||
-rw-r--r-- | lib/serialize_types.cpp | 15 | ||||
-rw-r--r-- | python/gras/CMakeLists.txt | 2 | ||||
-rw-r--r-- | python/gras/GRAS_TimeTag.i | 14 | ||||
-rw-r--r-- | python/gras/__init__.py | 1 |
7 files changed, 80 insertions, 1 deletions
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<TimeTag>, boost::additive<TimeTag> 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 <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; + } +} + +#endif /*INCLUDED_GRAS_TIME_TAG_I*/ diff --git a/lib/serialize_types.cpp b/lib/serialize_types.cpp index afa9481..fde7277 100644 --- a/lib/serialize_types.cpp +++ b/lib/serialize_types.cpp @@ -2,6 +2,7 @@ #include <gras/sbuffer.hpp> #include <gras/tags.hpp> +#include <gras/time_tag.hpp> #include <PMC/Serialize.hpp> #include <boost/serialization/split_free.hpp> #include <boost/serialization/string.hpp> @@ -82,3 +83,17 @@ void serialize(Archive &ar, gras::StreamTag &t, const unsigned int) }} PMC_SERIALIZE_EXPORT(gras::StreamTag, "PMC<gras::StreamTag>") + +/*********************************************************************** + * support for time tag type + **********************************************************************/ +namespace boost { namespace serialization { +template <class Archive> +void serialize(Archive &ar, gras::TimeTag &t, const unsigned int) +{ + ar & t._fsecs; + ar & t._ticks; +} +}} + +PMC_SERIALIZE_EXPORT(gras::TimeTag, "PMC<gras::TimeTag>") diff --git a/python/gras/CMakeLists.txt b/python/gras/CMakeLists.txt index 8171e7f..a7fc8f3 100644 --- a/python/gras/CMakeLists.txt +++ b/python/gras/CMakeLists.txt @@ -19,6 +19,7 @@ set(GR_SWIG_LIBRARIES gras) file(GLOB GR_SWIG_SOURCE_DEPS "${GRAS_SOURCE_DIR}/include/gras/*.i") GR_SWIG_MAKE(GRAS_Tags GRAS_Tags.i) +GR_SWIG_MAKE(GRAS_TimeTag GRAS_TimeTag.i) GR_SWIG_MAKE(GRAS_Block GRAS_Block.i) GR_SWIG_MAKE(GRAS_HierBlock GRAS_HierBlock.i) GR_SWIG_MAKE(GRAS_ThreadPool GRAS_ThreadPool.i) @@ -26,6 +27,7 @@ GR_SWIG_MAKE(GRAS_SBuffer GRAS_SBuffer.i) GR_SWIG_INSTALL( TARGETS GRAS_Tags + GRAS_TimeTag GRAS_Block GRAS_HierBlock GRAS_ThreadPool diff --git a/python/gras/GRAS_TimeTag.i b/python/gras/GRAS_TimeTag.i new file mode 100644 index 0000000..3b77dfb --- /dev/null +++ b/python/gras/GRAS_TimeTag.i @@ -0,0 +1,14 @@ +// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. + + +%include <gras/time_tag.i> + +%include <PMC/Registry.i> + +DECL_PMC_SWIG_TYPE(gras::TimeTag, swig_time_tag) + +%pythoncode %{ +from GRAS_TimeTag import TimeTag +%} + +REG_PMC_SWIG_TYPE(swig_time_tag, TimeTag) diff --git a/python/gras/__init__.py b/python/gras/__init__.py index 33d2b00..cf2c7f5 100644 --- a/python/gras/__init__.py +++ b/python/gras/__init__.py @@ -3,6 +3,7 @@ from PMC import * from GRAS_SBuffer import SBufferConfig, SBuffer from GRAS_Tags import Tag, StreamTag, PacketMsg +from GRAS_TimeTag import TimeTag from GRAS_Block import Block from GRAS_HierBlock import HierBlock, TopBlock from GRAS_ThreadPool import ThreadPoolConfig, ThreadPool |