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
00039 #ifndef ORO_ARRAYPARTDATASOURCE_HPP_
00040 #define ORO_ARRAYPARTDATASOURCE_HPP_
00041
00042 #include "DataSource.hpp"
00043
00044 namespace RTT
00045 {
00046 namespace internal
00047 {
00059 template<typename T>
00060 class ArrayPartDataSource
00061 : public AssignableDataSource<T>
00062 {
00063
00064 typename AssignableDataSource<T>::value_t* mref;
00065
00066 DataSource<unsigned int>::shared_ptr mindex;
00067
00068 base::DataSourceBase::shared_ptr mparent;
00069
00070 unsigned int mmax;
00071 public:
00072 ~ArrayPartDataSource() {}
00073
00074 typedef boost::intrusive_ptr<ArrayPartDataSource<T> > shared_ptr;
00075
00083 ArrayPartDataSource( typename AssignableDataSource<T>::reference_t ref,
00084 DataSource<unsigned int>::shared_ptr index,
00085 base::DataSourceBase::shared_ptr parent, unsigned int max )
00086 : mref(&ref), mindex(index), mparent(parent), mmax(max)
00087 {
00088 }
00089
00090 typename DataSource<T>::result_t get() const
00091 {
00092 unsigned int i = mindex->get();
00093 if (i >= mmax)
00094 return internal::NA<T>::na();
00095 return mref[ i ];
00096 }
00097
00098 typename DataSource<T>::result_t value() const
00099 {
00100 unsigned int i = mindex->get();
00101 if (i >= mmax)
00102 return internal::NA<T>::na();
00103 return mref[ i ];
00104 }
00105
00106 void set( typename AssignableDataSource<T>::param_t t )
00107 {
00108 unsigned int i = mindex->get();
00109 if (i >= mmax)
00110 return;
00111 mref[ i ] = t;
00112 updated();
00113 }
00114
00115 typename AssignableDataSource<T>::reference_t set()
00116 {
00117 unsigned int i = mindex->get();
00118 if (i >= mmax)
00119 return internal::NA<typename AssignableDataSource<T>::reference_t>::na();
00120 return mref[ i ];
00121 }
00122
00123 typename AssignableDataSource<T>::const_reference_t rvalue() const
00124 {
00125 unsigned int i = mindex->get();
00126 if (i >= mmax)
00127 return internal::NA<typename AssignableDataSource<T>::const_reference_t>::na();
00128 return mref[ i ];
00129 }
00130
00131 void updated() {
00132 if (mparent) mparent->updated();
00133 }
00134
00135 virtual ArrayPartDataSource<T>* clone() const {
00136 return new ArrayPartDataSource<T>( *mref, mindex, mparent, mmax);
00137 }
00138
00139 virtual ArrayPartDataSource<T>* copy( std::map<const base::DataSourceBase*, base::DataSourceBase*>& replace ) const {
00140
00141 if ( replace[this] != 0 ) {
00142 assert ( dynamic_cast<ArrayPartDataSource<T>*>( replace[this] ) == static_cast<ArrayPartDataSource<T>*>( replace[this] ) );
00143 return static_cast<ArrayPartDataSource<T>*>( replace[this] );
00144 }
00145 replace[this] = new ArrayPartDataSource<T>(*mref, mindex->copy(replace), mparent->copy(replace), mmax);
00146 return static_cast<ArrayPartDataSource<T>*>(replace[this]);
00147
00148 }
00149 };
00150
00151 }
00152 }
00153
00154 #endif