diff options
author | Josh Blum | 2013-06-05 10:44:00 -0700 |
---|---|---|
committer | Josh Blum | 2013-06-05 10:44:00 -0700 |
commit | 7889847eed1e8bc003b88b0d6ad4f7904873d2ac (patch) | |
tree | 4497b862f1e28faf585214e13ed124cf856323a5 | |
parent | 4201e46df896d88ef39a3ccb3b57f7517932d5a2 (diff) | |
download | sandhi-7889847eed1e8bc003b88b0d6ad4f7904873d2ac.tar.gz sandhi-7889847eed1e8bc003b88b0d6ad4f7904873d2ac.tar.bz2 sandhi-7889847eed1e8bc003b88b0d6ad4f7904873d2ac.zip |
gras: created duck typed API for posting msgs
Uses templates and template overloads in c++
User python duck typing in the python case.
Cleans up post for #84
m--------- | PMC | 0 | ||||
m--------- | grextras | 0 | ||||
-rw-r--r-- | include/gras/block.hpp | 8 | ||||
-rw-r--r-- | include/gras/block.i | 9 | ||||
-rw-r--r-- | include/gras/detail/block.hpp | 36 | ||||
-rw-r--r-- | lib/block_message.cpp | 4 |
6 files changed, 53 insertions, 4 deletions
diff --git a/PMC b/PMC -Subproject 69492abfcc79b37db611c04533dd699809c4494 +Subproject c21cb504317db1bd3ac2bb75092284b7edd649a diff --git a/grextras b/grextras -Subproject bd4eca76a3471a3771778b9abd3ef2da5efd44f +Subproject 1ab1184268fc64d7711e285b31e5a48507a3493 diff --git a/include/gras/block.hpp b/include/gras/block.hpp index 59c30c0..378358e 100644 --- a/include/gras/block.hpp +++ b/include/gras/block.hpp @@ -222,7 +222,8 @@ struct GRAS_API Block : Element * \param which_output the index of the output port * \param msg the message object to pass downstream */ - void post_output_msg(const size_t which_output, const PMCC &msg); + template <typename ValueType> + void post_output_msg(const size_t which_output, const ValueType &value); /*! * Pop a message from the specified port. @@ -248,7 +249,8 @@ struct GRAS_API Block : Element * \param which_input an input port on this block * \param msg the message to post to the input port */ - void post_input_msg(const size_t which_input, const PMCC &tag); + template <typename ValueType> + void post_input_msg(const size_t which_input, const ValueType &value); /******************************************************************* * The property interface: @@ -543,6 +545,8 @@ struct GRAS_API Block : Element void _register_setter(const std::string &, void *); virtual void _set_property(const std::string &, const PMCC &); virtual PMCC _get_property(const std::string &); + void _post_output_msg(const size_t which_output, const PMCC &msg); + void _post_input_msg(const size_t which_input, const PMCC &msg); }; } //namespace gras diff --git a/include/gras/block.i b/include/gras/block.i index 8e1a635..cce0d15 100644 --- a/include/gras/block.i +++ b/include/gras/block.i @@ -26,6 +26,15 @@ def get(self, key): return self._get_property(key)() + + def post_output_msg(self, which_output, value): + if not isinstance(value, PMCC): value = PMC_M(value) + self._post_output_msg(which_output, value) + + def post_input_msg(self, which_input, value): + if not isinstance(value, PMCC): value = PMC_M(value) + self._post_input_msg(which_input, value) + %} } diff --git a/include/gras/detail/block.hpp b/include/gras/detail/block.hpp index d975b0f..3c85905 100644 --- a/include/gras/detail/block.hpp +++ b/include/gras/detail/block.hpp @@ -97,6 +97,42 @@ inline ValueType Block::get(const std::string &key) return this->_get_property(key).as<ValueType>(); } +template <typename ValueType> +inline void Block::post_output_msg(const size_t i, const ValueType &value) +{ + this->_post_output_msg(i, PMC_M(value)); +} + +template <> +inline void Block::post_output_msg(const size_t i, const PMCC &value) +{ + this->_post_output_msg(i, value); +} + +template <> +inline void Block::post_output_msg(const size_t i, const PMC &value) +{ + this->_post_output_msg(i, value); +} + +template <typename ValueType> +inline void Block::post_input_msg(const size_t i, const ValueType &value) +{ + this->_post_input_msg(i, PMC_M(value)); +} + +template <> +inline void Block::post_input_msg(const size_t i, const PMCC &value) +{ + this->_post_input_msg(i, value); +} + +template <> +inline void Block::post_input_msg(const size_t i, const PMC &value) +{ + this->_post_input_msg(i, value); +} + } //namespace gras #endif /*INCLUDED_GRAS_DETAIL_BLOCK_HPP*/ diff --git a/lib/block_message.cpp b/lib/block_message.cpp index eae0c68..ef7dda6 100644 --- a/lib/block_message.cpp +++ b/lib/block_message.cpp @@ -12,7 +12,7 @@ void Block::post_output_tag(const size_t which_output, const Tag &tag) (*this)->block->post_downstream(which_output, InputTagMessage(tag)); } -void Block::post_output_msg(const size_t which_output, const PMCC &msg) +void Block::_post_output_msg(const size_t which_output, const PMCC &msg) { (*this)->block->stats.msgs_produced[which_output]++; (*this)->block->post_downstream(which_output, InputMsgMessage(msg)); @@ -56,7 +56,7 @@ void Block::post_input_tag(const size_t which_input, const Tag &tag) actor.GetFramework().Send(message, Theron::Address::Null(), actor.GetAddress()); } -void Block::post_input_msg(const size_t which_input, const PMCC &msg) +void Block::_post_input_msg(const size_t which_input, const PMCC &msg) { InputMsgMessage message(msg); message.index = which_input; |