Index: ocl/VectorTemplateComposition.hpp =================================================================== --- ocl/VectorTemplateComposition.hpp (revision 30075) +++ ocl/VectorTemplateComposition.hpp (working copy) @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -56,7 +57,8 @@ namespace RTT template void decomposeProperty(const std::vector& vec, PropertyBag& targetbag) { - targetbag.setType("list"); + std::string tname = detail::DataSourceTypeInfo::getType(); + targetbag.setType(tname+"s"); int dimension = vec.size(); std::string str; @@ -76,40 +78,93 @@ namespace RTT template bool composeProperty(const PropertyBag& bag, std::vector& result) { - if ( bag.getType() == "list" ) { + std::string tname = detail::DataSourceTypeInfo::getType(); + + if ( bag.getType() == tname+"s" ) { int dimension = bag.size(); Logger::log() << Logger::Info << "bag size " << dimension <* el_bag = bag.getProperty(out.str()); + + if(el_bag==NULL){ + // Works for properties in vector + PropertyBase* element = bag.getItem( i ); + //Property* t_bag= dynamic_cast< Property* >( element ); + log(Debug)<getName()<<", "<< element->getDescription()< my_property_t (t_abag->getName(),t_bag->getDescription()); + Property my_property_t (element->getName(),element->getDescription()); + log(Debug) << "element type" << element->getType() << endlog(); + log(Debug) << "property type" << my_property_t.getType() << endlog(); + if(my_property_t.getType()!=element->getType()) + { + log(Error)<< "Type of "<< element->getName() << " does not match type of "<composeType(element->getDataSource(),my_property_t.getDataSource()); + result[ i ] = my_property_t.get(); + } + } + else{ + // Works for propertybags in vector + const std::string el_bagType = el_bag->getType(); + log(Debug) << "el_bagType " << el_bagType << endlog(); + + //Property el_p(el_bag->getName(),el_bag->getDescription()); + Property el_p(el_bag->getName(),el_bag->getDescription()); + log(Debug) << "el_p type" << el_p.getType() << endlog(); + if(!(el_p.getDataSource()->composeType(el_bag->getDataSource()))){ + log(Error)<<"Could not compose element "<* t_bag= dynamic_cast< Property* >( element ); log(Debug)<getName()<<", "<< element->getDescription()< my_property_t (t_abag->getName(),t_bag->getDescription()); Property my_property_t (element->getName(),element->getDescription()); + log(Debug) << "element type" << element->getType() << endlog(); + log(Debug) << "property type" << my_property_t.getType() << endlog(); if(my_property_t.getType()!=element->getType()) - log(Error)<< "Type of "<< element->getName() << " does not match type of list"<getName() << " does not match type of "<composeType(element->getDataSource(),my_property_t.getDataSource()); result[ i ] = my_property_t.get(); } + */ } } else { Logger::log() << Logger::Error << "Composing Property< std::vector > :" << " type mismatch, got type '"<< bag.getType() - << "', expected type 'list'."< + + template struct StdVectorTemplateTypeInfo - : public TemplateContainerTypeInfo, int, T, ArrayIndexChecker >, SizeAssignChecker >, false > + : public TemplateContainerTypeInfo, int, T, ArrayIndexChecker >, SizeAssignChecker >, has_ostream > { - StdVectorTemplateTypeInfo( std::string name ) - : TemplateContainerTypeInfo, int, T, ArrayIndexChecker >, SizeAssignChecker >, false >(name) + StdVectorTemplateTypeInfo( std::string name ) + : TemplateContainerTypeInfo, int, T, ArrayIndexChecker >, SizeAssignChecker >, has_ostream >(name) { }; @@ -125,6 +180,116 @@ namespace RTT } }; + + template + std::ostream& operator << (std::ostream& os, const std::vector& vec) + { + os<<'['; + for(unsigned int i=0;i0) + os<<','; + os< + std::istream& operator >> (std::istream& is,std::vector& vec) + { + return is; + }; + + template + struct stdvector_ctor + : public std::unary_function&> + { + typedef const std::vector& (Signature)( int ); + mutable boost::shared_ptr< std::vector > ptr; + stdvector_ctor() + : ptr( new std::vector() ) {} + const std::vector& operator()( int size ) const + { + ptr->resize( size ); + return *(ptr); + } + }; + + /** + * See NArityDataSource which requires a function object like + * this one. + */ + template + struct stdvector_varargs_ctor + { + typedef const std::vector& result_type; + typedef T argument_type; + result_type operator()( const std::vector& args ) const + { + return args; + } + }; + + /** + * Constructs an array with \a n elements, which are given upon + * construction time. + */ + template + struct StdVectorBuilder + : public TypeBuilder + { + virtual DataSourceBase::shared_ptr build(const std::vector& args) const { + if (args.size() == 0 ) + return DataSourceBase::shared_ptr(); + typename NArityDataSource >::shared_ptr vds = new NArityDataSource >(); + for(unsigned int i=0; i != args.size(); ++i) { + typename DataSource::shared_ptr dsd = AdaptDataSource()( args[i] ); + if (dsd) + vds->add( dsd ); + else + return DataSourceBase::shared_ptr(); + } + return vds; + } + }; + + template + struct stdvector_ctor2 + : public std::binary_function&> + { + typedef const std::vector& (Signature)( int, T ); + mutable boost::shared_ptr< std::vector > ptr; + stdvector_ctor2() + : ptr( new std::vector() ) {} + const std::vector& operator()( int size, T value ) const + { + ptr->resize( size ); + ptr->assign( size, value ); + return *(ptr); + } + }; + + template + struct stdvector_index + : public std::binary_function&, int, T> + { + T operator()(const std::vector& v, int index) const + { + if ( index >= (int)(v.size()) || index < 0) + return T(); + return v[index]; + } + }; + + template + struct get_size + : public std::unary_function + { + int operator()(T cont ) const + { + return cont.size(); + } + }; }; #endif