DataSource.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon Jan 19 14:11:25 CET 2004 DataSource.hpp
3 
4  DataSource.hpp - description
5  -------------------
6  begin : Mon January 19 2004
7  copyright : (C) 2004 Peter Soetens
8  email : peter.soetens@mech.kuleuven.ac.be
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 #ifndef CORELIB_DATASOURCE_HPP
39 #define CORELIB_DATASOURCE_HPP
40 
41 #include <map>
42 #include <string>
43 #include <exception>
44 #include "../rtt-config.h"
45 #include <boost/call_traits.hpp>
46 #include <boost/static_assert.hpp>
47 #include <boost/type_traits/add_reference.hpp>
48 #include <boost/type_traits/add_const.hpp>
49 
50 #include "../base/DataSourceBase.hpp"
51 
52 namespace RTT
53 { namespace internal {
54 
55 
56 #ifndef ORO_EMBEDDED
57 
62  struct RTT_API bad_assignment : public std::exception
63  {
64  virtual ~bad_assignment() throw();
65  virtual const char* what() const throw();
66  };
67 #endif
68 
69  namespace details
70  {
71  template<typename X>
72  struct HasConst
73  { static const int value = 0; };
74  template<typename X>
75  struct HasConst<X const>
76  { static const int value = 1; };
77 
78  template<typename X>
79  struct GetConstRef
80  { typedef typename boost::add_reference<typename boost::add_const<X>::type>::type type; };
81  template<>
82  struct GetConstRef<void>
83  { typedef void type; };
84  }
85 
93  template<typename T>
94  class DataSource
95  : public base::DataSourceBase
96  {
97  protected:
98  virtual ~DataSource();
99 
100  public:
101 
105  typedef T value_t;
106  typedef T result_t;
108 
113  BOOST_STATIC_ASSERT( !details::HasConst<T>::value );
114 
115  typedef typename boost::intrusive_ptr<DataSource<T> > shared_ptr;
116 
117  typedef typename boost::intrusive_ptr<const DataSource<T> > const_ptr;
118 
122  virtual result_t get() const = 0;
123 
129  virtual result_t value() const = 0;
130 
137  virtual const_reference_t rvalue() const = 0;
138 
141  void const* getRawConstPointer() { return &rvalue(); }
142 
143  virtual bool evaluate() const;
144 
145  virtual DataSource<T>* clone() const = 0;
146 
147  virtual DataSource<T>* copy( std::map<const base::DataSourceBase*, base::DataSourceBase*>& alreadyCloned ) const = 0;
148 
149  virtual std::string getType() const;
150 
154  static std::string GetType();
155 
156  virtual const types::TypeInfo* getTypeInfo() const;
157 
161  static const types::TypeInfo* GetTypeInfo();
162 
167  static std::string GetTypeName();
168 
169  virtual std::string getTypeName() const;
170 
175  static DataSource<T>* narrow(base::DataSourceBase* db);
176 
177  };
178 
183  template<typename T>
185  : public DataSource<T>
186  {
187  protected:
189  public:
190  typedef typename DataSource<T>::value_t value_t;
192  typedef typename boost::call_traits<value_t>::param_type param_t;
193  typedef typename boost::call_traits<value_t>::reference reference_t;
194 
198  typedef boost::intrusive_ptr<AssignableDataSource<T> > shared_ptr;
199  typedef typename boost::intrusive_ptr<const AssignableDataSource<T> > const_ptr;
200 
204  virtual void set( param_t t ) = 0;
205 
210  virtual reference_t set() = 0;
211 
214  void* getRawPointer() { return &set(); }
215 
216  virtual bool isAssignable() const { return true; }
217 
218  virtual bool update( base::DataSourceBase* other );
219 
220  virtual base::ActionInterface* updateAction( base::DataSourceBase* other);
221 
222  virtual AssignableDataSource<T>* clone() const = 0;
223 
224  virtual AssignableDataSource<T>* copy( std::map<const base::DataSourceBase*, base::DataSourceBase*>& alreadyCloned ) const = 0;
225 
230  static AssignableDataSource<T>* narrow(base::DataSourceBase* db);
231 
232  };
233 }}
234 
235 // workaround inclusion dependencies.
236 #ifndef ORO_CORELIB_DATASOURCES_HPP
237 #include "DataSource.inl"
238 #endif
239 
240 /*
241  * Extern template declarations for core data source types
242  * (instantiated in DataSources.cpp)
243  */
244 RTT_EXT_IMPL template class RTT_API RTT::internal::DataSource< bool >;
245 RTT_EXT_IMPL template class RTT_API RTT::internal::AssignableDataSource< bool >;
246 RTT_EXT_IMPL template class RTT_API RTT::internal::DataSource< std::string >;
247 RTT_EXT_IMPL template class RTT_API RTT::internal::AssignableDataSource< std::string >;
248 
249 #endif
250 
virtual bool isAssignable() const
Definition: DataSource.hpp:216
boost::intrusive_ptr< const AssignableDataSource< T > > const_ptr
Definition: DataSource.hpp:199
The base class for all internal data representations.
boost::call_traits< value_t >::reference reference_t
Definition: DataSource.hpp:193
Based on the software pattern &#39;command&#39;, this interface allows execution of action objects...
boost::intrusive_ptr< DataSource< T > > shared_ptr
Definition: DataSource.hpp:115
boost::intrusive_ptr< AssignableDataSource< T > > shared_ptr
Definition: DataSource.hpp:198
boost::add_reference< typename boost::add_const< X >::type >::type type
Definition: DataSource.hpp:80
boost::intrusive_ptr< const DataSource< T > > const_ptr
Definition: DataSource.hpp:117
DataSource< T >::value_t value_t
Definition: DataSource.hpp:190
DataSource< T >::const_reference_t const_reference_t
Definition: DataSource.hpp:191
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
void const * getRawConstPointer()
Definition: DataSource.hpp:141
details::GetConstRef< T >::type const_reference_t
Definition: DataSource.hpp:107
static bool update(TaskContext *tc)
boost::call_traits< value_t >::param_type param_t
Definition: DataSource.hpp:192


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:32