Skip to content

Commit

Permalink
types: fix updating of struct containing vectors
Browse files Browse the repository at this point in the history
This is a cleanup that moves struct-specific code from TemplateTypeInfo
to StructTypeInfo (depends on boost::serialization features) and make
sure that the struct does not recursively decompose, but only its own.
The refresh action will then see how much further composition/decomposition
is needed.

Signed-off-by: Peter Soetens <[email protected]>
  • Loading branch information
Peter Soetens committed May 11, 2011
1 parent d676293 commit e73bec4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
14 changes: 2 additions & 12 deletions rtt/types/PropertyComposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,8 @@ bool RTT::types::composePropertyBag( PropertyBag const& sourcebag, PropertyBag&
log(Debug) << "Used user's composition function for " << tgtprop->getName() <<":"<<tgtprop->getType()<<endlog();
target.ownProperty(tgtprop);
} else {
// general case: user did not specify a composeType implementation, so we decompose
// our freshly built target, and try to update it with the source bag:

// we don't use ti->decomposeType() since that probably doesn't do what we wish
PropertyBag decomp;
if ( typeDecomposition( tgtprop->getDataSource(), decomp) && ( decomp.getType() == isbag.getType() ) && refreshProperties(decomp, isbag) ) {
// note: we add tgtprop ! the decomp is just a way to get a reference to the parts of tgtprop
target.ownProperty( tgtprop );
} else {
log(Error) <<"The type '" << isbag.value().getType() <<"' did not provide a type composition function, but I need one to compose it from a PropertyBag." <<endlog();
has_error = true;
}
log(Error) <<"The type '" << isbag.value().getType() <<"' did not provide a type composition function, but I need one to compose it from a PropertyBag." <<endlog();
has_error = true;
}
} else {
if ( isbag.ready() ) {
Expand Down
19 changes: 19 additions & 0 deletions rtt/types/StructTypeInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,25 @@ namespace RTT
log(Error) << "Wrong call to type info function " + this->getTypeName() << "'s getMember() can not process "<< item->getTypeName() <<endlog();
return base::DataSourceBase::shared_ptr();
}

/**
* Implementation that updates result with the matching parts in source
* Relies on the fact that getMember returns a C++ reference to each part of \a result, which is then updated
* with a property found in source.
*/
virtual bool composeTypeImpl(const PropertyBag& source, typename internal::AssignableDataSource<T>::reference_t result) const {
// The default implementation decomposes result and refreshes it with source.
internal::ReferenceDataSource<T> rds(result);
rds.ref(); // prevent dealloc.
PropertyBag decomp;
// only try refreshProperties if decomp's type is equal to source type.
// update vs refresh: since it is intentional that the decomposition leads to references to parts of result,
// only refreshProperties() is meaningful (ie we have a one-to-one mapping). In case of sequences, this would
// of course not match, so this is struct specific.
return typeDecomposition( &rds, decomp, false) && ( decomp.getType() == source.getType() ) && refreshProperties(decomp, source);
}


};
}
}
Expand Down
9 changes: 1 addition & 8 deletions rtt/types/TemplateTypeInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,16 +331,9 @@ namespace RTT

/**
* User, implement this function in case you want to control reading the XML data format.
* TemplateTypeInfo provides a default, good for most types implementation in case getMember()
* is implemented.
*/
virtual bool composeTypeImpl(const PropertyBag& source, typename internal::AssignableDataSource<T>::reference_t result) const {
// The default implementation decomposes result and refreshes it with source.
internal::ReferenceDataSource<T> rds(result);
rds.ref(); // prevent dealloc.
PropertyBag decomp;
// only try refreshProperties if decomp's type is equal to source type.
return typeDecomposition( &rds, decomp) && ( decomp.getType() == source.getType() ) && refreshProperties(decomp, source);
return false;
}

/**
Expand Down

0 comments on commit e73bec4

Please sign in to comment.