Orocos Real-Time Toolkit  2.8.3
ChannelElement.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Thu Oct 22 11:59:07 CEST 2009 ChannelElement.hpp
3 
4  ChannelElement.hpp - description
5  -------------------
6  begin : Thu October 22 2009
7  copyright : (C) 2009 Sylvain Joyeux
8  email : sylvain.joyeux@m4x.org
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 
39 #ifndef ORO_CHANNEL_ELEMENT_HPP
40 #define ORO_CHANNEL_ELEMENT_HPP
41 
42 #include <boost/intrusive_ptr.hpp>
43 #include <boost/call_traits.hpp>
44 #include "ChannelElementBase.hpp"
45 #include "../FlowStatus.hpp"
46 
47 namespace RTT { namespace base {
48 
49 
53  template<typename T>
55  {
56  public:
57  typedef T value_t;
58  typedef boost::intrusive_ptr< ChannelElement<T> > shared_ptr;
59  typedef typename boost::call_traits<T>::param_type param_t;
60  typedef typename boost::call_traits<T>::reference reference_t;
61 
62  shared_ptr getOutput()
63  {
64  return boost::static_pointer_cast< base::ChannelElement<T> >(
66  }
67 
68  shared_ptr getInput()
69  {
70  return boost::static_pointer_cast< base::ChannelElement<T> >(
72  }
73 
82  virtual bool data_sample(param_t sample)
83  {
84  typename ChannelElement<T>::shared_ptr output = boost::static_pointer_cast< ChannelElement<T> >(getOutput());
85  if (output)
86  return output->data_sample(sample);
87  return false;
88  }
89 
90  virtual value_t data_sample()
91  {
92  typename ChannelElement<T>::shared_ptr input = boost::static_pointer_cast< ChannelElement<T> >(getInput());
93  if (input)
94  return input->data_sample();
95  return value_t();
96  }
97 
103  virtual bool write(param_t sample)
104  {
105  typename ChannelElement<T>::shared_ptr output = boost::static_pointer_cast< ChannelElement<T> >(getOutput());
106  if (output)
107  return output->write(sample);
108  return false;
109  }
110 
116  virtual FlowStatus read(reference_t sample, bool copy_old_data)
117  {
118  typename ChannelElement<T>::shared_ptr input = this->getInput();
119  if (input)
120  return input->read(sample, copy_old_data);
121  else
122  return NoData;
123  }
124  };
125 }}
126 
127 #endif
128 
boost::call_traits< T >::param_type param_t
boost::intrusive_ptr< ChannelElement< T > > shared_ptr
FlowStatus
Returns the status of a data flow read.
Definition: FlowStatus.hpp:54
virtual FlowStatus read(reference_t sample, bool copy_old_data)
Reads a sample from the connection.
virtual bool write(param_t sample)
Writes a new sample on this connection.
ChannelElementBase::shared_ptr getInput()
Returns the current input channel element.
A typed version of ChannelElementBase.
boost::call_traits< T >::reference reference_t
virtual value_t data_sample()
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51
In the data flow implementation, a channel is created by chaining ChannelElementBase objects...
ChannelElementBase::shared_ptr getOutput()
Returns the next channel element in the channel&#39;s propagation direction.
virtual bool data_sample(param_t sample)
Provides a data sample to initialize this connection.