Orocos Real-Time Toolkit  2.6.0
DataSource.inl
00001 #ifndef CORELIB_DATASOURCE_INL
00002 #define CORELIB_DATASOURCE_INL
00003 
00004 #include "AssignCommand.hpp"
00005 #include "DataSourceTypeInfo.hpp"
00006 #include "../types/TypeTransporter.hpp"
00007 
00008 #include "../rtt-config.h"
00009 
00010 namespace RTT
00011 { namespace internal {
00012 
00013 
00014   template<typename T>
00015   DataSource<T>::~DataSource()
00016   {
00017   }
00018 
00019   template< typename T>
00020   std::string DataSource<T>::getType() const
00021   {
00022       return DataSource<T>::GetType();
00023   }
00024 
00025   template< typename T>
00026   std::string DataSource<T>::getTypeName() const
00027   {
00028       return DataSource<T>::GetTypeName();
00029   }
00030 
00031   template< typename T>
00032   std::string DataSource<T>::GetType()
00033   {
00034       return DataSourceTypeInfo< T >::getTypeName() + DataSourceTypeInfo< T >::getQualifier();
00035 
00036   }
00037 
00038   template< typename T>
00039   std::string DataSource<T>::GetTypeName()
00040   {
00041       return DataSourceTypeInfo< T >::getTypeName();
00042 
00043   }
00044 
00045   template< typename T>
00046   const types::TypeInfo* DataSource<T>::getTypeInfo() const { return GetTypeInfo(); }
00047 
00048   template< typename T>
00049   const types::TypeInfo* DataSource<T>::GetTypeInfo() { return DataSourceTypeInfo<T>::getTypeInfo(); }
00050 
00051   template< typename T>
00052   bool DataSource<T>::evaluate() const
00053   {
00054       this->get();
00055       return true;
00056   }
00057 
00058   template<>
00059   inline void const* DataSource<void>::getRawConstPointer() { return 0; }
00060 
00061     template<typename T>
00062     AssignableDataSource<T>::~AssignableDataSource()
00063     {}
00064 
00065     template<class T>
00066     DataSource<T>* DataSource<T>::narrow(base::DataSourceBase* dsb) {
00067         DataSource<T>* ret = dynamic_cast< DataSource<T>* >( dsb );
00068     return ret;
00069     }
00070 
00071     template<class T>
00072     AssignableDataSource<T>* AssignableDataSource<T>::narrow(base::DataSourceBase* dsb) {
00073         AssignableDataSource<T>* ret = dynamic_cast< AssignableDataSource<T>* >( dsb );
00074     return ret;
00075     }
00076 
00077     template<class T>
00078     bool AssignableDataSource<T>::update( base::DataSourceBase* other ) {
00079         if (!other) return false;
00080 
00081         base::DataSourceBase::shared_ptr r( other );
00082         typename DataSource<T>::shared_ptr o = boost::dynamic_pointer_cast< DataSource<T> >( DataSourceTypeInfo<T>::getTypeInfo()->convert(r) );
00083         if (o) {
00084             if ( o->evaluate() ) {
00085                 this->set( o->value() );
00086                 return true;
00087             }
00088             return false;
00089         }
00090         return false;
00091     }
00092 
00093     template<class T>
00094     base::ActionInterface* AssignableDataSource<T>::updateAction( base::DataSourceBase* other) {
00095 #ifndef ORO_EMBEDDED
00096         if (!other) throw bad_assignment();
00097 #else
00098         if (!other) return 0;
00099 #endif
00100 
00101         // Use the same rules of parameter passing as C++, but no const for 'int',...
00102         base::DataSourceBase::shared_ptr r( other );
00103         typename DataSource<value_t>::shared_ptr t = boost::dynamic_pointer_cast< DataSource<value_t> >( DataSourceTypeInfo<T>::getTypeInfo()->convert(r) );
00104         if ( t )
00105             return new AssignCommand<value_t>( this, t );
00106 
00107 #ifndef ORO_EMBEDDED
00108         throw bad_assignment();
00109 #endif
00110 
00111         return 0;
00112     }
00113 }}
00114 
00115 
00116 #endif