DataSources.inl

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     void ValueDataSource<T>::set( typename AssignableDataSource<T>::param_t t )
00026     {
00027         mdata = t;
00028     }
00029 
00030     template<typename T>
00031     ValueDataSource<T>* ValueDataSource<T>::clone() const
00032     {
00033         return new ValueDataSource<T>( mdata );
00034     }
00035 
00036     template<typename T>
00037     ValueDataSource<T>* ValueDataSource<T>::copy( std::map<const DataSourceBase*, DataSourceBase*>& replace ) const {
00038         // if somehow a copy exists, return the copy, otherwise return this (see Attribute copy)
00039         if ( replace[this] != 0 ) {
00040             assert ( dynamic_cast<ValueDataSource<T>*>( replace[this] ) == static_cast<ValueDataSource<T>*>( replace[this] ) );
00041             return static_cast<ValueDataSource<T>*>( replace[this] );
00042         }
00043         // Other pieces in the code rely on insertion in the map :
00044         replace[this] = const_cast<ValueDataSource<T>*>(this);
00045         // return this instead of a copy.
00046         return const_cast<ValueDataSource<T>*>(this);
00047     }
00048 
00049     template<typename T>
00050     ConstantDataSource<T>::~ConstantDataSource() {}
00051 
00052     template<typename T>
00053     ConstantDataSource<T>::ConstantDataSource( T value )
00054         : mdata( value )
00055     {
00056     }
00057 
00058     template<typename T>
00059     ConstantDataSource<T>* ConstantDataSource<T>::clone() const
00060     {
00061         return new ConstantDataSource<T>(mdata);
00062     }
00063 
00064     template<typename T>
00065     ConstantDataSource<T>* ConstantDataSource<T>::copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const {
00066         // no copy needed, share this with all instances.
00067         return const_cast<ConstantDataSource<T>*>(this);
00068     }
00069 
00070     template<typename T>
00071     ReferenceDataSource<T>::~ReferenceDataSource() {}
00072 
00073     template<typename T>
00074     ReferenceDataSource<T>::ReferenceDataSource( typename AssignableDataSource<T>::reference_t ref )
00075         : mref( ref )
00076     {
00077     }
00078     template<typename T>
00079     void ReferenceDataSource<T>::set( typename AssignableDataSource<T>::param_t t )
00080     {
00081         mref = t;
00082     }
00083 
00084     template<typename T>
00085     ReferenceDataSource<T>* ReferenceDataSource<T>::clone() const
00086     {
00087         return new ReferenceDataSource<T>(mref);
00088     }
00089 
00090     template<typename T>
00091     ReferenceDataSource<T>* ReferenceDataSource<T>::copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const {
00092         return const_cast<ReferenceDataSource<T>*>(this); // no copy needed, data is outside.
00093     }
00094 
00095     namespace detail {
00096 
00097         template< typename BoundT>
00098         UnboundDataSource<BoundT>::UnboundDataSource( typename BoundT::result_t data )
00099             : BoundT( data )
00100         {
00101         }
00102 
00103         template< typename BoundT>
00104         UnboundDataSource<BoundT>::UnboundDataSource( )
00105         {
00106         }
00107 
00108         template< typename BoundT>
00109         UnboundDataSource<BoundT>* UnboundDataSource<BoundT>::copy( std::map<const DataSourceBase*, DataSourceBase*>& replace) const {
00110             if ( replace[this] != 0 )
00111                 return static_cast<UnboundDataSource<BoundT>*>(replace[this]);
00112             replace[this] = new UnboundDataSource<BoundT>( this->get() );
00113             return static_cast<UnboundDataSource<BoundT>*>(replace[this]);
00114         }
00115     }
00116 }
00117 
00118 #endif
Generated on Thu Dec 23 13:22:37 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3