orocos-toolchain / rtt

Orocos Real-Time Toolkit
http://www.orocos.org
Other
72 stars 79 forks source link

Added method setDataSource() and assignment operator to the PropertyBase interface #158

Closed meyerj closed 8 years ago

meyerj commented 8 years ago

These new methods can be used to "link" a property to another without having to know the exact derived type, e.g.:

bool linkProperty(RTT::base::PropertyBase *target,
                  const RTT::base::PropertyBase *source) {
    return target->setDataSource(source->getDataSource());
    // or
    *target = source;
    return target.ready();
}
// create another property b which mirrors a
RTT::Property<double> a("a", "example property", 5.0);
RTT::PropertyBase *b = a->create();
*b = a;  // or linkProperty(b, &a)
assert(b.getDataSource() == a.getDataSource());

It should be noted that the assignment *b = a in the above example is equivalent to b = a->copy() because PropertyBase::copy() introduced in 44b9970e9685b9b812ddce1e8cc8c9b400553d54 also has linking semantics (shared data source). This is in fact inconsistent with the PropertyBase::copy(const PropertyBase *) or DataSourceBase::copy() methods which have deep-copy semantics -- so probably a candidate for removal in 2.9? The only usage of PropertyBase::copy() within RTT itself is PropertyBag assignment, which is supposed to have linking semantics, too, and which has a slightly different behavior for owned vs. non-owned properties.

The RTT::Property<T>::Property(base::PropertyBase *) constructor and assignment operator have been updated to call the new method for consistency reasons. The patch is not ABI compatible. That's why I would like to integrate it before an official 2.9 release.

We would need this feature to build an application-wide, consolidated property tree which also allows for dynamic updates (with manual coordination).

adolfo-rt commented 8 years ago

LGTM modulo a small testcase that exercises the two new PropertyBase interface additions.

Thanks for putting this together :)

meyerj commented 8 years ago

LGTM modulo a small testcase that exercises the two new PropertyBase interface additions.

Done: https://github.com/orocos-toolchain/rtt/pull/158/commits/45c7a64f512eea96f44a1efaca21ec090af79f64

smits commented 8 years ago

lgtm, I created a separate issue to track the unrelated failing test #164