Skip to content

Conversation

@facontidavide
Copy link
Collaborator

Enable passing shared_ptr to ports expecting shared_ptr while preserving ABI and API compatibility.

Implementation:

  • Add PolymorphicCastRegistry class for runtime cast registration
  • Store registry in BehaviorTreeFactory via PImpl (ABI-safe)
  • Propagate registry to blackboards via shared_ptr (tree outlives factory)
  • Add polymorphic cast fallback in Blackboard::get() and TreeNode::getInputStamped()
  • Add port type validation with polymorphic awareness in XML parser

API:

  • factory.registerPolymorphicCast<Derived, Base>() to register relationships
  • Supports transitive upcasts (Sphynx -> Cat -> Animal)
  • Compile-time port type checking still catches invalid connections

@facontidavide facontidavide force-pushed the feature/polymorphic-ports-abi-compatible branch 5 times, most recently from 90a4ffb to 363b666 Compare February 4, 2026 13:20
Enable passing shared_ptr<Derived> to ports expecting shared_ptr<Base>
without breaking ABI compatibility. Users register inheritance
relationships at runtime via BehaviorTreeFactory::registerPolymorphicCast,
and the system handles upcasting/downcasting transparently.

Key components:
- PolymorphicCastRegistry: thread-safe registry for inheritance
  relationships with transitive cast support (e.g. Sphynx->Cat->Animal)
- BehaviorTreeFactory owns the registry, shares it with Blackboards
- Blackboard::tryCastWithPolymorphicFallback: public Expected-returning
  API used by both Blackboard::get and TreeNode::getInputStamped
- XML parser validates port compatibility including polymorphic types
- Downcasts allowed at parse-time, checked at runtime via
  dynamic_pointer_cast

Design decisions:
- Registry uses shared_mutex for read-heavy workload
- Error propagation via nonstd::expected<T, std::string>
- No circular includes: safe_any.hpp includes registry directly
- All polymorphic tests consolidated in gtest_polymorphic_ports.cpp

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@facontidavide facontidavide force-pushed the feature/polymorphic-ports-abi-compatible branch from fc63b85 to 2dfa827 Compare February 5, 2026 10:52
@facontidavide facontidavide enabled auto-merge (squash) February 5, 2026 10:57
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 5, 2026

@facontidavide facontidavide merged commit 1e166f5 into master Feb 5, 2026
15 checks passed
@facontidavide facontidavide deleted the feature/polymorphic-ports-abi-compatible branch February 5, 2026 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant