Orocos Real-Time Toolkit  2.8.3
SequenceConstructor.hpp
Go to the documentation of this file.
1 #ifndef SEQUENCECONSTRUCTOR_HPP_
2 #define SEQUENCECONSTRUCTOR_HPP_
3 
4 #include "TypeConstructor.hpp"
5 #include "../internal/DataSources.hpp"
6 #include <vector>
7 
8 namespace RTT
9 {
10  namespace types
11  {
15  template<class T>
16  struct sequence_ctor: public std::unary_function<int, const T& >
17  {
18  typedef const T& ( Signature)(int);
19  mutable boost::shared_ptr<T> ptr;
21  ptr(new T())
22  {
23  }
24  const T& operator()(int size) const
25  {
26  ptr->resize(size);
27  return *(ptr);
28  }
29  };
30 
35  template<class T>
37  {
38  typedef const std::vector<T>& result_type;
39  typedef T argument_type;
40  result_type operator()(const std::vector<T>& args) const
41  {
42  return args;
43  }
44  };
45 
50  template<class T>
53  };
54 
59  template<class T>
61  {
62  typedef typename T::value_type value_type;
63  virtual base::DataSourceBase::shared_ptr build(const std::vector<
65  {
66  if (args.size() == 0)
69  for (unsigned int i = 0; i != args.size(); ++i)
70  {
72  boost::dynamic_pointer_cast<internal::DataSource<value_type> >(
73  args[i]);
74  if (dsd)
75  vds->add(dsd);
76  else
78  }
79  return vds;
80  }
81 
82  };
83 
89  template<class T>
90  struct sequence_ctor2: public std::binary_function<int, typename T::value_type,
91  const T&>
92  {
93  typedef const T& ( Signature)(int, typename T::value_type);
94  mutable boost::shared_ptr<T> ptr;
96  ptr(new T() )
97  {
98  }
99  const T& operator()(int size, typename T::value_type value) const
100  {
101  ptr->resize(size);
102  ptr->assign(size, value);
103  return *(ptr);
104  }
105  };
106 
107  }
108 }
109 
110 #endif /* SEQUENCECONSTRUCTOR_HPP_ */
DataSource is a base class representing a generic way to read data of type T.
Definition: DataSource.hpp:94
result_type operator()(const std::vector< T > &args) const
boost::shared_ptr< T > ptr
Sequence constructor which takes the number of elements in the sequence.
Constructs a sequence from the number of elements and a prototype element for these elements...
internal::NArityDataSource< sequence_varargs_ctor< T > > type
const T & operator()(int size, typename T::value_type value) const
const T &( Signature)(int, typename T::value_type)
boost::intrusive_ptr< NArityDataSource< function > > shared_ptr
const std::vector< T > & result_type
const T & operator()(int size) const
virtual base::DataSourceBase::shared_ptr build(const std::vector< base::DataSourceBase::shared_ptr > &args) const
Inspect args and return a type constructed with these args if such a constructor exists.
boost::intrusive_ptr< DataSource< T > > shared_ptr
Definition: DataSource.hpp:115
See NArityDataSource which requires a function object like this one.
Helper DataSource for constructing sequences with a variable number of parameters.
This interface describes how constructors work.
boost::intrusive_ptr< DataSourceBase > shared_ptr
Use this type to store a pointer to a DataSourceBase.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51
boost::shared_ptr< T > ptr
A generic N-arity composite DataSource.
Constructs an sequence with n elements, which are given upon construction time.