You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow passing a derived object to a port requiring a base class #943
Is your feature request related to a problem? Please describe.
There is a lot of boilerplate code needed for converting libraries, relying on inheritance, into BT nodes. Consider this example:
As you see, this would reduce boilerplate code in the C++ and in the XML representation. Is there any way to reduce the strictness of the custom std::any used in this project to enable this feature ? I think that this project https://github.com/samee/any_of implements this behavior.
There is also the problem that BT evaluates ports type for consistency. I don't think one can deduce the base class of a derived class typeid...
Fixed by #1107 (1e166f5). Register the inheritance once with factory.registerPolymorphicCast<Derived, Base>(), and a std::shared_ptr<Derived> output can then be read by a std::shared_ptr<Base> input port (see tests/gtest_polymorphic_ports.cpp). Making the cast automatic, without registration, would need a separate feature request.
Activity
facontidavide commentedon Mar 1, 2025
this is a good point.
Yes, I think it is safe to reduce the strictness of the any_cast.
Can you please help creating a PR with a unit test of the desired behavior, i.e. somehting like this should work out of the box
I am not sure if there is an easy fix for that, I need to investigate
Add polymorphic shared_ptr port support (Issue #943)
Add polymorphic shared_ptr port support (Issue #943)
Add polymorphic shared_ptr port support (Issue #943)
Add polymorphic shared_ptr port support (Issue #943)
Add polymorphic shared_ptr port support (Issue #943)
Add polymorphic shared_ptr port support (Issue #943) (#1107)
facontidavide commentedon Oct 24, 2026
Fixed by #1107 (1e166f5). Register the inheritance once with
factory.registerPolymorphicCast<Derived, Base>(), and astd::shared_ptr<Derived>output can then be read by astd::shared_ptr<Base>input port (seetests/gtest_polymorphic_ports.cpp). Making the cast automatic, without registration, would need a separate feature request.