00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef CORELIB_DATASOURCE_HPP
00039 #define CORELIB_DATASOURCE_HPP
00040
00041 #include <map>
00042 #include <string>
00043 #include <exception>
00044 #include "../rtt-config.h"
00045 #include <boost/call_traits.hpp>
00046 #include <boost/static_assert.hpp>
00047 #include <boost/type_traits/add_reference.hpp>
00048 #include <boost/type_traits/add_const.hpp>
00049
00050 #include "../base/DataSourceBase.hpp"
00051
00052 namespace RTT
00053 { namespace internal {
00054
00055
00056 #ifndef ORO_EMBEDDED
00057
00062 struct RTT_API bad_assignment : public std::exception
00063 {
00064 virtual ~bad_assignment() throw();
00065 virtual const char* what() const throw();
00066 };
00067 #endif
00068
00069 namespace details
00070 {
00071 template<typename X>
00072 struct HasConst
00073 { static const int value = 0; };
00074 template<typename X>
00075 struct HasConst<X const>
00076 { static const int value = 1; };
00077
00078 template<typename X>
00079 struct GetConstRef
00080 { typedef typename boost::add_reference<typename boost::add_const<X>::type>::type type; };
00081 template<>
00082 struct GetConstRef<void>
00083 { typedef void type; };
00084 }
00085
00093 template<typename T>
00094 class DataSource
00095 : public base::DataSourceBase
00096 {
00097 protected:
00098 virtual ~DataSource();
00099
00100 public:
00101
00105 typedef T value_t;
00106 typedef T result_t;
00107 typedef typename details::GetConstRef<T>::type const_reference_t;
00108
00113 BOOST_STATIC_ASSERT( !details::HasConst<T>::value );
00114
00115 typedef typename boost::intrusive_ptr<DataSource<T> > shared_ptr;
00116
00117 typedef typename boost::intrusive_ptr<const DataSource<T> > const_ptr;
00118
00122 virtual result_t get() const = 0;
00123
00129 virtual result_t value() const = 0;
00130
00137 virtual const_reference_t rvalue() const = 0;
00138
00141 void const* getRawConstPointer() { return &rvalue(); }
00142
00143 virtual bool evaluate() const;
00144
00145 virtual DataSource<T>* clone() const = 0;
00146
00147 virtual DataSource<T>* copy( std::map<const base::DataSourceBase*, base::DataSourceBase*>& alreadyCloned ) const = 0;
00148
00149 virtual std::string getType() const;
00150
00154 static std::string GetType();
00155
00156 virtual const types::TypeInfo* getTypeInfo() const;
00157
00161 static const types::TypeInfo* GetTypeInfo();
00162
00167 static std::string GetTypeName();
00168
00169 virtual std::string getTypeName() const;
00170
00175 static DataSource<T>* narrow(base::DataSourceBase* db);
00176
00177 };
00178
00183 template<typename T>
00184 class AssignableDataSource
00185 : public DataSource<T>
00186 {
00187 protected:
00188 ~AssignableDataSource();
00189 public:
00190 typedef typename DataSource<T>::value_t value_t;
00191 typedef typename DataSource<T>::const_reference_t const_reference_t;
00192 typedef typename boost::call_traits<value_t>::param_type param_t;
00193 typedef typename boost::call_traits<value_t>::reference reference_t;
00194
00198 typedef boost::intrusive_ptr<AssignableDataSource<T> > shared_ptr;
00199 typedef typename boost::intrusive_ptr<const AssignableDataSource<T> > const_ptr;
00200
00204 virtual void set( param_t t ) = 0;
00205
00210 virtual reference_t set() = 0;
00211
00214 void* getRawPointer() { return &set(); }
00215
00216 virtual bool isAssignable() const { return true; }
00217
00218 virtual bool update( base::DataSourceBase* other );
00219
00220 virtual base::ActionInterface* updateAction( base::DataSourceBase* other);
00221
00222 virtual AssignableDataSource<T>* clone() const = 0;
00223
00224 virtual AssignableDataSource<T>* copy( std::map<const base::DataSourceBase*, base::DataSourceBase*>& alreadyCloned ) const = 0;
00225
00230 static AssignableDataSource<T>* narrow(base::DataSourceBase* db);
00231
00232 };
00233 }}
00234
00235
00236 #ifndef ORO_CORELIB_DATASOURCES_HPP
00237 #include "DataSource.inl"
00238 #endif
00239 #endif
00240