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
00040 #ifndef MULTIVECTOR_COMPOSITION_HPP
00041 #define MULTIVECTOR_COMPOSITION_HPP
00042
00043 #include "MultiVector.hpp"
00044 #include "../Property.hpp"
00045 #include "../PropertyBag.hpp"
00046 #include "../Logger.hpp"
00047
00048 namespace RTT
00049 { namespace extras {
00050
00055 template<class T, int S>
00056 void decomposeProperty(base::PropertyIntrospection *pi, const Property< MultiVector<S, T> >& c)
00057 {
00058 Property<PropertyBag> result(c.getName(),c.getDescription(), PropertyBag("MultiVector") );
00059
00060 MultiVector<S,T> vec = c;
00061 Property<int>* dimension = new Property<int>("Size","Size of the MultiVector", vec.size() );
00062
00063 result.value().add( dimension );
00064
00065 std::stringstream data_name;
00066
00067 for ( int i=0; i < dimension->get() ; i++)
00068 {
00069 data_name << i;
00070 result.value().add( new Property<T>(data_name.str(),"",vec[i]) );
00071 data_name.str("");
00072 }
00073
00074 pi->introspect(result);
00075 deleteProperties( result.value() );
00076
00077 }
00078
00079 template<class T, int S>
00080 void decomposeProperty(base::PropertyIntrospection *pi, const Property< const MultiVector<S, T>& >& c)
00081 {
00082 Property<PropertyBag> result(c.getName(),c.getDescription(), PropertyBag("MultiVector") );
00083
00084 MultiVector<S,T> vec = c;
00085 Property<int>* dimension = new Property<int>("Size","Size of the MultiVector", vec.size() );
00086
00087 result.value().add( dimension );
00088
00089 std::stringstream data_name;
00090
00091 for ( int i=0; i < dimension->get() ; i++)
00092 {
00093 data_name << i;
00094 result.value().add( new Property<T>(data_name.str(),"",vec[i]) );
00095 data_name.str("");
00096 }
00097
00098 pi->introspect(result);
00099 deleteProperties( result.value() );
00100
00101 }
00102
00106 template<class T, int S>
00107 bool composeProperty(const PropertyBag& bag, Property<MultiVector<S,T> >& result)
00108 {
00109 base::PropertyBase* v_base = bag.find( result.getName() );
00110 if ( v_base == 0 )
00111 return false;
00112
00113 Property<PropertyBag>* v_bag = dynamic_cast< Property<PropertyBag>* >( v_base );
00114
00115 if (v_bag != 0 && v_bag->get().getType() == "MultiVector")
00116 {
00117 Property<T>* comp;
00118
00119 Property<int>* dim;
00120 v_base = v_bag->get().find("Size");
00121 if ( v_base == 0 ) {
00122 Logger::log() << Logger::Error << "In PropertyBag for Property< MultiVector<S,T> > :"
00123 << result.getName() << " : could not find property \"Size\"."<<Logger::endl;
00124 return false;
00125 }
00126 dim = dynamic_cast< Property<int>* >(v_base);
00127 if ( dim == 0) {
00128 Logger::log() << Logger::Error << "In PropertyBag for Property< MultiVector<S,T> > :"
00129 << result.getName() << " : Expected \"Size\" to be of type short."<<Logger::endl;
00130 return false;
00131 }
00132 int dimension = dim->get();
00133
00134 std::stringstream data_name;
00135
00136
00137 for (int i = 0; i < dimension ; i++)
00138 {
00139 data_name << i;
00140 base::PropertyBase* element = v_bag->get().find( data_name.str() );
00141 if ( element == 0 ) {
00142 Logger::log() << Logger::Error << "Aborting composition of Property< MultiVector<S,T> > "<<result.getName()
00143 << ": Data element "<< data_name.str() <<" not found !"
00144 <<Logger::endl;
00145 return false;
00146 }
00147 comp = dynamic_cast< Property<T>* >( element );
00148 if ( comp == 0 ) {
00149 base::DataSourceBase::shared_ptr ds = element->getDataSource();
00150 Logger::log() << Logger::Error << "Aborting composition of Property< MultiVector<S,T> > "<<result.getName()
00151 << ": Exptected data element "<< data_name.str() << " to be of type "<<internal::DataSource<T>::GetType()
00152 <<" got type " << element->getType()
00153 <<Logger::endl;
00154 return false;
00155 }
00156 result.value()[i] = comp->get();
00157
00158 data_name.str("");
00159 }
00160 }
00161 else
00162 {
00163 if ( v_bag != 0 ) {
00164 Logger::log() << Logger::Error << "Composing Property< MultiVector<S,T> > :"
00165 << result.getName() << " : type mismatch, got type '"<< v_bag->get().getType() <<"'"<<Logger::endl;
00166 } else {
00167 Logger::log() << Logger::Error << "Composing Property< MultiVector<S,T> > :"
00168 << result.getName() << " : not a PropertyBag."<<Logger::endl;
00169 }
00170
00171 Logger::log() << Logger::Debug << "Could not update Property< MultiVector<S,T> > : "<<result.getName()<<Logger::endl;
00172 return false;
00173 }
00174 return true;
00175
00176 }
00177
00178 }};
00179
00180
00181 #endif