00001 #ifndef ROSRTT_CHANNEL_ELEMENT_HPP 00002 #define ROSRTT_CHANNEL_ELEMENT_HPP 00003 00004 #include <boost/intrusive_ptr.hpp> 00005 #include <boost/call_traits.hpp> 00006 #include "channel_element_base.hpp" 00007 #include "../common.h" 00008 00009 namespace hpcl_rtt 00010 { 00011 00015 template<typename T> 00016 class ChannelElement : public ChannelElementBase 00017 { 00018 public: 00019 typedef T value_t; 00020 typedef boost::intrusive_ptr< ChannelElement<T> > shared_ptr; 00021 typedef typename boost::call_traits<T>::param_type param_t; 00022 typedef typename boost::call_traits<T>::reference reference_t; 00023 00024 shared_ptr getOutput() 00025 { 00026 return boost::static_pointer_cast< ChannelElement<T> >(ChannelElementBase::getOutput()); 00027 } 00028 00029 shared_ptr getInput() 00030 { 00031 return boost::static_pointer_cast< ChannelElement<T> >(ChannelElementBase::getInput()); 00032 } 00033 00042 virtual bool data_sample(param_t sample) 00043 { 00044 typename ChannelElement<T>::shared_ptr output = boost::static_pointer_cast< ChannelElement<T> >(getOutput()); 00045 if (output) 00046 { 00047 return output->data_sample(sample); 00048 } 00049 return false; 00050 } 00051 00052 virtual value_t data_sample() 00053 { 00054 typename ChannelElement<T>::shared_ptr input = boost::static_pointer_cast< ChannelElement<T> >(getInput()); 00055 if (input) 00056 { 00057 return input->data_sample(); 00058 } 00059 return value_t(); 00060 } 00061 00067 virtual bool write(param_t sample) 00068 { 00069 typename ChannelElement<T>::shared_ptr output = boost::static_pointer_cast< ChannelElement<T> >(getOutput()); 00070 if (output) 00071 { 00072 return output->write(sample); 00073 } 00074 return false; 00075 } 00076 00082 virtual FlowStatus read(reference_t sample, bool copy_old_data) 00083 { 00084 typename ChannelElement<T>::shared_ptr input = this->getInput(); 00085 if (input) 00086 { 00087 return input->read(sample, copy_old_data); 00088 } 00089 else 00090 { 00091 return NoData; 00092 } 00093 } 00094 }; 00095 00096 } 00097 00098 #endif 00099