00001 #ifndef ORO_CORELIB_DATASOURCES_INL 00002 #define ORO_CORELIB_DATASOURCES_INL 00003 00004 #include "DataSources.hpp" 00005 #include "DataSource.inl" 00006 00007 namespace RTT 00008 { 00009 template<typename T> 00010 ValueDataSource<T>::~ValueDataSource() {} 00011 00012 template<typename T> 00013 ValueDataSource<T>::ValueDataSource( T data ) 00014 : mdata( data ) 00015 { 00016 } 00017 00018 template<typename T> 00019 ValueDataSource<T>::ValueDataSource( ) 00020 : mdata() 00021 { 00022 } 00023 00024 template<typename T> 00025 typename DataSource<T>::result_t ValueDataSource<T>::value() const 00026 { 00027 return mdata; 00028 } 00029 00030 template<typename T> 00031 typename DataSource<T>::result_t ValueDataSource<T>::get() const 00032 { 00033 return mdata; 00034 } 00035 00036 template<typename T> 00037 void ValueDataSource<T>::set( typename AssignableDataSource<T>::param_t t ) 00038 { 00039 mdata = t; 00040 } 00041 00042 template<typename T> 00043 typename AssignableDataSource<T>::reference_t ValueDataSource<T>::set() { 00044 return mdata; 00045 } 00046 00047 template<typename T> 00048 typename AssignableDataSource<T>::const_reference_t ValueDataSource<T>::rvalue() const { 00049 return mdata; 00050 } 00051 00052 template<typename T> 00053 ValueDataSource<T>* ValueDataSource<T>::clone() const 00054 { 00055 return new ValueDataSource<T>( mdata ); 00056 } 00057 00058 template<typename T> 00059 ValueDataSource<T>* ValueDataSource<T>::copy( std::map<const DataSourceBase*, DataSourceBase*>& replace ) const { 00060 // if somehow a copy exists, return the copy, otherwise return this (see Attribute copy) 00061 if ( replace[this] != 0 ) { 00062 assert ( dynamic_cast<ValueDataSource<T>*>( replace[this] ) == static_cast<ValueDataSource<T>*>( replace[this] ) ); 00063 return static_cast<ValueDataSource<T>*>( replace[this] ); 00064 } 00065 // Other pieces in the code rely on insertion in the map : 00066 replace[this] = const_cast<ValueDataSource<T>*>(this); 00067 // return this instead of a copy. 00068 return const_cast<ValueDataSource<T>*>(this); 00069 } 00070 00071 template<typename T> 00072 ConstantDataSource<T>::~ConstantDataSource() {} 00073 00074 template<typename T> 00075 ConstantDataSource<T>::ConstantDataSource( T value ) 00076 : mdata( value ) 00077 { 00078 } 00079 00080 template<typename T> 00081 typename DataSource<T>::result_t ConstantDataSource<T>::get() const 00082 { 00083 return mdata; 00084 } 00085 00086 template<typename T> 00087 typename DataSource<T>::result_t ConstantDataSource<T>::value() const 00088 { 00089 return mdata; 00090 } 00091 00092 template<typename T> 00093 ConstantDataSource<T>* ConstantDataSource<T>::clone() const 00094 { 00095 return new ConstantDataSource<T>(mdata); 00096 } 00097 00098 template<typename T> 00099 ConstantDataSource<T>* ConstantDataSource<T>::copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const { 00100 // no copy needed, share this with all instances. 00101 return const_cast<ConstantDataSource<T>*>(this); 00102 } 00103 00104 template<typename T> 00105 ReferenceDataSource<T>::~ReferenceDataSource() {} 00106 00107 template<typename T> 00108 ReferenceDataSource<T>::ReferenceDataSource( typename AssignableDataSource<T>::reference_t ref ) 00109 : mref( ref ) 00110 { 00111 } 00112 00113 template<typename T> 00114 typename DataSource<T>::result_t ReferenceDataSource<T>::get() const 00115 { 00116 return mref; 00117 } 00118 00119 template<typename T> 00120 typename DataSource<T>::result_t ReferenceDataSource<T>::value() const 00121 { 00122 return mref; 00123 } 00124 00125 template<typename T> 00126 void ReferenceDataSource<T>::set( typename AssignableDataSource<T>::param_t t ) 00127 { 00128 mref = t; 00129 } 00130 00131 template<typename T> 00132 typename AssignableDataSource<T>::reference_t ReferenceDataSource<T>::set() { 00133 return mref; 00134 } 00135 00136 template<typename T> 00137 typename AssignableDataSource<T>::const_reference_t ReferenceDataSource<T>::rvalue() const { 00138 return mref; 00139 } 00140 00141 template<typename T> 00142 ReferenceDataSource<T>* ReferenceDataSource<T>::clone() const 00143 { 00144 return new ReferenceDataSource<T>(mref); 00145 } 00146 00147 template<typename T> 00148 ReferenceDataSource<T>* ReferenceDataSource<T>::copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const { 00149 return const_cast<ReferenceDataSource<T>*>(this); // no copy needed, data is outside. 00150 } 00151 00152 namespace detail { 00153 00154 template< typename BoundT> 00155 UnboundDataSource<BoundT>::UnboundDataSource( typename BoundT::result_t data ) 00156 : BoundT( data ) 00157 { 00158 } 00159 00160 template< typename BoundT> 00161 UnboundDataSource<BoundT>::UnboundDataSource( ) 00162 { 00163 } 00164 00165 template< typename BoundT> 00166 UnboundDataSource<BoundT>* UnboundDataSource<BoundT>::copy( std::map<const DataSourceBase*, DataSourceBase*>& replace) const { 00167 if ( replace[this] != 0 ) 00168 return static_cast<UnboundDataSource<BoundT>*>(replace[this]); 00169 replace[this] = new UnboundDataSource<BoundT>( this->get() ); 00170 return static_cast<UnboundDataSource<BoundT>*>(replace[this]); 00171 } 00172 } 00173 } 00174 00175 #endif
1.5.8