Hi,
I'm still busy constructing the BFL typekit.
So far I have been able to include typekit support for Probability
(just a class containing a double), ColumnVector and RowVector (using
SequenceTypeInfo).
No I try to make support for the WeightedSample type.
WeightedSample is a templateclass: and each WeightedSample has a value
of the templatetype (ValueGet()) and weight (a double) (WeightGet()).
>From the documentation I was not sure how you can construct a typekit
for types which are themselves consisting of other self-defined types.
Should I inherit from StructTypeInfo or from TempalteTypeInfo?
Do I have to implement the serialize function and how?
In 1.10: I implemented a composeProperty and decomposeProperty
function (for composeProperty see below):
template<class T>
bool composeProperty(const PropertyBag& bag, WeightedSample<T>&
weightedSample)
{
//log(Debug) << "composeProperty of WeightedSample " <<
endlog();
std::string tname = detail::DataSourceTypeInfo<T>::getType();
if ( bag.getType() == std::string("WeightedSample") ) {
// Get values of sample
Property<PropertyBag>* el_bag =
bag.getProperty<PropertyBag>("WeightedSampleValue");
if(el_bag==NULL){
// Works for properties in WeightedSample
PropertyBase* element = bag.getItem( 0 );
//log(Debug)<<element->getName()<<", "<<
element->getDescription()<<endlog();
Property
if(my_property_t.getType()!=element->getType())
{
log(Error)<< "Type of "<< element->getName() << "
does not match type of WeightedSample"<< "OR "<<"Could not read
WeightedSample Value "<<endlog();
return false;
}
else{
my_property_t.getTypeInfo()->composeType(element->getDataSource(),my_property_t.getDataSource());
weightedSample.ValueSet( my_property_t.get());
}
}
else{
// Works for propertybags in WeightedSample
const std::string el_bagType = el_bag->getType();
Property<T >
el_p(el_bag->getName(),el_bag->getDescription());
if(!(el_p.getDataSource()->composeType(el_bag->getDataSource()))){
log(Error)<<"Could not compose WeightedSampleValue
"<<endlog();
return false;
}
if(el_p.ready()){
weightedSample.ValueSet( el_p.get());
}else{
log(Error)<<"Property of WeightedSampleValue was
not ready for use"<
}
}
// Get weight of sample
Property
if(!weightProp)
{
log(Error)<< "Error reading weight of
WeightedSample"<<endlog();
return false;
}
else{
weightedSample.WeightSet( weightProp->get());
}
}
else {
Logger::log() << Logger::Error << "Composing Property<
WeightedSample<T> > :"
<< " type mismatch, got type '"<<
bag.getType()
<< "', expected type
"<<tname<<"."<
}
return true;
};
Any suggestions how to proceed?
Tinne
>