32 #ifndef SAMPLE_COMPOSITION_HPP 33 #define SAMPLE_COMPOSITION_HPP 35 #include <rtt/Property.hpp> 36 #include <rtt/PropertyBag.hpp> 37 #include <rtt/TemplateTypeInfo.hpp> 38 #include <rtt/Types.hpp> 39 #include <rtt/Logger.hpp> 40 #include <rtt/DataSources.hpp> 45 #include "../../sample/sample.h" 46 #include "../../sample/weightedsample.h" 52 class PropertyIntrospection;
64 std::string tname = detail::DataSourceTypeInfo<T>::getType();
65 targetbag.setType(
"Sample");
68 assert( targetbag.empty() );
75 Property<PropertyBag>* el_bag =
new Property<PropertyBag>(
"SampleValue",
"Sample Value");
76 Property<T> el(
"SampleValue" ,
"Sample value ",sample.
ValueGet()) ;
77 if( el.getTypeInfo()->decomposeType(el.getDataSource(),el_bag->value()) )
80 targetbag.add( el_bag );
86 targetbag.add(
new Property<T>(
"SampleValue" ,
"Sample Value",sample.
ValueGet() ));
98 std::string tname = detail::DataSourceTypeInfo<T>::getType();
99 if ( bag.getType() == std::string(
"Sample") ) {
101 Property<PropertyBag>* el_bag = bag.getProperty<PropertyBag>(
"SampleValue");
105 PropertyBase* element = bag.getItem( 0 );
107 Property<T> my_property_t (element->getName(),element->getDescription());
108 if(my_property_t.getType()!=element->getType())
110 log(Error)<<
"Type of "<< element->getName() <<
" does not match type of Sample"<<
"OR "<<
"Could not read Sample Value "<<endlog();
114 my_property_t.getTypeInfo()->composeType(element->getDataSource(),my_property_t.getDataSource());
115 sample.
ValueSet( my_property_t.get());
120 const std::string el_bagType = el_bag->getType();
121 Property<T > el_p(el_bag->getName(),el_bag->getDescription());
122 if(!(el_p.getDataSource()->composeType(el_bag->getDataSource()))){
123 log(Error)<<
"Could not compose SampleValue "<<endlog();
129 log(Error)<<
"Property of SampleValue was not ready for use"<<endlog();
135 Logger::log() << Logger::Error <<
"Composing Property< Sample<T> > :" 136 <<
" type mismatch, got type '"<< bag.getType()
137 <<
"', expected type "<<tname<<
"."<<Logger::endl;
143 template <
typename T>
145 :
public TemplateTypeInfo<Sample<T>, true>
148 : TemplateTypeInfo<
Sample<T>,
true >(name)
154 decomposeProperty<T>( sample, targetbag );
160 return composeProperty<T>( bag, result );
167 :
public std::unary_function<T, const Sample<T>&>
172 : ptr( new
Sample<T>() ) {}
175 ptr->ValueSet( value );
190 std::string tname = detail::DataSourceTypeInfo<T>::getType();
191 targetbag.setType(
"WeightedSample");
194 assert( targetbag.empty() );
202 Property<PropertyBag>* el_bag =
new Property<PropertyBag>(
"WeightedSampleValue",
"WeightedSample Value");
203 Property<T> el(
"WeightedSampleValue" ,
"WeightedSample value ",weightedSample.
ValueGet()) ;
204 if( el.getTypeInfo()->decomposeType(el.getDataSource(),el_bag->value()) )
207 targetbag.add( el_bag );
213 targetbag.add(
new Property<T>(
"WeightedSampleValue" ,
"WeightedSample Value",weightedSample.
ValueGet() ));
216 targetbag.add(
new Property<double>(
"WeightedSampleWeight" ,
"WeightedSample Weight",weightedSample.
WeightGet() ));
227 std::string tname = detail::DataSourceTypeInfo<T>::getType();
228 if ( bag.getType() == std::string(
"WeightedSample") ) {
230 Property<PropertyBag>* el_bag = bag.getProperty<PropertyBag>(
"WeightedSampleValue");
234 PropertyBase* element = bag.getItem( 0 );
236 Property<T> my_property_t (element->getName(),element->getDescription());
237 if(my_property_t.getType()!=element->getType())
239 log(Error)<<
"Type of "<< element->getName() <<
" does not match type of WeightedSample"<<
"OR "<<
"Could not read WeightedSample Value "<<endlog();
243 my_property_t.getTypeInfo()->composeType(element->getDataSource(),my_property_t.getDataSource());
244 weightedSample.
ValueSet( my_property_t.get());
249 const std::string el_bagType = el_bag->getType();
250 Property<T > el_p(el_bag->getName(),el_bag->getDescription());
251 if(!(el_p.getDataSource()->composeType(el_bag->getDataSource()))){
252 log(Error)<<
"Could not compose WeightedSampleValue "<<endlog();
256 weightedSample.
ValueSet( el_p.get());
258 log(Error)<<
"Property of WeightedSampleValue was not ready for use"<<endlog();
263 Property<double>* weightProp = bag.getProperty<
double>(
"WeightedSampleWeight");
267 log(Error)<<
"Error reading weight of WeightedSample"<<endlog();
271 weightedSample.
WeightSet( weightProp->get());
275 Logger::log() << Logger::Error <<
"Composing Property< WeightedSample<T> > :" 276 <<
" type mismatch, got type '"<< bag.getType()
277 <<
"', expected type "<<tname<<
"."<<Logger::endl;
283 template <
typename T>
285 :
public TemplateTypeInfo<WeightedSample<T>, true>
294 decomposeProperty<T>( weightedSample, targetbag );
300 return composeProperty<T>( bag, result );
307 :
public std::binary_function<T ,double , const WeightedSample<T>&>
315 ptr->ValueSet( value );
316 ptr->WeightSet( weight );
boost::shared_ptr< WeightedSample< T > > ptr
void WeightSet(double weight)
Set the weight.
const WeightedSample< T > &() Signature(T, double)
bool decomposeTypeImpl(const WeightedSample< T > &weightedSample, PropertyBag &targetbag) const
void decomposeProperty(const Sample< T > &sample, PropertyBag &targetbag)
bool composeTypeImpl(const PropertyBag &bag, Sample< T > &result) const
void ValueSet(const T &value)
Set the value of the Sample.
const WeightedSample< T > & operator()(T value, double weight) const
void ValueSet(const T &value)
Set the value of the Sample.
boost::shared_ptr< Sample< T > > ptr
const Sample< T > &() Signature(T)
T & ValueGet()
Get the value of the Sample.
double WeightGet() const
Get the weight.
const Sample< T > & operator()(T value) const
bool composeTypeImpl(const PropertyBag &bag, WeightedSample< T > &result) const
bool decomposeTypeImpl(const Sample< T > &sample, PropertyBag &targetbag) const
T & ValueGet()
Get the value of the Sample.
bool composeProperty(const PropertyBag &bag, Sample< T > &sample)