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